koishi-plugin-jscn-aaaquery 1.0.4 → 1.0.6

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.
Files changed (3) hide show
  1. package/lib/index.js +93 -26
  2. package/package.json +1 -1
  3. package/readme.md +43 -14
package/lib/index.js CHANGED
@@ -164,7 +164,11 @@ function apply(ctx, config) {
164
164
  }
165
165
  __name(formatAccount, "formatAccount");
166
166
  function isAccountResponseComplete(data) {
167
- return !!(data.accessUserName && data.onlineStatus && data.isPass && data.userIp && data.mac && data.maxUpSpeed !== void 0 && data.maxDownSpeed !== void 0 && data.accessDomain && data.startTime && data.startTimeSum !== void 0 && data.nickName);
167
+ const hasBasicFields = !!(data.accessUserName && data.onlineStatus && data.isPass);
168
+ if (data.onlineStatus === "离线" || data.isPass === "原因未知") {
169
+ return hasBasicFields;
170
+ }
171
+ return hasBasicFields && !!(data.userIp && data.mac && data.maxUpSpeed !== void 0 && data.maxDownSpeed !== void 0 && data.accessDomain && data.startTime && data.startTimeSum !== void 0 && data.nickName);
168
172
  }
169
173
  __name(isAccountResponseComplete, "isAccountResponseComplete");
170
174
  async function getToken() {
@@ -226,6 +230,29 @@ function apply(ctx, config) {
226
230
  });
227
231
  console.log("查询响应:", JSON.stringify(response, null, 2));
228
232
  if (response.status === 200 && response.data) {
233
+ if (response.data.isPass === "上线失败") {
234
+ console.log("账号上线失败,将使用失败信息");
235
+ if (!response.data.startTimeSum) response.data.startTimeSum = 0;
236
+ if (!response.data.maxUpSpeed) response.data.maxUpSpeed = 0;
237
+ if (!response.data.maxDownSpeed) response.data.maxDownSpeed = 0;
238
+ if (!response.data.startTime) response.data.startTime = response.data.onlineFailTime || "未知";
239
+ if (!response.data.nickName) response.data.nickName = response.data.nickName || "未知";
240
+ setCache("account", { account: formattedAccount }, response.data);
241
+ return response.data;
242
+ }
243
+ if (response.data.onlineStatus === "离线" || response.data.isPass === "原因未知") {
244
+ console.log("账号离线或状态异常,将使用有限信息");
245
+ if (!response.data.startTimeSum) response.data.startTimeSum = 0;
246
+ if (!response.data.maxUpSpeed) response.data.maxUpSpeed = 0;
247
+ if (!response.data.maxDownSpeed) response.data.maxDownSpeed = 0;
248
+ if (!response.data.startTime) response.data.startTime = "未知";
249
+ if (!response.data.nickName) response.data.nickName = "未知";
250
+ if (!response.data.mac) response.data.mac = "未知";
251
+ if (!response.data.userIp) response.data.userIp = "未知";
252
+ if (!response.data.accessDomain) response.data.accessDomain = "未知";
253
+ setCache("account", { account: formattedAccount }, response.data);
254
+ return response.data;
255
+ }
229
256
  if (!isAccountResponseComplete(response.data)) {
230
257
  throw new Error("账号信息有误,请检查账号是否正确");
231
258
  }
@@ -865,16 +892,36 @@ function apply(ctx, config) {
865
892
  // `RADIUS用户密码: ${user.password}`,
866
893
  `RADIUS状态: ${translateUserStatus(user.user_status)} ${user.user_status === "active" ? "✅" : user.user_status === "suspend" ? "⚠️" : "❌"}`,
867
894
  "",
868
- `状态: ${accountInfo.onlineStatus} ${accountInfo.onlineStatus.includes("在线") ? "✅" : "❌"}`,
869
- `认证: ${accountInfo.isPass} ${accountInfo.isPass.includes("成功") ? "✅" : "❌"}`,
870
- `IP地址: ${accountInfo.userIp}`,
871
- `MAC地址: ${accountInfo.mac}`,
872
- `最大上行: ${accountInfo.maxUpSpeed}Mbps`,
873
- `最大下行: ${accountInfo.maxDownSpeed}Mbps`,
874
- `开始时间: ${accountInfo.startTime}`,
875
- `在线时长: ${durationText}`,
876
- ""
895
+ `状态: ${accountInfo.onlineStatus} ${accountInfo.onlineStatus === "在线" ? "✅" : "❌"}`,
896
+ `认证: ${accountInfo.isPass} ${accountInfo.isPass.includes("成功") ? "✅" : "❌"}`
877
897
  ];
898
+ if (accountInfo.isPass === "上线失败") {
899
+ message.push(
900
+ `MAC地址: ${accountInfo.mac || "未知"}`,
901
+ `失败时间: ${accountInfo.onlineFailTime || "未知"}`,
902
+ `失败原因: ${accountInfo.onlineFailReason || "未知"}`,
903
+ `回复消息: ${accountInfo.failReplyMessage || "未知"}`,
904
+ `原因分析: ${accountInfo.reasonAnaly || "未知"}`
905
+ );
906
+ } else if (accountInfo.onlineStatus === "离线" || accountInfo.isPass === "原因未知") {
907
+ message.push(
908
+ `MAC地址: ${accountInfo.mac || "未知"}`,
909
+ `最后IP: ${accountInfo.userIp || "未知"}`
910
+ );
911
+ if (accountInfo.startTime) {
912
+ message.push(`最后在线: ${accountInfo.startTime || "未知"}`);
913
+ }
914
+ } else {
915
+ message.push(
916
+ `IP地址: ${accountInfo.userIp}`,
917
+ `MAC地址: ${accountInfo.mac}`,
918
+ `最大上行: ${accountInfo.maxUpSpeed}Mbps`,
919
+ `最大下行: ${accountInfo.maxDownSpeed}Mbps`,
920
+ `开始时间: ${accountInfo.startTime}`,
921
+ `在线时长: ${durationText}`
922
+ );
923
+ }
924
+ message.push("");
878
925
  if (orders && orders.length > 0) {
879
926
  message.push("🛒 订购信息");
880
927
  message.push("--------------------------------");
@@ -907,7 +954,7 @@ function apply(ctx, config) {
907
954
  });
908
955
  });
