测试变量作用域 #3
26
Tool.py
26
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
|
||||
|
35
main.py
35
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user