summaryrefslogtreecommitdiff
path: root/include/py/homekit/telegram/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'include/py/homekit/telegram/bot.py')
-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):