From f8ae60d1934af0f2c6ad0dd1b168d5b7f10a6bc8 Mon Sep 17 00:00:00 2001 From: Saipo Date: Sun, 27 Apr 2025 12:04:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=81=93=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tool.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Tool.py diff --git a/Tool.py b/Tool.py new file mode 100644 index 0000000..3fca93c --- /dev/null +++ b/Tool.py @@ -0,0 +1,9 @@ +class Tool: + id = 0 + name = "" + typeid = 0 + + def __init__(self, id, name, typeid): + self.id = id + self.name = name + self.typeid = typeid From decfe6b42ac9bee25edb4a2dc11411a17b2fcc06 Mon Sep 17 00:00:00 2001 From: Saipo Date: Sun, 27 Apr 2025 16:36:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=83=8C=E5=8C=85?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tool.py | 26 ++++++++++++++++++++++++-- main.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Tool.py b/Tool.py index 3fca93c..1ca51e7 100644 --- a/Tool.py +++ b/Tool.py @@ -1,9 +1,31 @@ +import pymysql + class Tool: id = 0 name = "" typeid = 0 - def __init__(self, id, name, typeid): + def __init__(self, id, typeid): self.id = id - self.name = name self.typeid = typeid + + + @staticmethod + def get_tool_name(id): + conn=pymysql.connect(host = '192.168.31.9' # 连接名称,默认 + ,user = 'saipo' + ,passwd='Grasste0403' # 密码 + ,port= 3306 # 端口,默认为3306 + ,db='saipo' # 数据库名称 + ,charset='utf8' # 字符编码 + ) + cur = conn.cursor() + sql = "SELECT name FROM tool WHERE id = %s" + cur.execute(sql, (id,)) + result = cur.fetchone() + cur.close() + conn.close() + if result: + return result[0] + else: + return None diff --git a/main.py b/main.py index f98fe5d..e92eeb0 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +import json +import Tool from astrbot.api.event import filter, AstrMessageEvent, MessageEventResult from astrbot.api.star import Context, Star, register from astrbot.api import logger @@ -127,6 +129,39 @@ class MyPlugin(Star): cur.close() conn.close() yield event.plain_result(f"昵称修改成功!\n新的昵称为:{name}") + + + @filter.command("我的背包") + async def bag(self, event: AstrMessageEvent): + if isUserExist(event.get_sender_id()) != True: + insertUser(event.get_sender_id()) + conn=pymysql.connect(host = '192.168.31.9' # 连接名称,默认 + ,user = 'saipo' + ,passwd='Grasste0403' # 密码 + ,port= 3306 # 端口,默认为3306 + ,db='saipo' # 数据库名称 + ,charset='utf8' # 字符编码 + ) + cur = conn.cursor() + sql = "SELECT baglist FROM dajiaouser WHERE openid = %s" + openid = event.get_sender_id() + cur.execute(sql,(openid,)) + date = cur.fetchone() + baglist = json.loads(date[0]) + baglist_str = "" + if len(baglist) == 0: + baglist_str = "背包空空如也" + else: + for item in baglist: + if Tool.get_tool_name(item["id"]) is None: + cur.close() + conn.close() + yield event.plain_result(f"背包存在异常!") + else: + baglist_str += f"{Tool.get_tool_name(item["id"])} x {item['num']}\n" + cur.close() + conn.close() + yield event.plain_result(f"背包列表:\n{baglist_str}") @filter.command("测试") async def test(self, event: AstrMessageEvent, name: str):