✨ QQ bot
This commit is contained in:
parent
439d42182a
commit
3d21d83bf0
2 changed files with 45 additions and 0 deletions
|
@ -1 +1,9 @@
|
||||||
# QQ 机器人
|
# 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` 进行回复
|
||||||
|
|
37
qqbot/bot.py
Executable file
37
qqbot/bot.py
Executable file
|
@ -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/<filepath:path>")
|
||||||
|
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)
|
Loading…
Reference in a new issue