diff --git a/CHANGELOG.md b/CHANGELOG.md index 994ea0a..99d7e2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ - Add `@loader.tag("out")` for watchers. Captures only outgoing events - Add `@loader.tag("in")` for watchers. Captures only incoming events - Add `@loader.tag("only_messages")` for watchers. Captures only messages (not service events) +- Add `@loader.tag("only_commands")` for watchers. Captures only userbot commands +- Add `@loader.tag("editable")` for watchers. Captures only messages, which can be edited +- Replace token obtainment mechanism with callback instead of inline - Do not cut off prefix in `message.message`, `message.text` and `message.raw_text` - Partially rework events processing and dispatching - Attempt to fix cached entities mixing up diff --git a/hikka/dispatcher.py b/hikka/dispatcher.py index 3c70341..c67d494 100755 --- a/hikka/dispatcher.py +++ b/hikka/dispatcher.py @@ -416,14 +416,29 @@ class CommandDispatcher: or whitelist_modules and f"{str(utils.get_chat_id(message))}.{func.__self__.__module__}" not in whitelist_modules - or getattr(func, "no_commands", False) - and await self._handle_command(event, watcher=True) - or getattr(func, "out", False) - and not getattr(message, "out", True) - or getattr(func, "in", False) - and getattr(message, "out", True) - or getattr(func, "only_messages", False) - and not isinstance(message, types.Message) + or ( + getattr(func, "no_commands", False) + and await self._handle_command(event, watcher=True) + ) + or ( + getattr(func, "only_commands", False) + and not await self._handle_command(event, watcher=True) + ) + or (getattr(func, "out", False) and not getattr(message, "out", True)) + or (getattr(func, "in", False) and getattr(message, "out", True)) + or ( + getattr(func, "only_messages", False) + and not isinstance(message, types.Message) + ) + or ( + getattr(func, "editable", False) + and ( + getattr(message, "fwd_from", False) + or not getattr(message, "out", False) + or getattr(message, "sticker", False) + or getattr(message, "via_bot_id", False) + ) + ) ): logging.debug(f"Ignored watcher of module {modname}") continue diff --git a/hikka/loader.py b/hikka/loader.py index d54cec6..df60e76 100644 --- a/hikka/loader.py +++ b/hikka/loader.py @@ -392,9 +392,11 @@ def tag(*tags, **kwarg_tags): Tag function (esp. watchers) with some tags Currently available tags: • `no_commands` - Ignore all userbot commands in watcher + • `only_commands` - Capture only userbot commands in watcher • `out` - Capture only outgoing events • `in` - Capture only incoming events • `only_messages` - Capture only messages (not join events) + • `editable` - Capture only messages, which can be edited (no forwards etc.) Usage example: diff --git a/hikka/modules/loader.py b/hikka/modules/loader.py index 2246c06..77181d0 100755 --- a/hikka/modules/loader.py +++ b/hikka/modules/loader.py @@ -651,10 +651,10 @@ class LoaderMod(loader.Module): self.set( "token", ( - await self._client.inline_query( - "@hikkamods_bot", "#get_hikka_token" - ) - )[0].title, + await (await self._client.get_messages("@hikka_ub", ids=[10]))[ + 0 + ].click(0) + ).message, ) res = await utils.run_sync(