diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-11-07 01:40:07 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-11-07 01:40:07 +0300 |
commit | 3a500359c7b7e4a50ec97fadbab284177bdaff01 (patch) | |
tree | ed8e8a7889884ff1e7614491e7962ce1ed4af853 | |
parent | 2addba8bcd5555946ac509c10b5b6f1c9a1fb40a (diff) |
sensors_bot fix
-rw-r--r-- | src/home/telegram/bot.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/home/telegram/bot.py b/src/home/telegram/bot.py index 86ed734..d7a1533 100644 --- a/src/home/telegram/bot.py +++ b/src/home/telegram/bot.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +import itertools from enum import Enum, auto from functools import wraps @@ -87,8 +88,9 @@ def _handler_of_handler(*args, **kwargs): return_with_context = False if 'argument' in kwargs and kwargs['argument'] == 'message_key': + del kwargs['argument'] mkey = None - for k, v in lang.get_langpack(ctx.lang).items(): + for k, v in lang.get_langpack(ctx.user_lang).items(): if ctx.text == v: mkey = k break @@ -118,8 +120,16 @@ def handler(**kwargs): inner_kwargs['argument'] = 'message_key' return _handler_of_handler(f=f, *args, **inner_kwargs) + messages = [] + if 'messages' in kwargs: + messages += kwargs['messages'] if 'message' in kwargs: - _updater.dispatcher.add_handler(MessageHandler(text_filter(lang.all(kwargs['message'])), _handler), group=0) + messages.append(kwargs['message']) + if messages: + _updater.dispatcher.add_handler( + MessageHandler(text_filter(*list(itertools.chain.from_iterable([lang.all(m) for m in messages]))), _handler), + group=0 + ) if 'command' in kwargs: _updater.dispatcher.add_handler(CommandHandler(kwargs['command'], _handler), group=0) |