Skip to content

Commit

Permalink
积分表 新增查询功能,用户可以查询积分情况
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Sep 18, 2023
1 parent 4aed045 commit ed8dff5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@
"cmd": [
"我的积分",
"查询积分"
],
"copywriting": [
"{user_name}查询成功,您当前的积分是{integral}",
"{user_name},您当前的积分是{integral}"
]
}
}
Expand Down
4 changes: 4 additions & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@
"cmd": [
"我的积分",
"查询积分"
],
"copywriting": [
"{user_name}查询成功,您当前的积分是{integral}",
"{user_name},您当前的积分是{integral}"
]
}
}
Expand Down
2 changes: 0 additions & 2 deletions data/badwords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2761,7 +2761,6 @@
暴徒
北京帮
小日本
分析
邮政局
一四我
假烟
Expand Down Expand Up @@ -4913,7 +4912,6 @@
公告
屌鸠
卢福坦
语音
奶油冰
摸奶
徐向前
Expand Down
65 changes: 65 additions & 0 deletions utils/my_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,70 @@ def get_copywriting_and_audio_synthesis(view_num):
get_copywriting_and_audio_synthesis(integral_data[4] + 1)

return True
elif "crud" == type:
content = data["content"]

# 是否开启了查询功能
if My_handle.config.get("integral", "crud", "query", "enable"):
# 判断弹幕内容是否是命令
if content in My_handle.config.get("integral", "crud", "query", "cmd"):
# 查询数据库中是否有当前用户的积分记录(缺个UID)
common_sql = '''
SELECT * FROM integral WHERE username =?
'''
integral_data = self.db.fetch_all(common_sql, (user_name,))

logging.debug(f"integral_data={integral_data}")

# 获取文案并合成语音,传入积分总数自动检索
def get_copywriting_and_audio_synthesis(total_integral):
# 匹配文案
resp_content = random.choice(My_handle.config.get("integral", "crud", "query", "copywriting"))

logging.debug(f"resp_content={resp_content}")

data_json = {
"user_name": data["username"],
"integral": total_integral
}

resp_content = self.common.dynamic_variable_replacement(resp_content, data_json)

# 如果积分为0,则返回个没积分的回复。不过这个基本没可能,除非有bug
if total_integral == 0:
resp_content = data["username"] + ",查询到您无积分。"

# 生成回复内容
message = {
"type": "direct_reply",
"tts_type": My_handle.audio_synthesis_type,
"data": My_handle.config.get(My_handle.audio_synthesis_type),
"config": self.filter_config,
"user_name": user_name,
"content": resp_content
}

# 音频合成(edge-tts / vits_fast)并播放
My_handle.audio.audio_synthesis(message)

if integral_data == []:
logging.info(f"integral积分表 查询不到 用户:{user_name}")

get_copywriting_and_audio_synthesis(0)

return True
else:
integral_data = integral_data[0]
# 积分表中有该用户

# 获取日期时间字符串字段,此处是个坑点,一旦数据库结构发生改变或者select语句改了,就会关联影响!!!
date_string = integral_data[3]

logging.info(f"integral积分表 用户:{user_name},总积分:{date_string}")

get_copywriting_and_audio_synthesis(int(date_string))

return True
return False


Expand Down Expand Up @@ -1221,6 +1284,8 @@ def comment_handle(self, data):
# 0、积分机制运转
if self.integral_handle("comment", data):
return
if self.integral_handle("crud", data):
return

"""
用户名也得过滤一下,防止炸弹人
Expand Down

0 comments on commit ed8dff5

Please sign in to comment.