调整xml内容
This commit is contained in:
@@ -8,12 +8,14 @@ from datetime import datetime
|
||||
robot_bp = Blueprint('robot', __name__, url_prefix='/robot')
|
||||
LOG = logger
|
||||
|
||||
|
||||
# 机器人管理页面
|
||||
@robot_bp.route('/')
|
||||
@login_required
|
||||
def robot_management():
|
||||
return render_template('robot_management.html')
|
||||
|
||||
|
||||
# API路由
|
||||
@robot_bp.route('/api/groups')
|
||||
@login_required
|
||||
@@ -45,7 +47,7 @@ def api_robot_groups():
|
||||
try:
|
||||
robot_status = GroupBotManager.get_group_permission(group_id, Feature.ROBOT)
|
||||
except:
|
||||
robot_status = PermissionStatus.UNKNOWN
|
||||
robot_status = PermissionStatus.DISABLED
|
||||
|
||||
group_data.append({
|
||||
"group_id": group_id,
|
||||
@@ -66,6 +68,7 @@ def api_robot_groups():
|
||||
LOG.error(f"获取群组列表失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@robot_bp.route('/api/group/<group_id>/permissions')
|
||||
@login_required
|
||||
def api_robot_group_permissions(group_id):
|
||||
@@ -86,6 +89,7 @@ def api_robot_group_permissions(group_id):
|
||||
LOG.error(f"获取群组权限失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@robot_bp.route('/api/group/<group_id>/permissions', methods=['POST'])
|
||||
@login_required
|
||||
def api_update_robot_permissions(group_id):
|
||||
@@ -115,6 +119,7 @@ def api_update_robot_permissions(group_id):
|
||||
LOG.error(f"更新群组权限失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 400
|
||||
|
||||
|
||||
@robot_bp.route('/api/batch_operation', methods=['POST'])
|
||||
@login_required
|
||||
def api_robot_batch_operation():
|
||||
@@ -138,6 +143,7 @@ def api_robot_batch_operation():
|
||||
LOG.error(f"批量操作失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 400
|
||||
|
||||
|
||||
@robot_bp.route('/api/add_group', methods=['POST'])
|
||||
@login_required
|
||||
def api_add_group():
|
||||
@@ -150,10 +156,10 @@ def api_add_group():
|
||||
return jsonify({"success": False, "error": "群组ID不能为空"}), 400
|
||||
|
||||
group_id = group_id.strip()
|
||||
#如果group_id 不是@chatroom 结尾,这提示错误
|
||||
# 如果group_id 不是@chatroom 结尾,这提示错误
|
||||
if not group_id.endswith("@chatroom"):
|
||||
return jsonify({"success": False, "error": "群组ID必须以 @chatroom 结尾"}), 400
|
||||
|
||||
|
||||
# 检查群组是否已存在
|
||||
if group_id in GroupBotManager.local_cache["group_list"]:
|
||||
return jsonify({"success": False, "error": "该群组已存在"}), 400
|
||||
@@ -182,6 +188,7 @@ def api_add_group():
|
||||
LOG.error(f"添加群组失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@robot_bp.route('/api/group/<group_id>/message_trend')
|
||||
@login_required
|
||||
def api_group_message_trend(group_id):
|
||||
@@ -214,6 +221,7 @@ def api_group_message_trend(group_id):
|
||||
LOG.error(f"获取群组消息趋势数据出错: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
# 添加缺失的群组状态更新接口
|
||||
@robot_bp.route('/api/group/<group_id>/status', methods=['POST'])
|
||||
@login_required
|
||||
@@ -222,23 +230,23 @@ def api_update_group_status(group_id):
|
||||
server = current_app.dashboard_server
|
||||
data = request.json
|
||||
status = data.get('status')
|
||||
|
||||
|
||||
if status == 'disabled':
|
||||
# 禁用该群组的所有功能
|
||||
LOG.info(f"正在禁用群组 {group_id} 的所有功能")
|
||||
|
||||
|
||||
# 获取所有功能并禁用
|
||||
for feature in Feature:
|
||||
GroupBotManager.set_group_permission(group_id, feature, PermissionStatus.DISABLED)
|
||||
|
||||
|
||||
# 特殊处理ROBOT功能,从群组列表中移除
|
||||
if group_id in GroupBotManager.local_cache["group_list"]:
|
||||
GroupBotManager.local_cache["group_list"].remove(group_id)
|
||||
|
||||
|
||||
# 从Redis中移除
|
||||
r = server.db_manager.get_redis_connection()
|
||||
r.srem("group:list", group_id)
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": f"群组 {group_id} 的所有功能已禁用"
|
||||
@@ -246,18 +254,18 @@ def api_update_group_status(group_id):
|
||||
elif status == 'enabled':
|
||||
# 启用该群组的基本功能
|
||||
LOG.info(f"正在启用群组 {group_id} 的基本功能")
|
||||
|
||||
|
||||
# 添加到群组列表
|
||||
if group_id not in GroupBotManager.local_cache["group_list"]:
|
||||
GroupBotManager.local_cache["group_list"].add(group_id)
|
||||
|
||||
|
||||
# 添加到Redis
|
||||
r = server.db_manager.get_redis_connection()
|
||||
r.sadd("group:list", group_id)
|
||||
|
||||
|
||||
# 启用ROBOT基本功能
|
||||
GroupBotManager.set_group_permission(group_id, Feature.ROBOT, PermissionStatus.ENABLED)
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": f"群组 {group_id} 的基本功能已启用"
|
||||
@@ -267,7 +275,7 @@ def api_update_group_status(group_id):
|
||||
"success": False,
|
||||
"error": "不支持的状态值,只接受 'enabled' 或 'disabled'"
|
||||
}), 400
|
||||
|
||||
|
||||
except Exception as e:
|
||||
LOG.error(f"更新群组状态失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
@@ -16,6 +16,7 @@ from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotMan
|
||||
import mysql.connector.pooling
|
||||
|
||||
from wechat_ipad import WechatAPIClient
|
||||
from wechat_ipad.models.message import WxMessage
|
||||
|
||||
|
||||
class PointTradePlugin(MessagePluginInterface):
|
||||
@@ -161,8 +162,9 @@ class PointTradePlugin(MessagePluginInterface):
|
||||
command = content.split(" ")
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
xml = message.get("xml", "")
|
||||
|
||||
msg: WxMessage = message.get("full_wx_msg")
|
||||
xml = msg.msg_source
|
||||
# 检查命令格式
|
||||
if len(command) < 3:
|
||||
client_msg_id, create_time, new_msg_id = await self.bot.send_at_message((roomid if roomid else sender),
|
||||
|
||||
Reference in New Issue
Block a user