调整消息发送逻辑

This commit is contained in:
liuwei
2025-05-08 09:47:37 +08:00
parent e18f391cab
commit bfe4652867
5 changed files with 27 additions and 26 deletions

View File

@@ -8,6 +8,7 @@ from typing import Callable, Dict, Any, Tuple
from db.stats_db import StatsDBOperator
from db.connection import DBConnectionManager
from wechat_ipad import WechatAPIClient
def plugin_stats_decorator(plugin_name: str) -> Callable:

View File

@@ -8,6 +8,7 @@ from typing import Callable, Dict, Any, Tuple, Union
from db.connection import DBConnectionManager
from db.points_db import PointsDBOperator, PointSource
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
from wechat_ipad import WechatAPIClient
def points_reward_decorator(points_calculator: Union[int, Callable], source_type: str = "other",
@@ -192,14 +193,17 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature =
return False, "没有权限"
# 检查是否开启了积分获取功能
if gbm and gbm.get_group_permission(roomid, Feature.SIGNIN) == PermissionStatus.DISABLED and gbm.get_group_permission(
if gbm and gbm.get_group_permission(roomid,
Feature.SIGNIN) == PermissionStatus.DISABLED and gbm.get_group_permission(
roomid, Feature.TASK_GAME) == PermissionStatus.DISABLED:
return await func(self, message)
# 获取消息信息
sender = message.get("sender", "")
roomid = message.get("roomid", "")
bot: WechatAPIClient = message.get("bot")
if not sender or not (roomid or sender):
return await func(self, message)
@@ -213,12 +217,12 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature =
user_points = points_db.get_user_points(sender, roomid)
if user_points["total_points"] < points:
# 积分不足
await self.message_util.send_text(
f"❌ 积分不足\n无法使用 {plugin_name} 功能\n"
f"🪙 先参与积分活动[签到,答题/t]赚取吧!\n"
f"💰 有: {user_points['total_points']} | 需: {points} |差: {points - user_points['total_points']} ",
(roomid if roomid else sender), sender
)
await bot.send_at_message((roomid if roomid else sender),
f"❌ 积分不足\n无法使用 {plugin_name} 功能\n"
f"🪙 先参与积分活动[签到,答题/t]赚取吧!\n"
f"💰 有: {user_points['total_points']} | 需: {points} |差: {points - user_points['total_points']} ",
[sender]
)
logger.info(f"用户 {sender} 积分不足,无法使用功能")
return False, "积分不足"
@@ -238,9 +242,9 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature =
# 添加对 response 的类型检查
if isinstance(response, str) and "积分" not in response:
response += f"\n\n💰 已消费 {points} 积分"
await self.message_util.send_text(
f"💰消费 {points} 积分",
(roomid if roomid else sender), sender
await bot.send_at_message(
(roomid if roomid else sender),
f"💰消费 {points} 积分", [sender]
)
else:
logger.warning(f"用户 {sender} 积分扣除失败: {deduct_result}")
@@ -262,10 +266,11 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature =
return False, "没有权限"
# 检查是否开启了积分获取功能
if gbm and gbm.get_group_permission(roomid, Feature.SIGNIN) == PermissionStatus.DISABLED and gbm.get_group_permission(
if gbm and gbm.get_group_permission(roomid,
Feature.SIGNIN) == PermissionStatus.DISABLED and gbm.get_group_permission(
roomid, Feature.TASK_GAME) == PermissionStatus.DISABLED:
return func(self, message)
# 获取消息信息
sender = message.get("sender", "")
roomid = message.get("roomid", "")