From 9d7abb93189514c066537db347e1d8d686ac9aaf Mon Sep 17 00:00:00 2001 From: Kyomotoi <0w0@imki.moe> Date: Sat, 15 Oct 2022 12:42:24 +0800 Subject: =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20=E4=BF=AE=E5=A4=8D=E5=9B=A0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=8F=91=E9=80=81=E5=A4=B1=E8=B4=A5=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E5=90=8E=E5=8F=B0=E6=8A=A5=E9=94=99=E5=88=B7?= =?UTF-8?q?=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/twitter/__init__.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ATRI/plugins/twitter/__init__.py b/ATRI/plugins/twitter/__init__.py index 3cfa142..66bde4f 100644 --- a/ATRI/plugins/twitter/__init__.py +++ b/ATRI/plugins/twitter/__init__.py @@ -12,7 +12,7 @@ from nonebot import get_bot from nonebot.matcher import Matcher from nonebot.params import CommandArg, ArgPlainText from nonebot.permission import Permission, SUPERUSER -from nonebot.adapters.onebot.v11 import Message, MessageSegment, GroupMessageEvent +from nonebot.adapters.onebot.v11 import Message, MessageSegment, GroupMessageEvent, Bot from ATRI.log import log from ATRI.utils import timestamp2datetime @@ -150,6 +150,9 @@ class TwitterDynamicChecker(BaseTrigger): return now +_bot: Bot = get_bot() + + @scheduler.scheduled_job( AndTrigger([IntervalTrigger(seconds=30), TwitterDynamicChecker()]), name="推特动态更新检查", @@ -169,6 +172,13 @@ async def _check_td(): await tq.put(i) else: m: TwitterSubscription = tq.get_nowait() + + group_list = await _bot.get_group_list() + gl = [f"{i['group_id']}" for i in group_list] + if m.group_id not in gl: + await sub.del_sub(m.tid, m.group_id) + log.warning(f"群 {m.group_id} 不存在, 已删除订阅 {m.name}@{m.screen_name}") + log.info(f"准备查询推主 {m.name}@{m.screen_name} 的动态,队列剩余 {tq.qsize()}") raw_ts = m.last_update.replace( @@ -197,15 +207,17 @@ async def _check_td(): } content = sub.gen_output(data, _CONTENT_LIMIT) - bot = get_bot() - await bot.send_group_msg(group_id=m.group_id, message=content) + try: + await _bot.send_group_msg(group_id=m.group_id, message=content) + except Exception: + log.warning("推信息发送失败") + await sub.update_sub( m.tid, m.group_id, {"last_update": timestamp2datetime(ts_t)} ) if _pic: pic = Message(MessageSegment.image(_pic)) try: - await bot.send_group_msg(group_id=m.group_id, message=pic) + await _bot.send_group_msg(group_id=m.group_id, message=pic) except Exception: - repo = "图片发送失败了..." - await bot.send_group_msg(group_id=m.group_id, message=repo) + log.warning("推图片发送失败") -- cgit v1.2.3