diff --git a/CHANGELOG.md b/CHANGELOG.md index 508e016..d89cb4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Hikka Changelog +## 🌑 Hikka 1.2.6 + +- Fix processing of `# scope: hikka_min` +- Add `forbid_joins.py` (to use it, download module from official repo with the same name) + ## 🌑 Hikka 1.2.5 - Add additional exit on restart to avoid port block diff --git a/hikka/forbid_joins.py b/hikka/forbid_joins.py new file mode 100644 index 0000000..8adbcf9 --- /dev/null +++ b/hikka/forbid_joins.py @@ -0,0 +1,70 @@ +from telethon import TelegramClient +from telethon.utils import is_list_like + +import inspect +import logging + +from . import loader + +logger = logging.getLogger(__name__) + +# ⚠️⚠️ WARNING! ⚠️⚠️ +# If you are a module developer, and you'll try to bypass this protection to +# force user join your channel, you will be added to SCAM modules +# list and you will be banned from Hikka federation. +# Let USER decide, which channel he will follow. Do not be so petty +# I hope, you understood me. +# Thank you + + +def install_join_forbidder(client: TelegramClient) -> TelegramClient: + if hasattr(client, "_forbid_join_tag"): + return client + + old_call = client._call + + async def new_call( + sender: "MTProtoSender", # type: ignore + request: "TLRequest", # type: ignore + ordered: bool = False, + flood_sleep_threshold: int = None, + ): + not_tuple = False + if not is_list_like(request): + not_tuple = True + request = (request,) + + new_request = [] + + for item in request: + if item.CONSTRUCTOR_ID == 615851205: + if next( + frame_info.frame.f_locals["self"] + for frame_info in inspect.stack() + if hasattr(frame_info, "frame") + and hasattr(frame_info.frame, "f_locals") + and isinstance(frame_info.frame.f_locals, dict) + and "self" in frame_info.frame.f_locals + and isinstance(frame_info.frame.f_locals["self"], loader.Module) + ).__class__.__name__ not in {"HelpMod", "LoaderMod"}: + logger.debug( + f"🎉 I protected you from unintented JoinChannelRequest ({item})!" + ) + continue + + new_request += [item] + + if not new_request: + return + + return await old_call( + sender, + new_request[0] if not_tuple else tuple(new_request), + ordered, + flood_sleep_threshold, + ) + + client._call = new_call + client._joins_forbidden = True + logger.debug("🎉 JoinForbidder installed!") + return client diff --git a/hikka/modules/loader.py b/hikka/modules/loader.py index fc844d9..b1d511f 100755 --- a/hikka/modules/loader.py +++ b/hikka/modules/loader.py @@ -552,7 +552,7 @@ class LoaderMod(loader.Module): }, { "text": self.lookup("updater").strings("cancel"), - "callback": self.lookup("updater").inline_close, + "action": "close", }, ], ) @@ -942,6 +942,19 @@ class LoaderMod(loader.Module): async def _update_modules(self): todo = await self._get_modules_to_load() + + # ⚠️⚠️ WARNING! ⚠️⚠️ + # If you are a module developer, and you'll try to bypass this protection to + # force user join your channel, you will be added to SCAM modules + # list and you will be banned from Hikka federation. + # Let USER decide, which channel he will follow. Do not be so petty + # I hope, you understood me. + # Thank you + + if "https://mods.hikariatama.ru/forbid_joins.py" in todo.values(): + from ..forbid_joins import install_join_forbidder + install_join_forbidder(self._client) + for mod in todo.values(): await self.download_and_install(mod) diff --git a/hikka/version.py b/hikka/version.py index e0b8f0f..46c619f 100644 --- a/hikka/version.py +++ b/hikka/version.py @@ -1,2 +1,2 @@ """Represents current userbot version""" -__version__ = (1, 2, 5) +__version__ = (1, 2, 6)