mirror of https://github.com/coddrago/Heroku
Deepsource fixes
parent
16ddeee41e
commit
cbc00985c8
|
@ -97,7 +97,7 @@ else:
|
||||||
log.init()
|
log.init()
|
||||||
|
|
||||||
from . import main
|
from . import main
|
||||||
except (ModuleNotFoundError, ImportError) as e:
|
except ImportError as e:
|
||||||
print(f"{str(e)}\n🔄 Attempting dependencies installation... Just wait ⏱")
|
print(f"{str(e)}\n🔄 Attempting dependencies installation... Just wait ⏱")
|
||||||
|
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
|
|
|
@ -40,11 +40,13 @@ DRAGON_EMOJI = "<emoji document_id=5375360100196163660>🐲</emoji>"
|
||||||
native_import = builtins.__import__
|
native_import = builtins.__import__
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# This is used to ensure, that dynamic dragon import passes in
|
|
||||||
# the right client. Whenever one of the clients attempts to install
|
|
||||||
# dragon-specific module, it must aqcuire the `import_lock` or wait
|
|
||||||
# until it's released. Then set the `current_client` variable to self.
|
|
||||||
class ImportLock:
|
class ImportLock:
|
||||||
|
# This is used to ensure, that dynamic dragon import passes in
|
||||||
|
# the right client. Whenever one of the clients attempts to install
|
||||||
|
# dragon-specific module, it must aqcuire the `import_lock` or wait
|
||||||
|
# until it's released. Then set the `current_client` variable to self.
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lock = asyncio.Lock()
|
self.lock = asyncio.Lock()
|
||||||
self.current_client = None
|
self.current_client = None
|
||||||
|
@ -203,14 +205,12 @@ class DragonScripts:
|
||||||
"<b>Telegram API error!</b>\n"
|
"<b>Telegram API error!</b>\n"
|
||||||
f"<code>[{e.CODE} {e.ID or e.NAME}] - {e.MESSAGE}</code>"
|
f"<code>[{e.CODE} {e.ID or e.NAME}] - {e.MESSAGE}</code>"
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
if hint:
|
hint_text = f"\n\n<b>Hint: {hint}</b>" if hint else ""
|
||||||
hint_text = f"\n\n<b>Hint: {hint}</b>"
|
|
||||||
else:
|
return (
|
||||||
hint_text = ""
|
f"<b>Error!</b>\n<code>{e.__class__.__name__}: {e}</code>" + hint_text
|
||||||
return (
|
)
|
||||||
f"<b>Error!</b>\n<code>{e.__class__.__name__}: {e}</code>" + hint_text
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def with_reply(func):
|
def with_reply(func):
|
||||||
|
@ -306,7 +306,7 @@ class DragonScripts:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return importlib.import_module(library_name)
|
return importlib.import_module(library_name)
|
||||||
except (ImportError, ModuleNotFoundError):
|
except ImportError:
|
||||||
completed = subprocess.run(
|
completed = subprocess.run(
|
||||||
[
|
[
|
||||||
sys.executable,
|
sys.executable,
|
||||||
|
@ -325,12 +325,15 @@ class DragonScripts:
|
||||||
),
|
),
|
||||||
package_name,
|
package_name,
|
||||||
],
|
],
|
||||||
|
check=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
if completed.returncode != 0:
|
if completed.returncode != 0:
|
||||||
raise AssertionError(
|
raise RuntimeError(
|
||||||
f"Failed to install library {package_name} (pip exited with code"
|
f"Failed to install library {package_name} (pip exited with code"
|
||||||
f" {completed.returncode})"
|
f" {completed.returncode})"
|
||||||
)
|
)
|
||||||
|
|
||||||
return importlib.import_module(library_name)
|
return importlib.import_module(library_name)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -142,24 +142,25 @@ class PyroProxyClient(PyroClient):
|
||||||
pyro_obj = self._convert(pyro_obj)
|
pyro_obj = self._convert(pyro_obj)
|
||||||
if isinstance(pyro_obj, list):
|
if isinstance(pyro_obj, list):
|
||||||
return [self._pyro2tl(i) for i in pyro_obj]
|
return [self._pyro2tl(i) for i in pyro_obj]
|
||||||
elif isinstance(pyro_obj, dict):
|
|
||||||
|
if isinstance(pyro_obj, dict):
|
||||||
return {k: self._pyro2tl(v) for k, v in pyro_obj.items()}
|
return {k: self._pyro2tl(v) for k, v in pyro_obj.items()}
|
||||||
else:
|
|
||||||
if not isinstance(pyro_obj, raw.core.TLObject):
|
|
||||||
return pyro_obj
|
|
||||||
|
|
||||||
if type(pyro_obj) not in PROXY:
|
if not isinstance(pyro_obj, raw.core.TLObject):
|
||||||
raise TypeError(
|
return pyro_obj
|
||||||
f"Cannot convert Pyrogram's {type(pyro_obj)} to Telethon TLObject"
|
|
||||||
)
|
|
||||||
|
|
||||||
return PROXY[type(pyro_obj)](
|
if type(pyro_obj) not in PROXY:
|
||||||
**{
|
raise TypeError(
|
||||||
attr: self._pyro2tl(getattr(pyro_obj, attr))
|
f"Cannot convert Pyrogram's {type(pyro_obj)} to Telethon TLObject"
|
||||||
for attr in pyro_obj.__slots__
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return PROXY[type(pyro_obj)](
|
||||||
|
**{
|
||||||
|
attr: self._pyro2tl(getattr(pyro_obj, attr))
|
||||||
|
for attr in pyro_obj.__slots__
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def _tl2pyro(self, tl_obj: telethon.tl.TLObject) -> raw.core.TLObject:
|
def _tl2pyro(self, tl_obj: telethon.tl.TLObject) -> raw.core.TLObject:
|
||||||
"""
|
"""
|
||||||
Recursively converts Telethon TLObjects to Pyrogram TLObjects (methods,
|
Recursively converts Telethon TLObjects to Pyrogram TLObjects (methods,
|
||||||
|
@ -180,32 +181,33 @@ class PyroProxyClient(PyroClient):
|
||||||
|
|
||||||
if isinstance(tl_obj, list):
|
if isinstance(tl_obj, list):
|
||||||
return [self._tl2pyro(i) for i in tl_obj]
|
return [self._tl2pyro(i) for i in tl_obj]
|
||||||
elif isinstance(tl_obj, dict):
|
|
||||||
|
if isinstance(tl_obj, dict):
|
||||||
return {k: self._tl2pyro(v) for k, v in tl_obj.items()}
|
return {k: self._tl2pyro(v) for k, v in tl_obj.items()}
|
||||||
else:
|
|
||||||
if isinstance(tl_obj, int) and str(tl_obj).startswith("-100"):
|
|
||||||
return int(str(tl_obj)[4:])
|
|
||||||
|
|
||||||
if not isinstance(tl_obj, telethon.tl.TLObject):
|
if isinstance(tl_obj, int) and str(tl_obj).startswith("-100"):
|
||||||
return tl_obj
|
return int(str(tl_obj)[4:])
|
||||||
|
|
||||||
if type(tl_obj) not in REVERSED_PROXY:
|
if not isinstance(tl_obj, telethon.tl.TLObject):
|
||||||
raise TypeError(
|
return tl_obj
|
||||||
f"Cannot convert Telethon's {type(tl_obj)} to Pyrogram TLObject"
|
|
||||||
)
|
|
||||||
|
|
||||||
hints = typing.get_type_hints(REVERSED_PROXY[type(tl_obj)].__init__) or {}
|
if type(tl_obj) not in REVERSED_PROXY:
|
||||||
|
raise TypeError(
|
||||||
return REVERSED_PROXY[type(tl_obj)](
|
f"Cannot convert Telethon's {type(tl_obj)} to Pyrogram TLObject"
|
||||||
**{
|
|
||||||
attr: self._convert_types(
|
|
||||||
hints.get(attr),
|
|
||||||
self._tl2pyro(getattr(tl_obj, attr)),
|
|
||||||
)
|
|
||||||
for attr in REVERSED_PROXY[type(tl_obj)].__slots__
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
hints = typing.get_type_hints(REVERSED_PROXY[type(tl_obj)].__init__) or {}
|
||||||
|
|
||||||
|
return REVERSED_PROXY[type(tl_obj)](
|
||||||
|
**{
|
||||||
|
attr: self._convert_types(
|
||||||
|
hints.get(attr),
|
||||||
|
self._tl2pyro(getattr(tl_obj, attr)),
|
||||||
|
)
|
||||||
|
for attr in REVERSED_PROXY[type(tl_obj)].__slots__
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_origin(hint: typing.Any) -> typing.Any:
|
def _get_origin(hint: typing.Any) -> typing.Any:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
# You can redistribute it and/or modify it under the terms of the GNU AGPLv3
|
# You can redistribute it and/or modify it under the terms of the GNU AGPLv3
|
||||||
# 🔑 https://www.gnu.org/licenses/agpl-3.0.html
|
# 🔑 https://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
import telethon
|
import telethon
|
||||||
from telethon.extensions.html import CUSTOM_EMOJIS
|
from telethon.extensions.html import CUSTOM_EMOJIS
|
||||||
|
|
|
@ -298,7 +298,7 @@ class Module:
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
local_event = asyncio.Event()
|
local_event = asyncio.Event()
|
||||||
self.__approve += [(channel, local_event)]
|
self.__approve += [(channel, local_event)] # skipcq: PTC-W0037
|
||||||
await local_event.wait()
|
await local_event.wait()
|
||||||
event.status = local_event.status
|
event.status = local_event.status
|
||||||
event.set()
|
event.set()
|
||||||
|
|
|
@ -66,11 +66,12 @@ class WebDebugger:
|
||||||
def app(request):
|
def app(request):
|
||||||
if request.args.get("ping", "N").upper() == "Y":
|
if request.args.get("ping", "N").upper() == "Y":
|
||||||
return Response("ok")
|
return Response("ok")
|
||||||
|
|
||||||
if request.args.get("shutdown", "N").upper() == "Y":
|
if request.args.get("shutdown", "N").upper() == "Y":
|
||||||
self._server._BaseServer__shutdown_request = True
|
self._server._BaseServer__shutdown_request = True
|
||||||
return Response("Shutdown!")
|
return Response("Shutdown!")
|
||||||
else:
|
|
||||||
raise self.exceptions.get(request.args.get("ex_id"), Exception("idk"))
|
raise self.exceptions.get(request.args.get("ex_id"), Exception("idk"))
|
||||||
|
|
||||||
app = DebuggedApplication(app, evalex=True, pin_security=True)
|
app = DebuggedApplication(app, evalex=True, pin_security=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue