async def execute(app: Mirai) -> None: delay = 10 while True: targets = Database.load().__root__ if not targets: await asyncio.sleep(delay) continue for target in targets: if target.groups: try: await asyncio.sleep(delay) resp = await getDynamicStatus(target.uid) if resp: footer = f"\n\n动态地址: https://t.bilibili.com/{resp.dynamic_id}" EventLogger.info( f'{target.name}动态更新:https://t.bilibili.com/{resp.dynamic_id}' ) # noinspection PyTypeChecker,PydanticTypeChecker components = [Plain(resp.msg)] + \ [await app.uploadImage( 'group', await Image.fromRemote(url) ) for url in resp.imgs] + \ [Plain(footer)] [ asyncio.create_task( app.sendGroupMessage(group=group_id, message=components)) for group_id in target.groups ] except Exception as e: EventLogger.error(f'动态检查出错:{target.name} {e}') EventLogger.error(traceback.format_exc()) continue
async def execute(app: Mirai, monitor: Monitor) -> None: # noinspection PyBroadException try: resp, groups = await monitor.run() if resp: EventLogger.info(f'{resp.name}直播:{resp.url}') if resp.cover: cover: Image = await app.uploadImage("group", await Image.fromRemote(resp.cover)) components = [Plain(f'(直播){resp.name}: {resp.title}\n{resp.url}\n'), cover] else: components = [Plain(f'(直播){resp.name}: {resp.title}\n{resp.url}')] tasks = [asyncio.create_task( app.sendGroupMessage(group=group_id, message=components) ) for group_id in groups] done, pending = await asyncio.wait(tasks) for task in done: if e := task.exception(): EventLogger.error(e) except ChannelResolveError as e: EventLogger.warning(e) except Exception: EventLogger.error(traceback.format_exc())