diff --git a/qqbot/README.md b/qqbot/README.md index f18879f..538154b 100644 --- a/qqbot/README.md +++ b/qqbot/README.md @@ -1 +1,9 @@ # QQ 机器人 + +go-cqhttp 上报的数据格式: + +```json +{'post_type': 'message', 'message_type': 'group', 'time': 1664423327, 'self_id': 3519964414, 'sub_type': 'normal', 'font': 0, 'message': '早上好', 'message_seq': 10221, 'sender': {'age': 0, 'area': '', 'card': '', 'level': '', 'nickname': 'EE0000', 'role': 'member', 'sex': 'unknown', 'title': '', 'user_id': 1040110848}, 'user_id': 1040110848, 'message_id': 200510966, 'anonymous': None, 'group_id': 346058845, 'raw_message': '早上好'} +``` + +判断 `post_type = message` 且 `message_type = group` 且 `group_id = 346058845` 进行回复 diff --git a/qqbot/bot.py b/qqbot/bot.py new file mode 100755 index 0000000..4692cd0 --- /dev/null +++ b/qqbot/bot.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# # -*- coding: utf-8 -*- + +import sys +from bottle import post, run, request, static_file, route + +sys.path.append("../data/convert/31-0") +from db import * + +db.bind(provider="sqlite", filename="../data/clean/31-0/data.sqlite3") +db.generate_mapping() + + +@route("/pics/") +def server_static(filepath): + return static_file(filepath, root="../data/render/output") + + +@post("/") +def recv_msg(): + data = request.json + if ( + data["post_type"] == "message" + and data["message_type"] == "group" + and data["group_id"] == 346058845 + ): + name = data["raw_message"] + query = select(m for m in Melee if m.name == name) + if query.count() > 0: + return { + "reply": f"[CQ]:image,file=http://localhost:7000/pics/{name}.png", + "at_sender": False, + } + return "OK" + + +run(host="localhost", port=7000)