From 77b755da5fb0c48d90a7e7bf56e085518596a00c Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 9 Jun 2023 18:38:40 +0800 Subject: [PATCH] fix --- app/modules/telegram/telegram.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/modules/telegram/telegram.py b/app/modules/telegram/telegram.py index 650e1bbb..322f07f3 100644 --- a/app/modules/telegram/telegram.py +++ b/app/modules/telegram/telegram.py @@ -35,15 +35,15 @@ class Telegram(metaclass=Singleton): def echo_all(message): RequestUtils(timeout=5).post_res(self._ds_url, json=message.json) - def run_polling(): - """ - 定义线程函数来运行 infinity_polling - """ - _bot.infinity_polling(long_polling_timeout=5) + def run_polling(): + """ + 定义线程函数来运行 infinity_polling + """ + _bot.infinity_polling(long_polling_timeout=5) - # 启动线程来运行 infinity_polling - self._polling_thread = threading.Thread(target=run_polling) - self._polling_thread.start() + # 启动线程来运行 infinity_polling + self._polling_thread = threading.Thread(target=run_polling) + self._polling_thread.start() def send_msg(self, title: str, text: str = "", image: str = "", userid: str = "") -> Optional[bool]: """ @@ -183,5 +183,6 @@ class Telegram(metaclass=Singleton): """ 停止Telegram消息接收服务 """ - self._bot.stop_polling() - self._polling_thread.join() + if not self._bot: + self._bot.stop_polling() + self._polling_thread.join()