新增消息工具包,防止代码重复,方便@ 逻辑
This commit is contained in:
@@ -7,6 +7,8 @@ import redis
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from wcferry import Wcf, WxMsg
|
||||
|
||||
from message_util import MessageUtil
|
||||
from robot_cmd.robot_command import GroupBotManager, Feature, PermissionStatus
|
||||
|
||||
# 创建表的SQL语句
|
||||
@@ -28,7 +30,8 @@ CREATE TABLE IF NOT EXISTS t_sign_record (
|
||||
|
||||
class SignInSystem:
|
||||
def __init__(self, wcf: Wcf, gbm: GroupBotManager, all_contacts: dict,
|
||||
db_pool: mysql.connector.pooling.MySQLConnectionPool, redis_pool: redis.ConnectionPool):
|
||||
db_pool: mysql.connector.pooling.MySQLConnectionPool, redis_pool: redis.ConnectionPool,
|
||||
message_util: MessageUtil):
|
||||
# 读取配置文件
|
||||
with open('message_sign/config.toml', 'rb') as f:
|
||||
self.config = tomllib.load(f)['SignIn']
|
||||
@@ -40,6 +43,7 @@ class SignInSystem:
|
||||
|
||||
self.wcf = wcf
|
||||
self.gbm = gbm
|
||||
self.message_util = message_util
|
||||
self.all_contacts = all_contacts
|
||||
self.db_pool = db_pool
|
||||
self.redis_pool = redis_pool
|
||||
@@ -184,9 +188,8 @@ class SignInSystem:
|
||||
|
||||
# 如果 sign_stat 已经大于或等于今天的零点,则认为用户已经签到过了
|
||||
if sign_stat >= today_start:
|
||||
ats = ""
|
||||
ats += f" @{self.wcf.get_alias_in_chatroom(message.sender, message.roomid)}"
|
||||
self.wcf.send_text(f"{ats} 您今天已经签到过了!当前积分:{user_record['points']}", message.roomid, message.sender)
|
||||
self.message_util.send_text_msg(f"您今天已经签到过了!当前积分:{user_record['points']}", message.roomid,
|
||||
message.sender)
|
||||
return
|
||||
|
||||
streak = 0
|
||||
@@ -251,16 +254,15 @@ class SignInSystem:
|
||||
# output += f"你连续签到了 {streak} 天!"
|
||||
# if streak > 1 and not streak_broken:
|
||||
# output += "[爱心]"
|
||||
|
||||
output = f"签到成功,加[{points_to_add}]分,第[{today_signin_rank}]个!"
|
||||
|
||||
if streak_broken and old_streak > 0: # 只有在真的断签且之前有签到记录时才显示
|
||||
output += f"断开了 {old_streak} 天连签!"
|
||||
elif streak > 1:
|
||||
output += f"连签 {streak} 天!"
|
||||
ats = ""
|
||||
ats += f" @{self.wcf.get_alias_in_chatroom(message.sender, message.roomid)}"
|
||||
self.wcf.send_text(f"{ats} {output}", message.roomid, message.sender)
|
||||
|
||||
self.message_util.send_text_msg(output, message.roomid,
|
||||
message.sender)
|
||||
|
||||
def __del__(self):
|
||||
"""连接池由外部管理,不需要手动关闭"""
|
||||
|
||||
Reference in New Issue
Block a user