- 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
pull/1/head
hikariatama 2022-08-03 10:47:48 +00:00
parent eb33b70939
commit f7eb19b3f0
4 changed files with 32 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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