mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
rua 头改为 tortoise,删除多余的初始化类
This commit is contained in:
parent
72ff4e54ac
commit
061f4460dd
10 changed files with 163 additions and 368 deletions
2
bot.py
2
bot.py
|
|
@ -13,9 +13,7 @@ driver.on_shutdown(disconnect)
|
|||
|
||||
def init_all():
|
||||
# 初始化数据库
|
||||
data_init.touch_init()
|
||||
data_init.todo_init()
|
||||
data_init.admin_init()
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_all()
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
class SqliteSqlalchemy(object):
|
||||
def __init__(self):
|
||||
# 创建Sqlite连接引擎
|
||||
engine = create_engine('sqlite:///./chat_bot.db', echo=True)
|
||||
# 创建Sqlite的session连接对象
|
||||
self.session = sessionmaker(bind=engine)()
|
||||
|
||||
def insert_administrator(member_openid):
|
||||
session = SqliteSqlalchemy().session
|
||||
session.execute(insertAdminID, {'member_openid': member_openid})
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
def check_admin_access(member_openid):
|
||||
session = SqliteSqlalchemy().session
|
||||
result = session.execute(selectAdminID, {'member_openid': member_openid}).fetchone()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
|
||||
def select_status(group_id):
|
||||
session = SqliteSqlalchemy().session
|
||||
result = session.execute(selectIsOn, {'group_id': group_id}).fetchone()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
def update_ai_availability(group_id, is_on):
|
||||
session = SqliteSqlalchemy().session
|
||||
result = session.execute(selectGroupID, {'group_id': group_id}).fetchone()
|
||||
if result is None:
|
||||
session.execute(insertGroupID, {'group_id': group_id, 'is_on': is_on})
|
||||
session.commit()
|
||||
else:
|
||||
session.execute(updateIsOn, {'group_id': group_id, 'is_on': is_on})
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
# 插入数据
|
||||
insertAdminID = text("INSERT INTO admin_list (user_id) VALUES (:member_openid)")
|
||||
|
||||
# 查找用户
|
||||
selectAdminID = text("SELECT * FROM admin_list WHERE user_id = :member_openid")
|
||||
|
||||
# 更新数据
|
||||
selectIsOn = text("SELECT is_on FROM group_list WHERE group_id = :group_id")
|
||||
|
||||
# 更新数据
|
||||
updateIsOn = text("UPDATE group_list SET is_on = :is_on WHERE group_id = :group_id")
|
||||
|
||||
# 查询是否已存该群
|
||||
selectGroupID = text("SELECT * FROM group_list WHERE group_id = :group_id")
|
||||
|
||||
# 存储群聊ID
|
||||
insertGroupID = text("INSERT INTO group_list (group_id, is_on) VALUES (:group_id, :is_on)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
insert_administrator('1234')
|
||||
print(check_admin_access('1234'))
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
import sqlite3
|
||||
|
||||
# 连接到数据库,如果不存在则创建
|
||||
conn = sqlite3.connect('chat_bot.db')
|
||||
# 创建游标
|
||||
c = conn.cursor()
|
||||
# 创建表
|
||||
c.execute("""
|
||||
|
||||
CREATE TABLE IF NOT EXISTS admin_list (
|
||||
user_id VARCHAR(100) PRIMARY KEY
|
||||
);
|
||||
|
||||
""")
|
||||
|
||||
c.execute("""
|
||||
|
||||
CREATE TABLE IF NOT EXISTS group_list (
|
||||
group_id VARCHAR(100) PRIMARY KEY,
|
||||
is_on BOOLEAN DEFAULT false
|
||||
);
|
||||
|
||||
""")
|
||||
|
|
@ -12,31 +12,6 @@ class SqliteSqlalchemy(object):
|
|||
self.session = sessionmaker(bind=engine)()
|
||||
|
||||
|
||||
def touch_init():
|
||||
session = SqliteSqlalchemy().session
|
||||
# 检查某个表是否存在
|
||||
table_exists = session.execute(selectQrTouch).fetchone()
|
||||
if table_exists:
|
||||
return print("摸摸功能已初始化。")
|
||||
else:
|
||||
print("摸摸功能未初始化,开始执行初始化文件。")
|
||||
execute_init_file2()
|
||||
return ""
|
||||
|
||||
"""
|
||||
执行初始化文件touch_init_data.py
|
||||
"""
|
||||
def execute_init_file2():
|
||||
# 拼接文件的完整路径
|
||||
file_path = os.getcwd() + "/src/my_sqlite/data_init/touch_init_data.py"
|
||||
init_file_path = os.path.join(os.path.dirname(__file__), file_path)
|
||||
try:
|
||||
# 执行初始化文件
|
||||
subprocess.run(["python", init_file_path], check=True)
|
||||
print("初始化文件已成功执行。")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"执行初始化文件时出错: {e}")
|
||||
|
||||
|
||||
def todo_init():
|
||||
session = SqliteSqlalchemy().session
|
||||
|
|
@ -66,36 +41,6 @@ def execute_init_file3():
|
|||
print(f"执行初始化文件时出错: {e}")
|
||||
|
||||
|
||||
def admin_init():
|
||||
session = SqliteSqlalchemy().session
|
||||
# 检查某个表是否存在
|
||||
table_exists = session.execute(selectAdminList).fetchone()
|
||||
table_exists2 = session.execute(selectGroupList).fetchone()
|
||||
if table_exists and table_exists2:
|
||||
return print("管理员表和群聊表状态正常。")
|
||||
else:
|
||||
print("管理员表或群聊表不存在,开始执行初始化文件。")
|
||||
execute_init_file4()
|
||||
return ""
|
||||
|
||||
|
||||
def execute_init_file4():
|
||||
# 拼接文件的完整路径
|
||||
file_path = os.getcwd() + "/src/my_sqlite/data_init/admin_init.py"
|
||||
init_file_path = os.path.join(os.path.dirname(__file__), file_path)
|
||||
try:
|
||||
# 执行初始化文件
|
||||
subprocess.run(["python", init_file_path], check=True)
|
||||
print("初始化文件已成功执行。")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"执行初始化文件时出错: {e}")
|
||||
|
||||
|
||||
|
||||
|
||||
# 查询初始化表是否存在
|
||||
selectQrTouch = text(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='qr_touch';")
|
||||
|
||||
# 查询待办表是否存在
|
||||
selectTodoTable = text(
|
||||
|
|
@ -103,7 +48,3 @@ selectTodoTable = text(
|
|||
selectUserList = text(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='user_list';")
|
||||
|
||||
# 查询管理员表是否存在
|
||||
selectAdminList = text("SELECT name FROM sqlite_master WHERE type='table' AND name='admin_list';")
|
||||
# 查询群聊表是否存在
|
||||
selectGroupList = text("SELECT name FROM sqlite_master WHERE type='table' AND name='group_list';")
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
import sqlite3
|
||||
|
||||
# 连接到数据库,如果不存在则创建
|
||||
conn = sqlite3.connect('chat_bot.db')
|
||||
# 创建游标
|
||||
c = conn.cursor()
|
||||
#
|
||||
c.execute("""DROP TABLE IF EXISTS qr_touch; """)
|
||||
c.execute("""DROP TABLE IF EXISTS qu_touch_log; """)
|
||||
# 创建表
|
||||
c.execute("""
|
||||
|
||||
CREATE TABLE qr_touch (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
touch_status INTEGER NOT NULL,
|
||||
reply_touch_content TEXT NOT NULL
|
||||
);
|
||||
""")
|
||||
|
||||
c.execute("""
|
||||
CREATE TABLE qr_touch_log (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
touch_status INTEGER NOT NULL,
|
||||
reply_touch_content TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
extract_time DATE
|
||||
);
|
||||
""")
|
||||
|
||||
|
||||
# 插入数据
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'哼!你怎么突然摸我的头,把我吓了一跳!我刚刚整理好的毛发都被你弄乱了啦,你得负责帮我重新梳理好哦,喵!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'哼,真是的,又来摸本喵的头。虽然…… 虽然也不是很讨厌,但你可别得寸进尺哦,不然我就用爪子抓你啦!喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~你在摸我的头呢,好舒服呀!感觉就像被柔软的云朵轻轻拂过一样呢 再用点力也没关系哦,我可是很享受的呢。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'嘿,人类,你以为摸我的头就能讨好我啦?不过看在你手法还不错的份上,这次就允许你啦,喵~但要记得给我准备小鱼干哦。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵呜~别停呀,你的摸头动作真是太棒啦,让我想起了妈妈舔我的感觉呢,我都快融化啦~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'嘻嘻,你在给我挠痒痒呢,真是太有趣啦!我要在你身边转圈圈啦,多摸摸我的头,我会更加爱你的哦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'哼,虽然我是一只高傲的猫,但被你摸摸头的感觉还不赖哦 不过,你可得小心点,要是把我惹毛了,我可是会亮出爪子的哦,喵!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~你的手好温暖呀,每次被摸摸头,我就觉得自己是世界上最幸福的猫咪啦,希望你能一直这样摸下去呢。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵!你在摸我的头,这是在向我表示友好吗?那我就勉为其难地接受啦,要是能再给我一些猫薄荷就更好啦~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'呜呜~被摸摸头的感觉好温馨哦,我都想在你的腿上睡一觉啦,记得要一直摸着我,不然我会生气的哦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'嘿,你的摸头让我感觉自己像个小宝贝呢,我会用最可爱的样子来报答你哦,多摸摸我的头,让我更加可爱吧,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~我喜欢这种被抚摸的感觉呢,就像沉浸在温暖的阳光中,你可以多摸摸我的头,这样我会更有活力哦,说不定会帮你抓到更多老鼠呢。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵呜~好啦好啦,我已经被你摸得服服帖帖啦,感觉自己的毛都变得更加顺滑啦,继续保持哦,我会更听你的话呢。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'你在摸我的头,是不是觉得我很可爱呀 我可以让你多摸一会儿,不过作为交换,你要陪我玩捉迷藏哦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~谢谢你的摸头啦,你真是个好人呢,我会给你带来好运的哦,就像招财猫一样,只要你继续给我摸摸头,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'嘿,你这个铲屎官,摸头的动作还挺熟练嘛,我允许你再摸一会儿啦,不过可别想随便摸我的尾巴哦,喵!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~你的摸头就像一场温柔的冒险,让我沉浸其中呢,希望你能多摸摸我,我会带你去探索很多有趣的地方哦。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵呜~被摸摸头真是太美妙啦,感觉自己的九条命都变得更加精彩啦,你是我最喜欢的人类啦,继续给我摸摸头吧。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'哼,虽然我很傲娇,但我不得不承认,被你摸摸头的感觉真的很棒哦,不过,你可别太得意啦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~我感觉自己像一只被宠爱的小猫咪,你是我最信任的人啦,多摸摸我的头,我会在你身边撒娇哦。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'呜呜~被摸摸头的时候,我觉得自己是最幸福的啦,希望你能一直守护我,就像我守护自己的小鱼干一样,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'嘿,你在摸我的头呢,是不是在给我施展魔法呀 我已经被你的魔法控制啦,要一直摸下去哦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~每次你摸我的头,我就会变得更加慵懒哦,我会躺在你的怀里,享受这种惬意的时光,希望你能多陪陪我呢。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵呜~你的摸头让我变得更加放松啦,我会像猫精灵一样为你带来快乐,只要你不停止给我摸头哦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'嘿,别以为摸我的头是一件简单的事情哦,这可是需要技巧的呢,不过你现在做得还不错啦,继续加油哦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'喵~我要把我的头靠在你手上啦,这样你就可以更方便地摸我啦,我会发出咕噜咕噜的声音来表示我的快乐哦。');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (0,'呜呜~你是在给我按摩吗?我太喜欢啦,我会用最可爱的动作来感谢你,多摸摸我的头,我会更有精神哦,喵~');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'喵!你这家伙到底有完没完?!再敢碰我的头一下,我就把这房间里的东西全部抓烂,让你见识见识我的厉害!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'嘶嘶 —— 离我远点!你这不知死活的家伙,摸我的头?你是想尝尝我的爪子有多锋利吗?我可不会手下留情!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'喵呜!!我警告你,立刻停止你的动作!你要是再敢侵犯我的领地(头部),我就趁你睡觉的时候在你脸上留下几道漂亮的爪痕,让你知道我的愤怒!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'哼!你以为你是谁?竟敢摸本大爷 / 大小姐的头!我现在就去把你的鞋子咬得稀巴烂,看你还敢不敢乱动!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'喵!!!我已经忍无可忍了!你这无礼的行为简直不可饶恕,我要发动我的猫之诅咒,让你接下来的日子诸事不顺,除非你马上把手拿开!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'别逼我使出绝招!你再摸一下试试,我就把你心爱的那些小物件一个个从桌子上推下去摔碎,让你为你的鲁莽付出代价!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'喵!你是不是瞎啊?没看到我浑身的毛都因为生气竖起来了吗?还不把手缩回去,我马上就扑上去咬断你的手指!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'嘶 —— 我可不是好惹的!你这愚蠢的人类,摸我的头就像在挑战我的威严,我会让你知道什么叫恐惧,等着瞧吧!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'喵呜!!你触碰到了我的底线,我现在就去把你藏在角落里的零食找出来吃掉,一颗都不给你留,这就是你摸我头的下场!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'哼,摸什么摸呀,烦死了!你就不能让我清净会儿吗?别老想着动手动脚的,真当我好脾气呢!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'啧,又来摸我的头,你是有多无聊啊!我可没那闲工夫陪你玩这幼稚的把戏,离我远点啦!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'够了够了!别碰我头了行不行,每次都这样,我都快被你摸得不耐烦了,再这样我可真要发火了啊!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'我警告你最后一次,别碰我的头!你这没完没了的样子真的太讨厌了,小心我对你不客气!');")
|
||||
c.execute("insert into qr_touch (touch_status,reply_touch_content) values (1,'啊!你怎么还摸啊,我都想抓狂了,你是听不懂人话吗?再摸我就把你手给剁了,烦死了!');")
|
||||
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
# 关闭游标和连接
|
||||
c.close()
|
||||
conn.close()
|
||||
|
|
@ -34,6 +34,9 @@ class QrFortune(Model):
|
|||
|
||||
|
||||
class QrFortuneLog(Model):
|
||||
"""
|
||||
获取运势日志表
|
||||
"""
|
||||
id = fields.IntField(primary_key=True, generated=True, auto_increment=True)
|
||||
fortune_summary = fields.CharField(max_length=64, description="运势总结", null=True)
|
||||
lucky_star = fields.CharField(max_length=64, description="幸运星", null=True)
|
||||
|
|
|
|||
116
src/my_sqlite/models/touch.py
Normal file
116
src/my_sqlite/models/touch.py
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
from datetime import datetime
|
||||
import random
|
||||
from tortoise import fields
|
||||
from typing_extensions import Self
|
||||
from src.my_sqlite.data_init.db_connect import Model
|
||||
|
||||
|
||||
class QrTouch(Model):
|
||||
"""
|
||||
摸头回复内容
|
||||
"""
|
||||
id = fields.IntField(primary_key=True, generated=True, auto_increment=True)
|
||||
touch_status = fields.IntField(default=0,description="状态", null=True)
|
||||
reply_touch_content = fields.CharField(max_length=255, description="响应内容", null=True)
|
||||
class Meta:
|
||||
# 指定表名
|
||||
table = "qr_touch"
|
||||
table_description = "rua回复内容"
|
||||
|
||||
@classmethod
|
||||
async def touch(cls, status: int | None)-> Self | None:
|
||||
"""
|
||||
获取摸头内容
|
||||
:param status:
|
||||
:return:
|
||||
"""
|
||||
existing_record = await QrTouch.filter(touch_status=status).all()
|
||||
if not existing_record:
|
||||
# 执行初始化
|
||||
await cls.bulk_create(touch_initial_data)
|
||||
existing_record = await QrTouch.filter(touch_status=status).all()
|
||||
return random.choice(existing_record)
|
||||
|
||||
|
||||
class QrTouchLog(Model):
|
||||
"""
|
||||
摸头记录
|
||||
"""
|
||||
id = fields.IntField(primary_key=True, generated=True, auto_increment=True)
|
||||
touch_status = fields.IntField(default=0,description="状态", null=True)
|
||||
reply_touch_content = fields.CharField(max_length=255, description="响应内容", null=True)
|
||||
user_id = fields.CharField(max_length=64, description="用户id", null=True)
|
||||
extract_time = fields.DateField(description="日期", null=True)
|
||||
class Meta:
|
||||
# 指定表名
|
||||
table = "qr_touch_log"
|
||||
table_description = "rua回复内容"
|
||||
|
||||
@classmethod
|
||||
async def insert_touch_log(cls, model:QrTouch, member_openid):
|
||||
"""
|
||||
插入摸头记录
|
||||
:param model:
|
||||
:param member_openid:
|
||||
:return:
|
||||
"""
|
||||
data = {
|
||||
"touch_status": model.touch_status,
|
||||
"reply_touch_content": model.reply_touch_content,
|
||||
"user_id": member_openid,
|
||||
"extract_time": datetime.now().date()
|
||||
}
|
||||
await cls.create(**data)
|
||||
|
||||
@classmethod
|
||||
async def touch_count(cls, member_openid):
|
||||
"""
|
||||
获取摸头次数
|
||||
:param member_openid:
|
||||
:return:
|
||||
"""
|
||||
result = await QrTouchLog.filter(user_id=member_openid, extract_time=datetime.now().date()).count()
|
||||
return result
|
||||
|
||||
touch_initial_data = [QrTouch(touch_status=0,reply_touch_content="哼!你怎么突然摸我的头,把我吓了一跳!我刚刚整理好的毛发都被你弄乱了啦,你得负责帮我重新梳理好哦,喵!"),
|
||||
QrTouch(touch_status=0,reply_touch_content="哼,真是的,又来摸本喵的头。虽然……虽然也不是很讨厌,但你可别得寸进尺哦,不然我就用爪子抓你啦!喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~你在摸我的头呢,好舒服呀!感觉就像被柔软的云朵轻轻拂过一样呢再用点力也没关系哦,我可是很享受的呢。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="嘿,人类,你以为摸我的头就能讨好我啦?不过看在你手法还不错的份上,这次就允许你啦,喵~但要记得给我准备小鱼干哦。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵呜~别停呀,你的摸头动作真是太棒啦,让我想起了妈妈舔我的感觉呢,我都快融化啦~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="嘻嘻,你在给我挠痒痒呢,真是太有趣啦!我要在你身边转圈圈啦,多摸摸我的头,我会更加爱你的哦,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="哼,虽然我是一只高傲的猫,但被你摸摸头的感觉还不赖哦不过,你可得小心点,要是把我惹毛了,我可是会亮出爪子的哦,喵!"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~你的手好温暖呀,每次被摸摸头,我就觉得自己是世界上最幸福的猫咪啦,希望你能一直这样摸下去呢。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵!你在摸我的头,这是在向我表示友好吗?那我就勉为其难地接受啦,要是能再给我一些猫薄荷就更好啦~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="呜呜~被摸摸头的感觉好温馨哦,我都想在你的腿上睡一觉啦,记得要一直摸着我,不然我会生气的哦,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="嘿,你的摸头让我感觉自己像个小宝贝呢,我会用最可爱的样子来报答你哦,多摸摸我的头,让我更加可爱吧,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~我喜欢这种被抚摸的感觉呢,就像沉浸在温暖的阳光中,你可以多摸摸我的头,这样我会更有活力哦,说不定会帮你抓到更多老鼠呢。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵呜~好啦好啦,我已经被你摸得服服帖帖啦,感觉自己的毛都变得更加顺滑啦,继续保持哦,我会更听你的话呢。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="你在摸我的头,是不是觉得我很可爱呀我可以让你多摸一会儿,不过作为交换,你要陪我玩捉迷藏哦,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~谢谢你的摸头啦,你真是个好人呢,我会给你带来好运的哦,就像招财猫一样,只要你继续给我摸摸头,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="嘿,你这个铲屎官,摸头的动作还挺熟练嘛,我允许你再摸一会儿啦,不过可别想随便摸我的尾巴哦,喵!"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~你的摸头就像一场温柔的冒险,让我沉浸其中呢,希望你能多摸摸我,我会带你去探索很多有趣的地方哦。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵呜~被摸摸头真是太美妙啦,感觉自己的九条命都变得更加精彩啦,你是我最喜欢的人类啦,继续给我摸摸头吧。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="哼,虽然我很傲娇,但我不得不承认,被你摸摸头的感觉真的很棒哦,不过,你可别太得意啦,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~我感觉自己像一只被宠爱的小猫咪,你是我最信任的人啦,多摸摸我的头,我会在你身边撒娇哦。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="呜呜~被摸摸头的时候,我觉得自己是最幸福的啦,希望你能一直守护我,就像我守护自己的小鱼干一样,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="嘿,你在摸我的头呢,是不是在给我施展魔法呀我已经被你的魔法控制啦,要一直摸下去哦,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~每次你摸我的头,我就会变得更加慵懒哦,我会躺在你的怀里,享受这种惬意的时光,希望你能多陪陪我呢。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵呜~你的摸头让我变得更加放松啦,我会像猫精灵一样为你带来快乐,只要你不停止给我摸头哦,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="嘿,别以为摸我的头是一件简单的事情哦,这可是需要技巧的呢,不过你现在做得还不错啦,继续加油哦,喵~"),
|
||||
QrTouch(touch_status=0,reply_touch_content="喵~我要把我的头靠在你手上啦,这样你就可以更方便地摸我啦,我会发出咕噜咕噜的声音来表示我的快乐哦。"),
|
||||
QrTouch(touch_status=0,reply_touch_content="呜呜~你是在给我按摩吗?我太喜欢啦,我会用最可爱的动作来感谢你,多摸摸我的头,我会更有精神哦,喵~"),
|
||||
QrTouch(touch_status=1,reply_touch_content="喵!你这家伙到底有完没完?!再敢碰我的头一下,我就把这房间里的东西全部抓烂,让你见识见识我的厉害!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="嘶嘶——离我远点!你这不知死活的家伙,摸我的头?你是想尝尝我的爪子有多锋利吗?我可不会手下留情!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="喵呜!!我警告你,立刻停止你的动作!你要是再敢侵犯我的领地(头部),我就趁你睡觉的时候在你脸上留下几道漂亮的爪痕,让你知道我的愤怒!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="哼!你以为你是谁?竟敢摸本大爷/大小姐的头!我现在就去把你的鞋子咬得稀巴烂,看你还敢不敢乱动!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="喵!!!我已经忍无可忍了!你这无礼的行为简直不可饶恕,我要发动我的猫之诅咒,让你接下来的日子诸事不顺,除非你马上把手拿开!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="别逼我使出绝招!你再摸一下试试,我就把你心爱的那些小物件一个个从桌子上推下去摔碎,让你为你的鲁莽付出代价!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="喵!你是不是瞎啊?没看到我浑身的毛都因为生气竖起来了吗?还不把手缩回去,我马上就扑上去咬断你的手指!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="嘶——我可不是好惹的!你这愚蠢的人类,摸我的头就像在挑战我的威严,我会让你知道什么叫恐惧,等着瞧吧!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="喵呜!!你触碰到了我的底线,我现在就去把你藏在角落里的零食找出来吃掉,一颗都不给你留,这就是你摸我头的下场!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="哼,摸什么摸呀,烦死了!你就不能让我清净会儿吗?别老想着动手动脚的,真当我好脾气呢!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="啧,又来摸我的头,你是有多无聊啊!我可没那闲工夫陪你玩这幼稚的把戏,离我远点啦!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="够了够了!别碰我头了行不行,每次都这样,我都快被你摸得不耐烦了,再这样我可真要发火了啊!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="我警告你最后一次,别碰我的头!你这没完没了的样子真的太讨厌了,小心我对你不客气!"),
|
||||
QrTouch(touch_status=1,reply_touch_content="啊!你怎么还摸啊,我都想抓狂了,你是听不懂人话吗?再摸我就把你手给剁了,烦死了!"),
|
||||
]
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
from sqlalchemy import Column, Integer, String, Date, create_engine, text
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
|
||||
|
||||
def touch_count(member_openid):
|
||||
session = SqliteSqlalchemy().session
|
||||
#
|
||||
result = session.execute(selectTouchCount,
|
||||
{'member_openid': member_openid}).scalar()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
|
||||
def touch(status):
|
||||
session = SqliteSqlalchemy().session
|
||||
result = session.execute(selectTouchContent,{'status': status}).fetchone()
|
||||
session.close()
|
||||
return result
|
||||
|
||||
|
||||
def insert_touch_log(QrTouchLog):
|
||||
session = SqliteSqlalchemy().session
|
||||
session.execute(insertTouchLog,
|
||||
{'touch_status': QrTouchLog.touch_status,
|
||||
'reply_touch_content': QrTouchLog.reply_touch_content,
|
||||
'member_openid': QrTouchLog.user_id})
|
||||
session.commit()
|
||||
session.close()
|
||||
return ""
|
||||
|
||||
# 申明基类对象
|
||||
Base = declarative_base()
|
||||
|
||||
class QrTouch:
|
||||
__tablename__ = 'qr_touch'
|
||||
id = Column(Integer, primary_key=True)
|
||||
touch_status = Column(Integer)
|
||||
reply_touch_content = Column(String(255))
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
"QrTouch(id:{},touch_status:{},reply_touch_content:{})" .format(
|
||||
self.id,
|
||||
self.touch_status,
|
||||
self.reply_touch_content
|
||||
))
|
||||
|
||||
class QrTouchLog:
|
||||
__tablename__ = 'qr_touch_log'
|
||||
id = Column(Integer, primary_key=True)
|
||||
touch_status = Column(Integer)
|
||||
reply_touch_content = Column(String(255))
|
||||
user_id = Column(String(255))
|
||||
extract_time = Column(Date)
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
"QrFortune(id:{},touch_status:{},reply_touch_content:{},user_id:{})" .format(
|
||||
self.id,
|
||||
self.touch_status,
|
||||
self.reply_touch_content,
|
||||
self.user_id))
|
||||
|
||||
|
||||
class SqliteSqlalchemy(object):
|
||||
def __init__(self):
|
||||
# 创建Sqlite连接引擎
|
||||
engine = create_engine('sqlite:///./chat_bot.db', echo=True)
|
||||
# 创建Sqlite的session连接对象
|
||||
self.session = sessionmaker(bind=engine)()
|
||||
|
||||
|
||||
# 查询初始化表是否存在
|
||||
selectInit = text(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='qr_touch';")
|
||||
# 查询回复内容
|
||||
selectTouchContent = text("select * from qr_touch where touch_status = :status order by random() limit 1")
|
||||
# 查询触摸次数
|
||||
selectTouchCount = text(
|
||||
"select count(*) from qr_touch_log where user_id = :member_openid and extract_time = date('now')")
|
||||
# 插入日志表
|
||||
insertTouchLog = text(
|
||||
"insert into qr_touch_log (touch_status, reply_touch_content,user_id,extract_time) values (:touch_status, :reply_touch_content, :member_openid,date('now'))")
|
||||
|
|
@ -8,46 +8,39 @@ async def get_cf_rounds():
|
|||
await cf_query.send("正在为您整理近期比赛信息哦~\n请稍等💭💡🎈")
|
||||
try:
|
||||
result = requests.get('https://codeforces.com/api/contest.list?gym=false').json()
|
||||
except:
|
||||
except BaseException:
|
||||
await cf_query.finish("API请求失败,这绝对不是咱的错,绝对不是!")
|
||||
|
||||
print("正在请求codeforces比赛API")
|
||||
i = False
|
||||
all_matches = ""
|
||||
for matches in result['result']:
|
||||
if i:
|
||||
break
|
||||
if matches["phase"] == "BEFORE":
|
||||
phase = "未开始"
|
||||
elif matches["phase"] == "FINISHED":
|
||||
phase = "已结束"
|
||||
elif matches["phase"] == "CODING":
|
||||
phase = "进行中"
|
||||
elif matches["phase"] == "PENDING_SYSTEM_TEST":
|
||||
phase = "等待判题"
|
||||
elif matches["phase"] == "SYSTEM_TEST":
|
||||
phase = "判题中"
|
||||
elif matches["phase"] == "FINISHED":
|
||||
phase = "已结束"
|
||||
else:
|
||||
phase = "未知"
|
||||
one_match = ("\n比赛:" + str(matches["name"]) +
|
||||
"\n状态:" + phase +
|
||||
"\n时长:" + str(int(matches["durationSeconds"]) / 3600) + "h\n")
|
||||
phase = get_match_phase(matches["phase"])
|
||||
one_match = ("\n比赛:" + str(matches["name"]) + "\n状态:" + phase + "\n时长:" + str(int(matches["durationSeconds"]) / 3600) +"h\n")
|
||||
all_matches = "".join([all_matches, one_match])
|
||||
|
||||
if phase == "未开始":
|
||||
until_start_time_min = 0 - int(matches["relativeTimeSeconds"]) / 60
|
||||
if until_start_time_min <= 180:
|
||||
until_start = "距开始:" + str(int(until_start_time_min)) + "min\n"
|
||||
elif 180 < until_start_time_min <= 1440:
|
||||
until_start = "距开始:" + str(int(until_start_time_min / 60)) + "h\n"
|
||||
elif until_start_time_min > 1440:
|
||||
until_start = "距开始:" + str(int(until_start_time_min / 60 / 24)) + "days\n"
|
||||
else:
|
||||
until_start = "距开始:未知\n"
|
||||
until_start = get_until_start_time(until_start_time_min)
|
||||
all_matches = "".join([all_matches, until_start])
|
||||
if matches["phase"] == "FINISHED":
|
||||
i = True
|
||||
# print(all_matches)
|
||||
break
|
||||
await cf_query.finish(all_matches)
|
||||
|
||||
|
||||
def get_match_phase(phase):
|
||||
phase_map = {
|
||||
"BEFORE": "未开始",
|
||||
"FINISHED": "已结束",
|
||||
"CODING": "进行中",
|
||||
"PENDING_SYSTEM_TEST": "等待判题",
|
||||
"SYSTEM_TEST": "判题中",
|
||||
}
|
||||
return phase_map.get(phase, "未知")
|
||||
|
||||
|
||||
def get_until_start_time(until_start_time_min):
|
||||
if until_start_time_min <= 180:
|
||||
return "距开始:" + str(int(until_start_time_min)) + "min\n"
|
||||
elif 180 < until_start_time_min <= 1440:
|
||||
return "距开始:" + str(int(until_start_time_min / 60)) + "h\n"
|
||||
elif until_start_time_min > 1440:
|
||||
return "距开始:" + str(int(until_start_time_min / 60 / 24)) + "days\n"
|
||||
else:
|
||||
return "距开始:未知\n"
|
||||
|
|
|
|||
|
|
@ -2,36 +2,27 @@ from pathlib import Path
|
|||
from nonebot.rule import to_me
|
||||
from nonebot.plugin import on_command
|
||||
from nonebot.adapters.qq import Message, MessageEvent, MessageSegment
|
||||
from src.my_sqlite.touch_by_sqlite import touch_count, QrTouchLog, insert_touch_log, touch
|
||||
from src.my_sqlite.models.touch import QrTouch, QrTouchLog
|
||||
from src.image.get_image import download_qq_image_by_account, qq_image_delete, rua
|
||||
|
||||
|
||||
to = on_command("摸摸头", rule=to_me(), priority=10, block=True)
|
||||
|
||||
@to.handle()
|
||||
async def handle_touch(event: MessageEvent):
|
||||
|
||||
member_openid = event.get_user_id()
|
||||
num = touch_count(member_openid)
|
||||
q = QrTouchLog()
|
||||
q.user_id = member_openid
|
||||
async def handle_touch(message: MessageEvent):
|
||||
member_openid = message.get_user_id()
|
||||
num = await QrTouchLog.touch_count(member_openid)
|
||||
if num > 10:
|
||||
await to.finish("你今天已经摸了太多次了,请明天再吧!")
|
||||
elif num > 5:
|
||||
result = touch(1)
|
||||
q = QrTouch()
|
||||
q.touch_status = 1
|
||||
q.reply_touch_content = result.reply_touch_content
|
||||
if num > 5:
|
||||
result = await QrTouch.touch(1)
|
||||
else:
|
||||
result = touch(0)
|
||||
q.touch_status = 1
|
||||
result = await QrTouch.touch(0)
|
||||
q.reply_touch_content = result.reply_touch_content
|
||||
|
||||
insert_touch_log(q)
|
||||
await QrTouchLog.insert_touch_log(q, member_openid)
|
||||
local_gif = rua(download_qq_image_by_account(None)).add_gif()
|
||||
msg = Message([
|
||||
MessageSegment.file_image(Path(local_gif)),
|
||||
MessageSegment.text(result.reply_touch_content),
|
||||
])
|
||||
msg = Message([MessageSegment.file_image(Path(local_gif)),
|
||||
MessageSegment.text(result.reply_touch_content),])
|
||||
qq_image_delete()
|
||||
await to.finish(msg)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue