koishi-plugin-ets2-tools-tmp 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  const changePointV1 = require("./changePointV1");
2
2
  const changePointV2 = require("./changePointV2");
3
3
 
4
- module.exports = async (ctx, cfg, session, target, changeType, quantity) => {
4
+ module.exports = async (ctx, cfg, session, target, changeType, quantity, reason) => {
5
5
  const { platformVersion } = cfg.mainSettings?.settings || {};
6
6
  const platform = (platformVersion || "v1").toLowerCase();
7
7
 
@@ -9,6 +9,6 @@ module.exports = async (ctx, cfg, session, target, changeType, quantity) => {
9
9
  case "v2":
10
10
  return await changePointV2(ctx, cfg, session, target, changeType, quantity);
11
11
  default:
12
- return await changePointV1(ctx, cfg, session, target, changeType, quantity);
12
+ return await changePointV1(ctx, cfg, session, target, changeType, quantity, reason);
13
13
  }
14
14
  };
@@ -1,3 +1,110 @@
1
- module.exports = async (ctx, cfg, session, target, changeType, quantity) => {
2
- return "V1.0平台暂不支持积分修改功能";
1
+ module.exports = async (ctx, cfg, session, target, changeType, quantity, reason) => {
2
+ const { url, token, logOutput } = cfg.mainSettings?.settings || {};
3
+ const { adminUsers } = cfg.changePoint?.settings || {};
4
+ const currentUserQQ = session.userId;
5
+ const isPrivateChat = session.channelId === `private:${currentUserQQ}`;
6
+ const isAdmin = adminUsers.includes(currentUserQQ);
7
+
8
+ const log = (msg) => logOutput && ctx.logger.info(msg);
9
+
10
+ const parseAtQQ = (raw) => {
11
+ if (!raw?.startsWith("<at ")) return raw;
12
+ const idStart = raw.indexOf('id="');
13
+ if (idStart === -1) return "";
14
+ const idEnd = raw.indexOf('"', idStart + 4);
15
+ if (idEnd === -1) return "";
16
+ return raw.substring(idStart + 4, idEnd);
17
+ };
18
+
19
+ try {
20
+ if (isPrivateChat) {
21
+ return "积分修改功能仅支持群聊使用";
22
+ }
23
+
24
+ if (!isAdmin) {
25
+ return "您没有权限使用积分修改功能,请联系管理员";
26
+ }
27
+
28
+ if (!token) return "未配置车队平台API认证令牌";
29
+
30
+ if (!changeType || !["增加", "减少"].includes(changeType)) {
31
+ return "请指定操作类型:增加 或 减少";
32
+ }
33
+
34
+ if (!quantity || isNaN(Number(quantity)) || Number(quantity) <= 0) {
35
+ return "请输入有效的积分数量(正整数)";
36
+ }
37
+
38
+ if (!reason) {
39
+ return "请输入备注原因(必填)";
40
+ }
41
+
42
+ const baseUrl = url || "open.vtcm.link";
43
+ let userId;
44
+
45
+ if (target) {
46
+ const parsedQQ = parseAtQQ(target);
47
+ const isQQ = parsedQQ && /^\d+$/.test(parsedQQ);
48
+ const isTeamId = !isQQ && /^\d+$/.test(target);
49
+
50
+ let queryUrl;
51
+ if (isQQ) {
52
+ queryUrl = `https://${baseUrl}/api/user/info/list?page=0&limit=7&tmpId=&tmpName=&teamId=&qq=${encodeURIComponent(parsedQQ)}&state=0&teamRole=&token=${token}`;
53
+ log(`[V1] 通过QQ号查询成员: ${parsedQQ}`);
54
+ } else if (isTeamId) {
55
+ queryUrl = `https://${baseUrl}/api/user/info/list?page=0&limit=7&tmpId=&tmpName=&teamId=${encodeURIComponent(target)}&qq=&state=0&teamRole=&token=${token}`;
56
+ log(`[V1] 通过车队编号查询成员: ${target}`);
57
+ } else {
58
+ return "目标用户格式不正确,请输入车队编号或@群成员";
59
+ }
60
+
61
+ log(`[V1] 查询成员URL: ${queryUrl.replace(token, "***")}`);
62
+ const queryResponse = await ctx.http.get(queryUrl, { timeout: 10000 });
63
+ log(`[V1] 查询成员响应: code=${queryResponse.code}, listCount=${queryResponse.page?.list?.length}`);
64
+
65
+ if (queryResponse.code !== 0) {
66
+ return queryResponse.msg || "成员信息查询失败";
67
+ }
68
+
69
+ const list = queryResponse.page?.list;
70
+ if (!list || list.length === 0) {
71
+ return "没有找到该成员";
72
+ }
73
+
74
+ userId = list[0].id;
75
+ log(`[V1] 获取到成员ID: ${userId}`);
76
+ } else {
77
+ return "请指定目标用户(车队编号或@群成员)";
78
+ }
79
+
80
+ const changeTypeNum = changeType === "增加" ? 1 : 2;
81
+ const quantityNum = Number(quantity);
82
+
83
+ const changeUrl = `https://${baseUrl}/api/point/changeRecord/add`;
84
+ const requestBody = {
85
+ userId: userId,
86
+ changeType: changeTypeNum,
87
+ quantity: String(quantityNum),
88
+ reason: reason
89
+ };
90
+ log(`[V1] 积分修改请求: ${changeUrl}, body: ${JSON.stringify(requestBody)}`);
91
+ const changeResponse = await ctx.http.post(changeUrl, requestBody, { timeout: 10000 });
92
+ log(`[V1] 积分修改响应: ${JSON.stringify(changeResponse)}`);
93
+
94
+ if (changeResponse.code !== 0) {
95
+ return changeResponse.msg || "积分修改失败";
96
+ }
97
+
98
+ return `积分修改成功!\n目标ID: ${userId}\n操作: ${changeType} ${quantityNum} 积分\n备注: ${reason}`;
99
+
100
+ } catch (error) {
101
+ ctx.logger.error(`[V1] 积分修改错误: ${error.message}`);
102
+ if (error.response) {
103
+ return `请求失败: ${error.response.status} ${error.response.statusText}`;
104
+ } else if (error.code) {
105
+ return `网络错误: ${error.code}`;
106
+ } else {
107
+ return "系统错误,请稍后重试";
108
+ }
109
+ }
3
110
  };
package/lib/index.js CHANGED
@@ -351,11 +351,11 @@ function registerBaseCommands(ctx, cfg) {
351
351
  }
352
352
 
353
353
  if (cfg.commands?.changePoint) {
354
- ctx.command(`积分修改 <target:string> <changeType:string> <quantity:string>`, "修改欧卡车队平台积分")
355
- .usage("管理员专用。changeType: 增加 或 减少。target可输入UID或@群成员")
356
- .example(`积分修改 @某人 增加 10 - 增加@某人10积分`)
357
- .example(`积分修改 10000 减少 5 - 减少UID为10000的用户5积分`)
358
- .action(async ({ session }, target, changeType, quantity) => await commands.changePoint(ctx, cfg, session, target, changeType, quantity));
354
+ ctx.command(`积分修改 <target:string> <changeType:string> <quantity:string> <reason:string>`, "修改欧卡车队平台积分")
355
+ .usage("管理员专用。changeType: 增加 或 减少。target可输入车队编号(V1)或UID(V2)或@群成员。reason为备注原因(V1必填)")
356
+ .example(`积分修改 @某人 增加 10 活动奖励 - 增加@某人10积分,备注活动奖励`)
357
+ .example(`积分修改 5 减少 5 违规扣分 - 减少车队编号5的用户5积分,备注违规扣分`)
358
+ .action(async ({ session }, target, changeType, quantity, reason) => await commands.changePoint(ctx, cfg, session, target, changeType, quantity, reason));
359
359
  }
360
360
 
361
361
  if (cfg.commands?.addMember) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ets2-tools-tmp",
3
3
  "description": "欧卡2 TruckersMP信息查询、车队平台查询及活动提醒",
4
- "version": "3.0.0",
4
+ "version": "3.0.1",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"