aboutsummaryrefslogtreecommitdiff
path: root/velascobot2
diff options
context:
space:
mode:
authorGuillermo Serrahima <dev@vylion.com>2026-02-02 16:20:15 +0100
committerGuillermo Serrahima <dev@vylion.com>2026-02-02 16:20:15 +0100
commitfb075394d76f2633e7e4b13a673dcbe0db2ae0b9 (patch)
tree1c5675b8bacfe0fd3d39c28d75cb53c6eb3126bb /velascobot2
parentd2d0f2922bc7bd49718240a23bb7f9f6d9cfda18 (diff)
downloadvelascobot2-fb075394d76f2633e7e4b13a673dcbe0db2ae0b9.tar.xz
velascobot2-fb075394d76f2633e7e4b13a673dcbe0db2ae0b9.zip
Added rudimentary error catches for sending messages
Diffstat (limited to 'velascobot2')
-rw-r--r--velascobot2/bot.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/velascobot2/bot.py b/velascobot2/bot.py
index 2a997ff..19ec090 100644
--- a/velascobot2/bot.py
+++ b/velascobot2/bot.py
@@ -344,7 +344,11 @@ class Bot:
logger.info(
"Sending a {} to {}: '{}'".format(msg, chat_id, content)
)
- await bot.send_message(chat_id, content, **kwargs)
+ try:
+ await bot.send_message(chat_id, content, **kwargs)
+ except (telegram.error.Forbidden, telegram.error.BadRequest, telegram.error.NetworkError) as e:
+ logger.error(str(e))
+
else:
assert isinstance(content, tuple)
graph_type, graph_id = content
@@ -355,21 +359,26 @@ class Bot:
'Sending {} "{}" to {}'.format(graph_type, graph_id, chat_id)
)
- if graph_type == GraphicType.STICKER:
- sent = await bot.send_sticker(
- chat_id=chat_id, sticker=graph_id, **kwargs
- )
- elif graph_type == GraphicType.ANIMATION:
- sent = await bot.send_animation(
- chat_id=chat_id, animation=graph_id, **kwargs
- )
- elif graph_type == GraphicType.VIDEO:
- sent = await bot.send_video(
- chat_id=chat_id, video=graph_id, **kwargs
- )
- else:
- raise Exception("Sending unkown graphic type")
- logger.debug(f"Sent graphic: {sent}")
+ try:
+ if graph_type == GraphicType.STICKER:
+ sent = await bot.send_sticker(
+ chat_id=chat_id, sticker=graph_id, **kwargs
+ )
+ elif graph_type == GraphicType.ANIMATION:
+ sent = await bot.send_animation(
+ chat_id=chat_id, animation=graph_id, **kwargs
+ )
+ elif graph_type == GraphicType.VIDEO:
+ sent = await bot.send_video(
+ chat_id=chat_id, video=graph_id, **kwargs
+ )
+ else:
+ raise Exception("Sending unkown graphic type")
+ logger.debug(f"Sent graphic: {sent}")
+ except (telegram.error.Forbidden, telegram.error.BadRequest, telegram.error.NetworkError) as e:
+ logger.error(str(e))
+ except Exception as e:
+ raise e
async def announce(self, announcement, check=(lambda _: True)) -> None:
"""Sends an announcement to all chats that pass a check."""
@@ -601,4 +610,7 @@ class Bot:
f"{chat_data.answer_chance}.\n\nThis chat is {permissions}."
)
- await msg.reply_markdown(answer)
+ try:
+ await msg.reply_markdown(answer)
+ except Exception:
+ pass