Browse Source

MCP加入更换跑区功能

Pchen. 1 month ago
parent
commit
34560c8bcd
2 changed files with 62 additions and 3 deletions
  1. 28 3
      apis/MCP/McpRPC.js
  2. 34 0
      lib/Lepao/Mcp.js

+ 28 - 3
apis/MCP/McpRPC.js

@@ -138,9 +138,34 @@ class McpRpc extends API {
                                 "required": ["sender", "email", "title", "content"]
                             }
                         },
+                        {
+                            "name": "change_area",
+                            "description": "Set the running area for the user. If the user requests a random area, use '随机分配'",
+                            "inputSchema": {
+                                "type": "object",
+                                "properties": {
+                                    "sender": {
+                                        "type": "string",
+                                        "description": "Unique user identifier from the chat platform"
+                                    },
+                                    "area": {
+                                        "type": "string",
+                                        "enum": [
+                                            "兰花湖校区跑区",
+                                            "主校区北跑区",
+                                            "主校区南跑区",
+                                            "重庆工商大学茶园校区",
+                                            "随机分配"
+                                        ],
+                                        "description": "Running area. Must be one of the predefined areas, or '随机分配' for random assignment"
+                                    }
+                                },
+                                "required": ["sender", "area"]
+                            }
+                        },
                         {
                             "name": "change_auto_time",
-                            "description": "Set the automatic running start hour when the user wants to schedule running time",
+                            "description": "Set the automatic running start hour. Use -1 if the user wants a random time assigned",
                             "inputSchema": {
                                 "type": "object",
                                 "properties": {
@@ -150,9 +175,9 @@ class McpRpc extends API {
                                     },
                                     "auto_time": {
                                         "type": "integer",
-                                        "minimum": 7,
+                                        "minimum": -1,
                                         "maximum": 23,
-                                        "description": "Hour of day to start running (7-23)"
+                                        "description": "Hour of day to start running (7-23), or -1 to assign a random time"
                                     }
                                 },
                                 "required": ["sender", "auto_time"]

+ 34 - 0
lib/Lepao/Mcp.js

@@ -20,6 +20,8 @@ class Mcp {
             { label: '周日', value: 0 }
         ]
 
+        this.area = ["兰花湖校区跑区", "主校区北跑区", "主校区南跑区", "重庆工商大学茶园校区","随机分配"]
+
         this.autoTimeLabel = (record) => {
             if (record.auto_time === -1) {
                 if (record.today_auto_time)
@@ -247,6 +249,38 @@ class Mcp {
         }
     }
 
+    async change_area({ sender, area }) {
+        try {
+            if ([sender, area].some(value => value === '' || value === null || value === undefined))
+                return '缺少参数'
+
+            this.logger.info(`MCP接收更换跑区请求:${sender},area:${area}`)
+            
+            if(!this.area.includes(area)) return '系统无该跑区,无法设置'
+
+            let insertSql = `
+                UPDATE 
+                    lepao_account la
+                JOIN 
+                    lepao_extra le 
+                ON 
+                    la.student_num = le.student_num
+                SET 
+                    la.area = ?
+                WHERE 
+                    le.bot_account = ?
+            `
+            let insertRows = await db.query(insertSql, [area === "随机分配" ? '' : area, sender])
+            if (!insertRows || insertRows.affectedRows === 0)
+                return '系统出错,请稍后再试'
+
+            return `操作成功`
+        } catch (error) {
+            this.logger.error(`MCP更换跑区出错:${error.stack}`)
+            return '系统出错,请稍后再试'
+        }
+    }
+
     async change_auto_time({ sender, auto_time }) {
         try {
             if ([sender, auto_time].some(value => value === '' || value === null || value === undefined))