fix some
This commit is contained in:
+11
-3
@@ -1124,8 +1124,9 @@ class BotInterface:
|
||||
)
|
||||
else:
|
||||
from types import SimpleNamespace
|
||||
chat_id = params.chat_id or callback.message.chat.id
|
||||
msg_mock = SimpleNamespace(
|
||||
chat=SimpleNamespace(id=params.chat_id),
|
||||
chat=SimpleNamespace(id=chat_id),
|
||||
bot=callback.message.bot,
|
||||
)
|
||||
await interface.background_tasks.cancel_task(tid)
|
||||
@@ -1133,7 +1134,7 @@ class BotInterface:
|
||||
task_id=tid,
|
||||
coro=interface._run_twitch(tid, params, msg_mock),
|
||||
task_type="twitch_irc",
|
||||
metadata={"type": "twitch_irc", "channel": params.channel, "chat_id": params.chat_id},
|
||||
metadata={"type": "twitch_irc", "channel": params.channel, "chat_id": chat_id},
|
||||
)
|
||||
|
||||
if success:
|
||||
@@ -2062,11 +2063,14 @@ class BotInterface:
|
||||
from services.irc_service import TwitchIRCClient
|
||||
|
||||
irc = TwitchIRCClient(params.channel, params.target_username)
|
||||
url_tasks: set = set()
|
||||
|
||||
async def on_url(url, username):
|
||||
if params.stream_offline:
|
||||
return # не обрабатываем ссылки пока стрим оффлайн
|
||||
return
|
||||
task = asyncio.create_task(self._process_url(url, username, params, message))
|
||||
url_tasks.add(task)
|
||||
task.add_done_callback(url_tasks.discard)
|
||||
task.add_done_callback(
|
||||
lambda t: logger.error(f"URL processing failed: {t.exception()}") if not t.cancelled() and t.exception() else None
|
||||
)
|
||||
@@ -2098,6 +2102,10 @@ class BotInterface:
|
||||
logger.error(f"IRC error [{params.channel}]: {e}")
|
||||
finally:
|
||||
watcher.cancel()
|
||||
for t in list(url_tasks):
|
||||
t.cancel()
|
||||
if url_tasks:
|
||||
await asyncio.gather(*url_tasks, return_exceptions=True)
|
||||
await irc.disconnect()
|
||||
if self.storage:
|
||||
await self.storage.save_task(task_id, params)
|
||||
|
||||
Reference in New Issue
Block a user