48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from pathlib import Path
|
|
|
|
from nonebot import Bot, logger
|
|
from nonebot.adapters.onebot.v11 import Message, MessageSegment
|
|
from nonebot.internal.matcher import Matcher
|
|
from nonebot.plugin.on import on_command
|
|
|
|
from . import rlib, pconfig
|
|
|
|
handler = on_command("烤leak最近活动")
|
|
|
|
|
|
@handler.handle()
|
|
async def _(matcher: Matcher, bot: Bot):
|
|
try:
|
|
data = rlib.refetch_event().unwrap()
|
|
message = Message()
|
|
inner = [MessageSegment.text(f"活动 {data.event_id} 的卡牌数据")]
|
|
if len(data.cards) == 0:
|
|
inner.append(MessageSegment.text("没有新的卡牌。"))
|
|
# else
|
|
for card in data.cards:
|
|
inner.append(MessageSegment.text(card.text))
|
|
for item in card.path:
|
|
p = Path(item)
|
|
n = MessageSegment.image(file=item)
|
|
n.data["summary"] = f"[{p.name}]"
|
|
inner.append(n)
|
|
for node in inner:
|
|
message.append(MessageSegment.node_custom(
|
|
user_id=int(bot.self_id),
|
|
nickname=pconfig.nickname,
|
|
content=Message([node])
|
|
))
|
|
|
|
await matcher.send(message)
|
|
|
|
for card in data.cards:
|
|
for path in card.path:
|
|
try:
|
|
Path(path).unlink()
|
|
except Exception as e:
|
|
logger.error(f"删除文件 {path} 失败: {e}")
|
|
except Exception as e:
|
|
logger.error(f"获取活动数据失败: {e}")
|
|
await matcher.send(f"获取活动数据失败: {e}")
|
|
return
|