koishi-plugin-ets2-tools-tmp 3.4.3 → 3.4.5
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.
- package/lib/command/tmpActivityService/tmpActivityServiceV1.js +197 -26
- package/lib/command/tmpActivityService.js +12 -3
- package/lib/command/tmpMileageRanking.js +1 -1
- package/lib/command/tmpVersionCheck.js +278 -12
- package/lib/command/tmpVtcMileageRanking.js +1 -1
- package/lib/database/guildBind.js +16 -9
- package/lib/database/model.js +1 -1
- package/lib/index.js +16 -5
- package/lib/resource/version-update.html +706 -0
- package/lib/util/tmpIdPicker.js +4 -4
- package/package.json +1 -1
|
@@ -7,23 +7,30 @@ const evmOpenApi = require('../api/evmOpenApi');
|
|
|
7
7
|
*/
|
|
8
8
|
module.exports = {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* 刷新玩家名(**总是查接口**,用于玩家改名后的及时同步):
|
|
11
|
+
* - 并发查询传入的所有行(含缺名的旧数据);
|
|
12
|
+
* - 名字确实变了才写库,避免无谓的写操作;
|
|
13
|
+
* - 单个查询失败保留旧名(不把已有名字清空),下次再刷新。
|
|
14
|
+
* 注意:只在**要显示名字**的地方调用(我的绑定 / 序号列表 / 解绑·设为默认文案),
|
|
15
|
+
* 不显示名字的路径(如 pickAll、排行榜)不要调用,省接口。
|
|
12
16
|
* @returns 原数组(行对象已被就地更新)
|
|
13
17
|
*/
|
|
14
|
-
async
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
18
|
+
async refreshNames(ctx, rows) {
|
|
19
|
+
const list = (rows || []).filter(r => r && r.tmp_id != null);
|
|
20
|
+
if (list.length === 0) {
|
|
17
21
|
return rows;
|
|
18
22
|
}
|
|
19
|
-
await Promise.all(
|
|
23
|
+
await Promise.all(list.map(async (row) => {
|
|
20
24
|
try {
|
|
21
25
|
const info = await evmOpenApi.playerInfo(ctx.http, row.tmp_id);
|
|
22
26
|
if (!info.error && info.data && info.data.name) {
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
const name = info.data.name;
|
|
28
|
+
if (row.tmp_name !== name) {
|
|
29
|
+
row.tmp_name = name;
|
|
30
|
+
await ctx.database.set('tmp_guild_bind', row.id, { tmp_name: name });
|
|
31
|
+
}
|
|
25
32
|
}
|
|
26
|
-
} catch { } //
|
|
33
|
+
} catch { } // 查询失败保留旧名,下次再刷新
|
|
27
34
|
}));
|
|
28
35
|
return rows;
|
|
29
36
|
},
|
package/lib/database/model.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -129,7 +129,15 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
129
129
|
|
|
130
130
|
tmpVersionCheck: koishi_1.Schema.object({
|
|
131
131
|
checkInterval: koishi_1.Schema.number().description("版本检查间隔(分钟)").default(30),
|
|
132
|
-
groups: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("接收版本更新通知的群组ID列表").default([])
|
|
132
|
+
groups: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("接收版本更新通知的群组ID列表").default([]),
|
|
133
|
+
notifyType: koishi_1.Schema.union([
|
|
134
|
+
koishi_1.Schema.const(1).description('文字'),
|
|
135
|
+
koishi_1.Schema.const(2).description('图片')
|
|
136
|
+
]).default(1).description('版本更新通知形式(图片较精美,需启用 puppeteer;渲染失败会自动回退文字)'),
|
|
137
|
+
extraText: koishi_1.Schema.string()
|
|
138
|
+
.role('textarea')
|
|
139
|
+
.description('更新通知末尾附加的文本(留空则不追加)。支持用 \\n 表示换行')
|
|
140
|
+
.default('')
|
|
133
141
|
}).description("TMP版本更新查询配置"),
|
|
134
142
|
steamApi: koishi_1.Schema.object({
|
|
135
143
|
key: koishi_1.Schema.string().description("Steam API Key,用于查询游戏时长")
|
|
@@ -270,8 +278,8 @@ function registerBaseCommands(ctx, cfg) {
|
|
|
270
278
|
if (bindings.length === 0) {
|
|
271
279
|
return '还没有绑定编号,使用「绑定 tmpId」添加';
|
|
272
280
|
}
|
|
273
|
-
//
|
|
274
|
-
await guildBind.
|
|
281
|
+
// 展示前刷新名字(玩家改名后可及时同步)
|
|
282
|
+
await guildBind.refreshNames(ctx, bindings);
|
|
275
283
|
const lines = bindings.map((b, i) => {
|
|
276
284
|
const mark = guildBind.isDefault(b) ? '★ ' : ' ';
|
|
277
285
|
return `${mark}${i + 1}. ${b.tmp_name || '未知'} (${b.tmp_id})`;
|
|
@@ -289,7 +297,7 @@ function registerBaseCommands(ctx, cfg) {
|
|
|
289
297
|
if (!index || !index.trim()) {
|
|
290
298
|
return '请输入要设为默认的序号(序号见「我的绑定」)';
|
|
291
299
|
}
|
|
292
|
-
await guildBind.
|
|
300
|
+
await guildBind.refreshNames(ctx, await guildBind.list(ctx.database, session.platform, session.userId));
|
|
293
301
|
const { row, changed, total } = await guildBind.setDefaultByIndex(
|
|
294
302
|
ctx, ctx.database, session.platform, session.userId, index.trim()
|
|
295
303
|
);
|
|
@@ -312,7 +320,6 @@ function registerBaseCommands(ctx, cfg) {
|
|
|
312
320
|
if (bindings.length === 0) {
|
|
313
321
|
return '还没有绑定编号';
|
|
314
322
|
}
|
|
315
|
-
await guildBind.ensureNames(ctx, bindings);
|
|
316
323
|
if (!index) {
|
|
317
324
|
return '请输入要解绑的序号或 all(序号见「我的绑定」)';
|
|
318
325
|
}
|
|
@@ -324,6 +331,8 @@ function registerBaseCommands(ctx, cfg) {
|
|
|
324
331
|
if (isNaN(idx) || idx < 1 || idx > bindings.length) {
|
|
325
332
|
return `序号无效,可用范围 1-${bindings.length}(序号见「我的绑定」)`;
|
|
326
333
|
}
|
|
334
|
+
// 到这一步才需要显示名字(成功文案 / 顶替提示)→ 此时刷新
|
|
335
|
+
await guildBind.refreshNames(ctx, bindings);
|
|
327
336
|
const row = bindings[idx - 1];
|
|
328
337
|
const { promoted } = await guildBind.remove(ctx.database, session.platform, session.userId, row.id);
|
|
329
338
|
let msg = `已解绑 ${idx}. ${row.tmp_name || '未知'} (${row.tmp_id})`;
|
|
@@ -556,6 +565,8 @@ function apply(ctx, cfg) {
|
|
|
556
565
|
const versionCheckConfig = {
|
|
557
566
|
checkInterval: cfg.tmpVersionCheck.checkInterval,
|
|
558
567
|
groups: cfg.tmpVersionCheck.groups,
|
|
568
|
+
notifyType: cfg.tmpVersionCheck.notifyType,
|
|
569
|
+
extraText: cfg.tmpVersionCheck.extraText,
|
|
559
570
|
debugMode: cfg.debugMode,
|
|
560
571
|
debug: cfg.tmpActivityService?.debug
|
|
561
572
|
};
|