SanYeCao-Nonebot/src/qq_plugins/touch.py

38 lines
1.2 KiB
Python
Raw Normal View History

2025-01-16 09:07:05 +00:00
from pathlib import Path
2025-01-04 16:17:12 +00:00
from nonebot.rule import to_me
from nonebot.plugin import on_command
2025-01-16 09:07:05 +00:00
from nonebot.adapters.qq import Message,MessageEvent,MessageSegment
2025-01-14 10:57:59 +00:00
from src.my_sqlite.touch_by_sqlite import touch_count, QrTouchLog, insert_touch_log, touch
2025-01-16 09:07:05 +00:00
from src.image.get_image import download_qq_image_by_account,qq_image_delete,rua
2025-01-14 10:57:59 +00:00
to = on_command("摸摸头",rule=to_me(),priority=10,block=True)
2025-01-04 16:17:12 +00:00
@to.handle()
async def handle_touch(event: MessageEvent):
member_openid = event.get_user_id()
2025-01-16 09:07:05 +00:00
num = touch_count(member_openid)
q = QrTouchLog()
q.user_id = member_openid
if num > 10 :
await to.finish("你今天已经摸了太多次了,请明天再吧!")
elif num > 5:
2025-01-04 16:17:12 +00:00
result = touch(1)
2025-01-16 09:07:05 +00:00
q.touch_status = 1
2025-01-04 16:17:12 +00:00
q.reply_touch_content = result.reply_touch_content
else:
result = touch(0)
2025-01-16 09:07:05 +00:00
q.touch_status = 1
2025-01-04 16:17:12 +00:00
q.reply_touch_content = result.reply_touch_content
2025-01-16 09:07:05 +00:00
insert_touch_log(q)
local_gif = rua(download_qq_image_by_account(None)).add_gif()
msg = Message([
MessageSegment.file_image(Path(local_gif)),
MessageSegment.text(result.reply_touch_content),
])
qq_image_delete()
await to.finish(msg)
2025-01-04 16:17:12 +00:00