From a837428cea8271068bd187a35065a26f29bbdd4c Mon Sep 17 00:00:00 2001 From: hikariatama Date: Thu, 26 May 2022 18:07:13 +0000 Subject: [PATCH] Remove `HikkaDL` as redundant --- hikka/loader.py | 4 - hikka/modules/hikka_dl.py | 163 -------------------------------- hikka/modules/hikka_settings.py | 21 ---- 3 files changed, 188 deletions(-) delete mode 100644 hikka/modules/hikka_dl.py diff --git a/hikka/loader.py b/hikka/loader.py index 618dcad..1d1edfe 100644 --- a/hikka/loader.py +++ b/hikka/loader.py @@ -328,10 +328,6 @@ class Modules: not db.get("hikka", "disable_quickstart", False) or x != "quickstart.py" ) - and ( - db.get("hikka.main", "use_dl_btn", True) - or x != "hikka_dl.py" - ) ), os.listdir(os.path.join(utils.get_base_dir(), MODULES_NAME)), ) diff --git a/hikka/modules/hikka_dl.py b/hikka/modules/hikka_dl.py deleted file mode 100644 index a20b268..0000000 --- a/hikka/modules/hikka_dl.py +++ /dev/null @@ -1,163 +0,0 @@ -# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀ ▄▀█ ▀█▀ ▄▀█ █▀▄▀█ ▄▀█ -# █▀█ █ █ █ █▀█ █▀▄ █ ▄ █▀█ █ █▀█ █ ▀ █ █▀█ -# -# © Copyright 2022 -# -# https://t.me/hikariatama -# -# 🔒 Licensed under the GNU GPLv3 -# 🌐 https://www.gnu.org/licenses/agpl-3.0.html - -# scope: inline -# requires: websockets - -import asyncio -import json -import logging -import re - -import websockets -from telethon.tl.functions.contacts import UnblockRequest -from telethon.tl.functions.messages import SendReactionRequest - -from .. import loader - -logger = logging.getLogger(__name__) - -ALLOWED_ORIGINS = [ - "https://github.com/morisummerz/ftg-mods/raw/main", - "https://raw.githubusercontent.com/morisummerz/ftg-mods/main", - "https://mods.morisummer.ml", - "https://gitlab.com/cakestwix/friendly-userbot-modules/-/raw/master", - "https://twix.nonfalse-networks.net.ua/modules", - "https://mods.hikariatama.ru", - "https://raw.githubusercontent.com/hikariatama/ftg/master", - "https://github.com/hikariatama/ftg/raw/master", - "https://raw.githubusercontent.com/hikariatama/host/master", - "https://github.com/hikariatama/host/raw/master", -] - - -class RefreshToken(Exception): - """Placeholder""" - - -@loader.tds -class HikkaDLMod(loader.Module): - """Downloads stuff""" - - strings = {"name": "HikkaDL"} - - _connected = False - - async def _wss(self): - logger.debug("Connecting to HikkaDL websocket....") - async with websockets.connect( - f"wss://hikka.hikariatama.ru/ws/{self.get('token')}" - ) as wss: - while True: - ans = json.loads(await wss.recv()) - self._connected = True - self._no_revoke = False - if ans["event"] == "dlmod": - try: - msg = ( - await self._client.get_messages( - ans["channel"], - ids=[ans["message_id"]], - ) - )[0] - except Exception: - await wss.send("msg_404") - continue - - try: - link = re.search( - r".dlmod (https://[^ ]*\.py)", - msg.raw_text, - ).group(1) - except Exception: - await wss.send("link_404") - continue - - if "/".join(link.split("/")[:-1]).lower() not in ALLOWED_ORIGINS: - await wss.send("🚫 Origin is not allowed") - continue - - # Modules' creators spend so much time to create cool modules - # so this code part is a little propriety gesture. Send a ❤ - # to a message with a link to currently downloading module - try: - await self._client( - SendReactionRequest( - peer=ans["channel"], - msg_id=ans["message_id"], - reaction="❤️", - ) - ) - except Exception: - pass - - m = await self._client.send_message("me", f".dlmod {link}") - - if "dlmod" not in self.allmodules.commands: - await wss.send( - "Loader is unavailable. Perhaps, userbot is not yet fully loaded" - ) - continue - - await self.allmodules.commands["dlmod"](m) - load = (await self._client.get_messages(m.peer_id, ids=[m.id]))[0] - await wss.send(load.raw_text.splitlines()[0]) - await m.delete() - - if ans["event"] == "update": - logger.debug("Socket keep-alive timer expired, reconnecting...") - return - - if ans["event"] == "invalid_token": - logger.debug("Refreshing token...") - raise RefreshToken - - async def _connect(self): - self._no_revoke = False - while True: - try: - await self._wss() - except RefreshToken: - logger.debug("Token became invalid, revoking...") - await self._get_token() - except Exception: - logger.debug("Socket disconnected, retry in 5 sec", exc_info=True) - self._connected = False - await asyncio.sleep(5) - - async def _get_token(self): - async with self._client.conversation(self._bot) as conv: - m = await conv.send_message("/token") - r = await conv.get_response() - token = r.raw_text - await m.delete() - await r.delete() - - if not token.startswith("kirito_") and not token.startswith("asuna_"): - raise loader.LoadError("Can't get token") - - self.set("token", token) - - await self._client.delete_dialog(self._bot) - - async def client_ready(self, client, db): - self._db = db - self._client = client - self._bot = "@hikka_userbot" - - await self._client(UnblockRequest(id=self._bot)) - - if not self.get("token"): - await self._get_token() - - self._task = asyncio.ensure_future(self._connect()) - - async def on_unload(self): - self._task.cancel() diff --git a/hikka/modules/hikka_settings.py b/hikka/modules/hikka_settings.py index 1dbfaae..4aa3c1e 100755 --- a/hikka/modules/hikka_settings.py +++ b/hikka/modules/hikka_settings.py @@ -664,27 +664,6 @@ class HikkaSettingsMod(loader.Module): } ), ], - [ - ( - { - "text": self.strings("download_btn"), - "callback": self.inline__setting, - "args": ( - "use_dl_btn", - False, - ), - } - if self._db.get(main.__name__, "use_dl_btn", True) - else { - "text": self.strings("no_download_btn"), - "callback": self.inline__setting, - "args": ( - "use_dl_btn", - True, - ), - } - ), - ], [ { "text": self.strings("btn_restart"),