From 4f0cc4106c1f3684861ea1dfcd0b4f5d6a79ca56 Mon Sep 17 00:00:00 2001 From: klux2 Date: Sun, 12 May 2019 22:00:10 +0200 Subject: [PATCH] bug fix: made send_message function coroutine Signed-off-by: klux2 --- HSMensaW_botA.py.BAK | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/HSMensaW_botA.py.BAK b/HSMensaW_botA.py.BAK index 146cd6a..498ce0b 100644 --- a/HSMensaW_botA.py.BAK +++ b/HSMensaW_botA.py.BAK @@ -120,30 +120,30 @@ async def send_essen(chat_id: int) -> None: nachricht = nachricht.replace("MONAT", monate[(datum.month - 1) % 12]) for i in essen: nachricht += "- " + str(i).replace(".", ",") + "\n\n" - send_message(bot_obj=bot, chat_id=chat_id, msg=nachricht, parse_mode="markdown") + await send_message(bot_obj=bot, chat_id=chat_id, msg=nachricht, parse_mode="markdown") async def send_status(text: str) -> None: global config_ids for chat_id in config_ids: - send_message(bot_obj=bot, chat_id=chat_id, msg=text) + await send_message(bot_obj=bot, chat_id=chat_id, msg=text) -def send_message(bot_obj: DelegatorBot, chat_id: int, msg: str, parse_mode: Any = None, - disable_web_page_preview: bool = None, disable_notification: bool = None, - reply_to_message_id: int = None, reply_markup: Any = None) -> None: +async def send_message(bot_obj: DelegatorBot, chat_id: int, msg: str, parse_mode: Any = None, + disable_web_page_preview: bool = None, disable_notification: bool = None, + reply_to_message_id: int = None, reply_markup: Any = None) -> None: """Sends a message with bot_obj to chat_id. See https://core.telegram.org/bots/api#sendmessage for details.""" try: - bot_obj.sendMessage(chat_id=chat_id, text=msg, parse_mode=parse_mode, - disable_web_page_preview=disable_web_page_preview, - disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, - reply_markup=reply_markup) + await bot_obj.sendMessage(chat_id=chat_id, text=msg, parse_mode=parse_mode, + disable_web_page_preview=disable_web_page_preview, + disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, + reply_markup=reply_markup) except BotWasBlockedError: if chat_id in ids: ids.remove(chat_id) config['ids'] = ids - await send_status("Bot wurde blockiert für Chat ID %i)" % chat_id) + await send_status("Bot wurde blockiert für Chat ID %i" % chat_id) write_config()