summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-06-11 02:27:43 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-06-11 02:27:43 +0300
commiteaab12b8f4722ceae1039e4745088c555d6cbd1e (patch)
tree3a7c298c8ce0901dbc4609a2a5d973fdfc32c35f /include
parent1d0b9c5d1c90c4f7c7a6eb0c3cf32ffb843f2533 (diff)
pump_bot: port to new config scheme and PTB 20
Diffstat (limited to 'include')
-rw-r--r--include/py/homekit/telegram/bot.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/include/py/homekit/telegram/bot.py b/include/py/homekit/telegram/bot.py
index 5ed8b06..cf68b1d 100644
--- a/include/py/homekit/telegram/bot.py
+++ b/include/py/homekit/telegram/bot.py
@@ -26,6 +26,7 @@ from ._botlang import lang, languages
from ._botdb import BotDatabase
from ._botutil import exc2text, IgnoreMarkup
from ._botcontext import Context
+from .config import TelegramUserListType
db: Optional[BotDatabase] = None
@@ -518,29 +519,30 @@ async def _default_any_handler(ctx: Context):
# _reporting.report(update.callback_query.message, text=update.callback_query.data)
-def notify_all(text_getter: callable,
- exclude: Tuple[int] = ()) -> None:
- if 'notify_users' not in config['bot']:
- _logger.error('notify_all() called but no notify_users directive found in the config')
+async def notify_all(text_getter: callable,
+ exclude: Tuple[int] = ()) -> None:
+ notify_user_ids = config.app_config.get_user_ids(TelegramUserListType.NOTIFY)
+ if not notify_user_ids:
+ _logger.error('notify_all() called but no notify_users defined in the config')
return
- for user_id in config['bot']['notify_users']:
+ for user_id in notify_user_ids:
if user_id in exclude:
continue
text = text_getter(db.get_user_lang(user_id))
- _application.bot.send_message(chat_id=user_id,
- text=text,
- parse_mode='HTML')
+ await _application.bot.send_message(chat_id=user_id,
+ text=text,
+ parse_mode='HTML')
-def notify_user(user_id: int, text: Union[str, Exception], **kwargs) -> None:
+async def notify_user(user_id: int, text: Union[str, Exception], **kwargs) -> None:
if isinstance(text, Exception):
text = exc2text(text)
- _application.bot.send_message(chat_id=user_id,
- text=text,
- parse_mode='HTML',
- **kwargs)
+ await _application.bot.send_message(chat_id=user_id,
+ text=text,
+ parse_mode='HTML',
+ **kwargs)
def send_photo(user_id, **kwargs):