From 3d21d83bf045675c650ce593e3ea48a002bed5ca Mon Sep 17 00:00:00 2001 From: Zhao Zuohong <1040110848@qq.com> Date: Thu, 29 Sep 2022 14:29:45 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20QQ=20bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qqbot/README.md | 8 ++++++++ qqbot/bot.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 qqbot/bot.py 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)