Cosmetic changes

pull/1/head
hikariatama 2023-05-24 08:47:05 +00:00
parent 03a45535e5
commit 81aa45127f
12 changed files with 33 additions and 67 deletions

View File

@ -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

View File

@ -274,7 +274,7 @@ class DragonScripts:
" list:</b>\n"
)
for command, desc in commands.items():
for command in commands:
cmd = command.split(maxsplit=1)
args = " <code>" + cmd[1] + "</code>" if len(cmd) > 1 else ""
help_text += f"<code>{self.misc.prefix}{cmd[0]}</code>{args}\n"

View File

@ -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__

View File

@ -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"

View File

@ -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")

View File

@ -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

View File

@ -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: "
)
)

View File

@ -41,7 +41,7 @@ class Brainfuck:
had_error = self._eval(code)
if had_error:
return
return ""
self._interpret(code)
return self.out

View File

@ -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

View File

@ -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.

View File

@ -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<cmd>.*)\n(?P<sig>.*?)\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)):

View File

@ -357,6 +357,8 @@ class SecurityManager:
):
return True
return False
async def check(
self,
message: typing.Optional[Message],