909
956
  });
910
- ctx.command("账号查询 <account:string>", "查询宽带账号状态").action(async ({ session }, account) => {
957
+ ctx.command("账号查询 <account:string>", "查询宽带账号状态").alias("/账号查询").action(async ({ session }, account) => {
911
958
  if (!account) return "请输入要查询的账号";
912
959
  return new Promise((resolve) => {
913
960
  addToMessageQueue(session, async () => {
@@ -936,16 +983,36 @@ function apply(ctx, config) {
936
983
  // `RADIUS用户密码: ${user.password}`,
937
984
  `RADIUS状态: ${translateUserStatus(user.user_status)} ${user.user_status === "active" ? "✅" : user.user_status === "suspend" ? "⚠️" : "❌"}`,
938
985
  "",
939
- `状态: ${accountInfo.onlineStatus} ${accountInfo.onlineStatus.includes("在线") ? "✅" : "❌"}`,
940
- `认证: ${accountInfo.isPass} ${accountInfo.isPass.includes("成功") ? "✅" : "❌"}`,
941
- `IP地址: ${accountInfo.userIp}`,
942
- `MAC地址: ${accountInfo.mac}`,
943
- `最大上行: ${accountInfo.maxUpSpeed}Mbps`,
944
- `最大下行: ${accountInfo.maxDownSpeed}Mbps`,
945
- `开始时间: ${accountInfo.startTime}`,
946
- `在线时长: ${durationText}`,
947
- ""
986
+ `状态: ${accountInfo.onlineStatus} ${accountInfo.onlineStatus === "在线" ? "✅" : "❌"}`,
987
+ `认证: ${accountInfo.isPass} ${accountInfo.isPass.includes("成功") ? "✅" : "❌"}`
948
988
  ];
989
+ if (accountInfo.isPass === "上线失败") {
990
+ message.push(
991
+ `MAC地址: ${accountInfo.mac || "未知"}`,
992
+ `失败时间: ${accountInfo.onlineFailTime || "未知"}`,
993
+ `失败原因: ${accountInfo.onlineFailReason || "未知"}`,
994
+ `回复消息: ${accountInfo.failReplyMessage || "未知"}`,
995
+ `原因分析: ${accountInfo.reasonAnaly || "未知"}`
996
+ );
997
+ } else if (accountInfo.onlineStatus === "离线" || accountInfo.isPass === "原因未知") {
998
+ message.push(
999
+ `MAC地址: ${accountInfo.mac || "未知"}`,
1000
+ `最后IP: ${accountInfo.userIp || "未知"}`
1001
+ );
1002
+ if (accountInfo.startTime) {
1003
+ message.push(`最后在线: ${accountInfo.startTime || "未知"}`);
1004
+ }
1005
+ } else {
1006
+ message.push(
1007
+ `IP地址: ${accountInfo.userIp}`,
1008
+ `MAC地址: ${accountInfo.mac}`,
1009
+ `最大上行: ${accountInfo.maxUpSpeed}Mbps`,
1010
+ `最大下行: ${accountInfo.maxDownSpeed}Mbps`,
1011
+ `开始时间: ${accountInfo.startTime}`,
1012
+ `在线时长: ${durationText}`
1013
+ );
1014
+ }
1015
+ message.push("");
949
1016
  if (orders && orders.length > 0) {
950
1017
  message.push("🛒 订购信息");
951
1018
  message.push("--------------------------------");
@@ -972,7 +1039,7 @@ function apply(ctx, config) {
972
1039
  resolve();
973
1040
  });
974
1041
  });
975
- ctx.command("账号详情 <account:string>", "查询宽带账号详细记录").action(async ({ session }, account) => {
1042
+ ctx.command("账号详情 <account:string>", "查询宽带账号详细记录").alias("/账号详情").action(async ({ session }, account) => {
976
1043
  if (!account) return "请输入要查询的账号";
977
1044
  return new Promise((resolve) => {
978
1045
  addToMessageQueue(session, async () => {
@@ -1004,7 +1071,7 @@ function apply(ctx, config) {
1004
1071
  resolve();
1005
1072
  });
1006
1073
  });
1007
- ctx.command("终端查询 <mac:string>", "查询终端基本信息").action(async ({ session }, mac) => {
1074
+ ctx.command("终端查询 <mac:string>", "查询终端基本信息").alias("/终端查询").action(async ({ session }, mac) => {
1008
1075
  if (!mac) return "请输入要查询的MAC地址";
1009
1076
  return new Promise((resolve) => {
1010
1077
  addToMessageQueue(session, async () => {
@@ -1046,7 +1113,7 @@ function apply(ctx, config) {
1046
1113
  resolve();
1047
1114
  });
1048
1115
  });
1049
- ctx.command("终端详细查询 <mac:string>", "查询终端详细信息").action(async ({ session }, mac) => {
1116
+ ctx.command("终端详细查询 <mac:string>", "查询终端详细信息").alias("/终端详细查询").action(async ({ session }, mac) => {
1050
1117
  if (!mac) return "请输入要查询的MAC地址";
1051
1118
  return new Promise((resolve) => {
1052
1119
  addToMessageQueue(session, async () => {
@@ -1103,7 +1170,7 @@ function apply(ctx, config) {
1103
1170
  resolve();
1104
1171
  });
1105
1172
  });
1106
- ctx.command("日志查询 <mac:string> [startTime:string] [endTime:string]", "查询终端工单日志").action(async ({ session }, mac, startTime, endTime) => {
1173
+ ctx.command("日志查询 <mac:string> [startTime:string] [endTime:string]", "查询终端工单日志").alias("/日志查询").action(async ({ session }, mac, startTime, endTime) => {
1107
1174
  if (!mac) return "请输入要查询的MAC地址";
1108
1175
  try {
1109
1176
  await session?.send("正在查询日志,请稍候...");
@@ -1160,7 +1227,7 @@ function apply(ctx, config) {
1160
1227
  return "查询失败,请稍后重试";
1161
1228
  }
1162
1229
  });
1163
- ctx.command("用户查询 <account:string>", "查询RADIUS用户信息").action(async ({ session }, account) => {
1230
+ ctx.command("用户查询 <account:string>", "查询RADIUS用户信息").alias("/用户查询").action(async ({ session }, account) => {
1164
1231
  if (!account) return "请输入要查询的账号";
1165
1232
  return new Promise((resolve) => {
1166
1233
  addToMessageQueue(session, async () => {
@@ -1174,7 +1241,7 @@ function apply(ctx, config) {
1174
1241
  "🔐 RADIUS用户信息",
1175
1242
  "--------------------------------",
1176
1243
  `账号: ${user.login_name}`,
1177
- `密码: ${user.password}`,
1244
+ // `密码: ${user.password}`,
1178
1245
  `状态: ${translateUserStatus(user.user_status)} ${user.user_status === "active" ? "✅" : user.user_status === "suspend" ? "⚠️" : "❌"}`,
1179
1246
  `漫游状态: ${user.roam_status === "0" ? "允许漫游" : "禁止漫游"}`,
1180
1247
  `分公司标识: ${user.org_code}`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-jscn-aaaquery",
3
3
  "description": "江苏有线无锡分公司宽带信息查询插件",
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -11,24 +11,28 @@
11
11
  ## 命令列表
12
12
 
13
13
  ### 1. 账号查询
14
- - 命令格式:`账号查询 <账号>`
15
- - 示例:`账号查询 GDC8510019239048`
14
+ - 命令格式:`账号查询 <账号>` 或 `/账号查询 <账号>`
15
+ - 示例:`账号查询 GDC8510019239048` 或 `/账号查询 GDC8510019239048`
16
16
  - 功能:查询宽带账号的基本信息,包括在线状态、IP地址、MAC地址等。
17
17
  - 返回信息:
18
18
  - RADIUS用户信息:状态、密码等
19
19
  - 账号基本信息:在线状态、认证状态、IP地址、MAC地址等
20
20
  - 订购信息:订购状态、服务名称、生效时间、失效时间等
21
+ - 账号状态处理:
22
+ - 在线状态:显示IP地址、MAC地址、带宽、时长等完整信息
23
+ - 离线状态:显示最后IP地址、MAC地址、最后在线时间等基本信息
24
+ - 上线失败:显示MAC地址、失败时间、失败原因、回复消息、原因分析等故障信息
21
25
  - 备注:账号会自动转换为大写,在线时长会以"天小时分钟"的形式显示。
22
26
 
23
27
  ### 2. 账号详情
24
- - 命令格式:`账号详情 <账号>`
25
- - 示例:`账号详情 GDC8510019239048`
28
+ - 命令格式:`账号详情 <账号>` 或 `/账号详情 <账号>`
29
+ - 示例:`账号详情 GDC8510019239048` 或 `/账号详情 GDC8510019239048`
26
30
  - 功能:查询宽带账号的详细记录,包括登录时间、登出时间等。
27
31
  - 备注:账号会自动转换为大写。
28
32
 
29
33
  ### 3. 终端查询
30
- - 命令格式:`终端查询 <MAC地址>`
31
- - 示例:`终端查询 00:11:22:33:44:55`
34
+ - 命令格式:`终端查询 <MAC地址>` 或 `/终端查询 <MAC地址>`
35
+ - 示例:`终端查询 00:11:22:33:44:55` 或 `/终端查询 00:11:22:33:44:55`
32
36
  - 功能:查询终端的基本信息,包括光功率和业务配置信息。
33
37
  - 返回信息:
34
38
  - 设备基本信息:状态、设备名称等
@@ -42,8 +46,8 @@
42
46
  - 中文符号分隔:`00:11。22-33|44:55`
43
47
 
44
48
  ### 4. 终端详细查询
45
- - 命令格式:`终端详细查询 <MAC地址>`
46
- - 示例:`终端详细查询 00:11:22:33:44:55`
49
+ - 命令格式:`终端详细查询 <MAC地址>` 或 `/终端详细查询 <MAC地址>`
50
+ - 示例:`终端详细查询 00:11:22:33:44:55` 或 `/终端详细查询 00:11:22:33:44:55`
47
51
  - 功能:查询终端的详细信息,包括机房、设备名称、OLT IP、工单信息等。
48
52
  - 返回信息:
49
53
  - 设备详细信息:状态、机房、设备名称、OLT IP、PON端口、逻辑号等
@@ -52,11 +56,11 @@
52
56
  - 业务配置信息:端口VLAN和工单VLAN配置详情
53
57
 
54
58
  ### 5. 日志查询
55
- - 命令格式:`日志查询 <MAC地址> [开始时间] [结束时间]`
59
+ - 命令格式:`日志查询 <MAC地址> [开始时间] [结束时间]` 或 `/日志查询 <MAC地址> [开始时间] [结束时间]`
56
60
  - 示例:
57
- - `日志查询 00:11:22:33:44:55`
58
- - `日志查询 00:11:22:33:44:55 2024.3.1 2024.3.10`
59
- - `日志查询 00:11:22:33:44:55 三月一日`
61
+ - `日志查询 00:11:22:33:44:55` 或 `/日志查询 00:11:22:33:44:55`
62
+ - `日志查询 00:11:22:33:44:55 2024.3.1 2024.3.10` 或 `/日志查询 00:11:22:33:44:55 2024.3.1 2024.3.10`
63
+ - `日志查询 00:11:22:33:44:55 三月一日` 或 `/日志查询 00:11:22:33:44:55 三月一日`
60
64
  - 功能:查询终端的上线分析日志。
61
65
  - 时间格式支持:
62
66
  - 完整日期:`2024.3.1` 或 `2024/3/1`
@@ -64,8 +68,8 @@
64
68
  - 中文日期:`三月一日` 或 `三月一号`
65
69
 
66
70
  ### 6. 用户查询
67
- - 命令格式:`用户查询 <账号>`
68
- - 示例:`用户查询 GDC8510013590471`
71
+ - 命令格式:`用户查询 <账号>` 或 `/用户查询 <账号>`
72
+ - 示例:`用户查询 GDC8510013590471` 或 `/用户查询 GDC8510013590471`
69
73
  - 功能:查询RADIUS系统中的用户信息和订购状态。
70
74
  - 返回信息:
71
75
  - 用户基本信息:账号、密码、状态、漫游设置等
@@ -130,10 +134,35 @@
130
134
  5. 如果查询失败,请检查输入格式是否正确。
131
135
  6. 确保运维系统和RADIUS系统API能够正常访问。
132
136
  7. 账号查询时会先检查RADIUS授权,如授权有误将不继续查询账号信息。
137
+ 8. 光功率刷新功能将无论设备是否在线都会尝试刷新,确保获取最新数据。
138
+ 9. 针对上线失败或离线状态的账号,系统也能提供有用的信息,不会简单报错。
139
+ 10. 所有命令支持带斜杠(如`/账号查询`)和不带斜杠(如`账号查询`)两种触发方式,提高命令输入的灵活性。
140
+
141
+ ## 开发相关
142
+
143
+ 为了支持开发过程中的热重载功能,需要确保:
144
+ 1. 在`koishi.yml`中正确配置hmr插件
145
+ 2. 安装并启用loader服务
146
+ 3. 在开发环境下运行Koishi时设置`NODE_ENV=development`
147
+
148
+ ```yaml
149
+ # 开发相关配置示例
150
+ group:develop:
151
+ $if: env.NODE_ENV === 'development'
152
+ hmr:
153
+ root:
154
+ - .
155
+ loader:
156
+ watch: true
157
+ ```
133
158
 
134
159
  ## 更新日志
135
160
 
136
161
  ### 最新更新
162
+ - 增加了对双触发词的支持,同时兼容带斜杠(如`/账号查询`)和不带斜杠(如`账号查询`)的命令格式
163
+ - 增加了离线状态和上线失败状态的特殊处理,提供更多有用信息
164
+ - 修复了状态图标显示问题,确保"不在线"状态正确显示❌图标
165
+ - 优化了数据完整性检查,对不同状态采用不同的验证标准
137
166
  - 增加了光功率评估功能,直观显示接收光功率是否在正常范围内
138
167
  - 优化了在线时长显示,支持天/小时/分钟格式
139
168
  - 增强了MAC地址格式处理,支持中文符号分隔