优化逻辑
This commit is contained in:
@@ -19,8 +19,8 @@ class PointTrade:
|
||||
|
||||
def __init__(self, wcf: Wcf, gbm: GroupBotManager, db_pool: mysql.connector.pooling.MySQLConnectionPool):
|
||||
self.LOG = logging.getLogger(__name__)
|
||||
self.wcf = wcf # 假设 wcf 对象在此类中初始化
|
||||
self.gbm = gbm # 权限功能
|
||||
self.wcf = wcf
|
||||
self.gbm = gbm
|
||||
self.db_pool = db_pool
|
||||
with open("point_trade/config.toml", "rb") as f:
|
||||
plugin_config = tomllib.load(f)
|
||||
@@ -96,8 +96,11 @@ class PointTrade:
|
||||
(message.roomid if message.from_group() else message.sender), message.sender)
|
||||
return
|
||||
|
||||
sender_user_id, sender_wx_id, sender_wx_nick_name, sender_current_points = sender_result
|
||||
sender_current_points = int(sender_current_points)
|
||||
# 从字典中提取字段
|
||||
sender_user_id = sender_result['id']
|
||||
sender_wx_id = sender_result['wx_id']
|
||||
sender_wx_nick_name = sender_result['wx_nick_name']
|
||||
sender_current_points = int(sender_result['points'])
|
||||
|
||||
# 检查发信人积分是否足够
|
||||
if sender_current_points < reward_points:
|
||||
@@ -114,10 +117,13 @@ class PointTrade:
|
||||
(message.roomid if message.from_group() else message.sender), message.sender)
|
||||
return
|
||||
|
||||
recipient_user_id, recipient_wx_id, recipient_wx_nick_name, recipient_current_points = recipient_result
|
||||
recipient_current_points = int(recipient_current_points)
|
||||
# 从字典中提取字段
|
||||
recipient_user_id = recipient_result['id']
|
||||
recipient_wx_id = recipient_result['wx_id']
|
||||
recipient_wx_nick_name = recipient_result['wx_nick_name']
|
||||
recipient_current_points = int(recipient_result['points'])
|
||||
|
||||
# 使用 SQL 增量更新积分(不再在程序中计算)
|
||||
# 使用 SQL 增量更新积分
|
||||
try:
|
||||
self._update_user_points(sender_user_id, -reward_points, group_id) # 减少发送者积分
|
||||
self._update_user_points(recipient_user_id, reward_points, group_id) # 增加接收者积分
|
||||
@@ -155,7 +161,7 @@ class PointTrade:
|
||||
查询用户的记录
|
||||
:param wx_id: 用户的微信ID
|
||||
:param group_id: 群组ID
|
||||
:return: 用户记录(id, wx_id, wx_nick_name, points)
|
||||
:return: 用户记录(字典格式)
|
||||
"""
|
||||
try:
|
||||
with self._get_db_connection() as conn:
|
||||
@@ -171,10 +177,10 @@ class PointTrade:
|
||||
|
||||
def _get_user_record_by_nick(self, wx_id, group_id):
|
||||
"""
|
||||
根据微信ID查询用户的记录(此处与 _get_user_record 功能相同,可优化)
|
||||
根据微信ID查询用户的记录
|
||||
:param wx_id: 用户的微信ID
|
||||
:param group_id: 群组ID
|
||||
:return: 用户记录(id, wx_id, wx_nick_name, points)
|
||||
:return: 用户记录(字典格式)
|
||||
"""
|
||||
try:
|
||||
with self._get_db_connection() as conn:
|
||||
|
||||
Reference in New Issue
Block a user