diff --git a/message_util.py b/message_util.py index caf35d9..5b7da1f 100644 --- a/message_util.py +++ b/message_util.py @@ -35,18 +35,13 @@ class MessageUtil: if at_list: if at_list == "notify@all": # @所有人 ats = " @所有人" - else: - wxids = at_list.split(",") - if len(wxids) > 0: - ats += self.client.get_nickname(receiver) - # {msg}{ats} 表示要发送的消息内容后面紧跟@,例如 北京天气情况为:xxx @张三 if ats == "": self.LOG.info(f"To {receiver}: {msg}") - self.client.send_text_message(receiver, "{msg}", "") + self.client.send_text_message(receiver, msg, "") else: self.LOG.info(f"To {receiver}: {ats}\r{msg}") - self.client.send_text_message(receiver, f"{ats}\n{msg}", at_list) + self.client.send_at_message(receiver, msg, at_list.split(",")) def send_file(self, file_path: str, receiver: str) -> str: """ @@ -107,7 +102,7 @@ class MessageUtil: return self.client.send_link_message(self.app_id, receiver, title, digest, url, thumburl) def invite_member(self, group_id, sender): - return self.client.invite_chatroom_member( sender, group_id) + return self.client.invite_chatroom_member(sender, group_id) def get_chatroom_members(self, group_id) -> dict: data = self.client.get_chatroom_member_list(self.app_id, group_id) diff --git a/plugins/dify/main.py b/plugins/dify/main.py index b0fe6c9..3e6eb4b 100644 --- a/plugins/dify/main.py +++ b/plugins/dify/main.py @@ -137,7 +137,7 @@ class DifyPlugin(MessagePluginInterface): query = re.sub(r"@.*?[\u2005|\s]", "", content).strip() if not query: - await bot.send_at_message(roomid, "请在@我的同时提供问题内容", sender) + await bot.send_at_message(roomid, "请在@我的同时提供问题内容", [sender]) return False, "没有提供问题内容" # self.message_util.send_text_msg("⏳AI 正在加油,请稍候… 😊", roomid, sender) @@ -156,7 +156,7 @@ class DifyPlugin(MessagePluginInterface): self.message_util.send_file(response, roomid) else: # 如果是普通文本,使用发送文本方法 - await bot.send_at_message((roomid if roomid else sender), response, sender) + await bot.send_at_message((roomid if roomid else sender), response, [sender]) return True, "发送成功" else: await bot.send_text_message((roomid if roomid else sender), "❌未能获取到回复,请稍后再试", sender) @@ -208,7 +208,7 @@ class DifyPlugin(MessagePluginInterface): else: # 如果是普通文本,使用发送文本方法 await bot.send_at_message((roomid if roomid else sender), response, - sender if roomid else "") + [sender if roomid else ""]) return True, "发送成功" else: client_msg_id, create_time, new_msg_id = await bot.send_text_message((roomid if roomid else sender), diff --git a/plugins/message_sign/main.py b/plugins/message_sign/main.py index a575293..9cfcb04 100644 --- a/plugins/message_sign/main.py +++ b/plugins/message_sign/main.py @@ -316,7 +316,7 @@ class MessageSignPlugin(MessagePluginInterface): output += f"\n今日词汇:{daily_vocab}" client_msg_id, create_time, new_msg_id = await self.bot.send_at_message((roomid if roomid else sender), - output, sender) + output, [sender]) revoke.add_message_to_revoke(roomid, client_msg_id, create_time, new_msg_id, 60) return True, "签到成功" @@ -325,7 +325,7 @@ class MessageSignPlugin(MessagePluginInterface): client_msg_id, create_time, new_msg_id = await self.bot.send_at_message((roomid if roomid else sender), f"签到出错:{e}", - sender) + [sender]) revoke.add_message_to_revoke(roomid, client_msg_id, create_time, new_msg_id, 3) return False, f"处理出错: {e}" diff --git a/utils/decorator/plugin_decorators.py b/utils/decorator/plugin_decorators.py index 5ef6a84..33da372 100644 --- a/utils/decorator/plugin_decorators.py +++ b/utils/decorator/plugin_decorators.py @@ -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: diff --git a/utils/decorator/points_decorator.py b/utils/decorator/points_decorator.py index 7392627..fec1a32 100644 --- a/utils/decorator/points_decorator.py +++ b/utils/decorator/points_decorator.py @@ -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", "")