cli2telegram 2.0.2__tar.gz → 2.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/PKG-INFO +1 -1
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/cli2telegram/util.py +16 -1
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/pyproject.toml +1 -1
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/LICENSE +0 -0
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/README.md +0 -0
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/cli2telegram/__init__.py +0 -0
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/cli2telegram/cli.py +0 -0
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/cli2telegram/config.py +0 -0
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/cli2telegram/const.py +0 -0
- {cli2telegram-2.0.2 → cli2telegram-2.0.3}/cli2telegram/daemon.py +0 -0
|
@@ -18,6 +18,7 @@ import time
|
|
|
18
18
|
from datetime import datetime, timedelta
|
|
19
19
|
|
|
20
20
|
from telegram import Bot, InlineKeyboardMarkup, Message
|
|
21
|
+
from telegram.error import BadRequest, Forbidden, InvalidToken
|
|
21
22
|
from telegram.ext import Application
|
|
22
23
|
|
|
23
24
|
from cli2telegram import RetryLimitReachedException
|
|
@@ -88,11 +89,25 @@ async def try_send_message(
|
|
|
88
89
|
:param give_up_after: when to give up trying
|
|
89
90
|
"""
|
|
90
91
|
started_trying = datetime.now()
|
|
92
|
+
parse_mode = "markdown"
|
|
91
93
|
success = False
|
|
92
94
|
while not success:
|
|
93
95
|
try:
|
|
94
|
-
await send_message(bot=app.bot, chat_id=chat_id, message=message, parse_mode=
|
|
96
|
+
await send_message(bot=app.bot, chat_id=chat_id, message=message, parse_mode=parse_mode)
|
|
95
97
|
success = True
|
|
98
|
+
except BadRequest as ex:
|
|
99
|
+
if parse_mode is not None and "parse entities" in str(ex).lower():
|
|
100
|
+
# characters like "_" or "*" in the text are not valid markdown, so send it as plain text
|
|
101
|
+
LOGGER.warning(f"Message is not valid markdown, sending it as plain text instead: {ex}")
|
|
102
|
+
parse_mode = None
|
|
103
|
+
continue
|
|
104
|
+
# the request itself is wrong, retrying would never help
|
|
105
|
+
LOGGER.exception(ex)
|
|
106
|
+
raise
|
|
107
|
+
except (InvalidToken, Forbidden) as ex:
|
|
108
|
+
# wrong token or the bot is not allowed to write to the chat, retrying would never help
|
|
109
|
+
LOGGER.exception(ex)
|
|
110
|
+
raise
|
|
96
111
|
except Exception as ex:
|
|
97
112
|
LOGGER.exception(ex)
|
|
98
113
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|