koishi-plugin-bind-bot 2.1.7 → 2.2.0
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/export-utils.js +4 -3
- package/lib/handlers/binding.handler.js +9 -19
- package/lib/handlers/buid.handler.js +19 -26
- package/lib/handlers/group-request-review.handler.js +11 -10
- package/lib/handlers/lottery.handler.js +4 -4
- package/lib/handlers/mcid.handler.js +31 -37
- package/lib/handlers/tag.handler.js +10 -7
- package/lib/handlers/whitelist.handler.js +5 -13
- package/lib/index.js +76 -64
- package/lib/services/database.service.d.ts +5 -1
- package/lib/services/database.service.js +110 -28
- package/lib/services/nickname.service.js +2 -2
- package/lib/types/database.d.ts +4 -0
- package/lib/types/update-data.d.ts +4 -0
- package/lib/utils/bind-status.d.ts +111 -0
- package/lib/utils/bind-status.js +156 -0
- package/lib/utils/helpers.js +0 -4
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.js +27 -0
- package/lib/utils/message-utils.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { MCIDBIND } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 绑定状态辅助工具类
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* 该类提供统一的绑定状态判断方法,用于替代散落在各处的 `_temp_` 判断逻辑。
|
|
7
|
+
* 支持新旧机制的向后兼容,优先使用新的 hasMcBind/hasBuidBind 字段。
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // 检查是否有有效的 MC 绑定
|
|
12
|
+
* if (BindStatus.hasValidMcBind(bind)) {
|
|
13
|
+
* console.log('用户已绑定 MC 账号')
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* // 获取显示用的 MC 用户名
|
|
17
|
+
* const mcName = BindStatus.getDisplayMcUsername(bind)
|
|
18
|
+
* console.log(`MC 用户名: ${mcName}`)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class BindStatus {
|
|
22
|
+
/**
|
|
23
|
+
* 检查是否有有效的 MC 绑定
|
|
24
|
+
*
|
|
25
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
26
|
+
* @returns true 表示已绑定有效的 MC 账号,false 表示未绑定或为临时状态
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* 判断逻辑:
|
|
30
|
+
* 1. 优先使用新字段 `hasMcBind`(如果存在)
|
|
31
|
+
* 2. 降级到旧逻辑:检查 `mcUsername` 非空且不以 `_temp_` 开头
|
|
32
|
+
*/
|
|
33
|
+
static hasValidMcBind(bind: MCIDBIND | null | undefined): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 检查是否有有效的 B站 绑定
|
|
36
|
+
*
|
|
37
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
38
|
+
* @returns true 表示已绑定有效的 B站 账号,false 表示未绑定
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* 判断逻辑:
|
|
42
|
+
* 1. 优先使用新字段 `hasBuidBind`(如果存在)
|
|
43
|
+
* 2. 降级到旧逻辑:检查 `buidUid` 非空
|
|
44
|
+
*/
|
|
45
|
+
static hasValidBuidBind(bind: MCIDBIND | null | undefined): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 获取显示用的 MC 用户名
|
|
48
|
+
*
|
|
49
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
50
|
+
* @param fallback - 当无有效绑定时的默认值(默认为 '未绑定')
|
|
51
|
+
* @returns MC 用户名或 fallback 值
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const mcName = BindStatus.getDisplayMcUsername(bind, '未设置')
|
|
56
|
+
* // 结果:'Notch' 或 '未设置'
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
static getDisplayMcUsername(bind: MCIDBIND | null | undefined, fallback?: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* 获取显示用的 B站 用户名
|
|
62
|
+
*
|
|
63
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
64
|
+
* @param fallback - 当无有效绑定时的默认值(默认为 '未绑定')
|
|
65
|
+
* @returns B站 用户名或 fallback 值
|
|
66
|
+
*/
|
|
67
|
+
static getDisplayBuidUsername(bind: MCIDBIND | null | undefined, fallback?: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* 检查是否完成全部绑定(MC + B站)
|
|
70
|
+
*
|
|
71
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
72
|
+
* @returns true 表示已完成 MC 和 B站 两项绑定
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* if (BindStatus.hasCompletedAllBinds(bind)) {
|
|
77
|
+
* console.log('用户已完成所有绑定!')
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
static hasCompletedAllBinds(bind: MCIDBIND | null | undefined): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* 获取绑定状态摘要信息
|
|
84
|
+
*
|
|
85
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
86
|
+
* @returns 包含绑定状态详细信息的对象
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const status = BindStatus.getBindingSummary(bind)
|
|
91
|
+
* console.log(`MC: ${status.mcStatus}, B站: ${status.buidStatus}`)
|
|
92
|
+
* // 输出: MC: 已绑定(Notch), B站: 已绑定(UID123456)
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
static getBindingSummary(bind: MCIDBIND | null | undefined): {
|
|
96
|
+
hasMcBind: boolean;
|
|
97
|
+
hasBuidBind: boolean;
|
|
98
|
+
hasCompletedAll: boolean;
|
|
99
|
+
mcStatus: string;
|
|
100
|
+
buidStatus: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 检查是否为临时绑定状态(仅用于过渡期诊断)
|
|
104
|
+
*
|
|
105
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
106
|
+
* @returns true 表示使用了临时用户名机制
|
|
107
|
+
*
|
|
108
|
+
* @deprecated 该方法仅用于重构过渡期,最终会被移除
|
|
109
|
+
*/
|
|
110
|
+
static isTempBinding(bind: MCIDBIND | null | undefined): boolean;
|
|
111
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BindStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 绑定状态辅助工具类
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* 该类提供统一的绑定状态判断方法,用于替代散落在各处的 `_temp_` 判断逻辑。
|
|
9
|
+
* 支持新旧机制的向后兼容,优先使用新的 hasMcBind/hasBuidBind 字段。
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // 检查是否有有效的 MC 绑定
|
|
14
|
+
* if (BindStatus.hasValidMcBind(bind)) {
|
|
15
|
+
* console.log('用户已绑定 MC 账号')
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // 获取显示用的 MC 用户名
|
|
19
|
+
* const mcName = BindStatus.getDisplayMcUsername(bind)
|
|
20
|
+
* console.log(`MC 用户名: ${mcName}`)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class BindStatus {
|
|
24
|
+
/**
|
|
25
|
+
* 检查是否有有效的 MC 绑定
|
|
26
|
+
*
|
|
27
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
28
|
+
* @returns true 表示已绑定有效的 MC 账号,false 表示未绑定或为临时状态
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* 判断逻辑:
|
|
32
|
+
* 1. 优先使用新字段 `hasMcBind`(如果存在)
|
|
33
|
+
* 2. 降级到旧逻辑:检查 `mcUsername` 非空且不以 `_temp_` 开头
|
|
34
|
+
*/
|
|
35
|
+
static hasValidMcBind(bind) {
|
|
36
|
+
if (!bind)
|
|
37
|
+
return false;
|
|
38
|
+
// 优先使用新字段
|
|
39
|
+
if (bind.hasMcBind !== undefined) {
|
|
40
|
+
return bind.hasMcBind;
|
|
41
|
+
}
|
|
42
|
+
// 降级到旧逻辑(向后兼容)
|
|
43
|
+
return !!(bind.mcUsername && !bind.mcUsername.startsWith('_temp_'));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 检查是否有有效的 B站 绑定
|
|
47
|
+
*
|
|
48
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
49
|
+
* @returns true 表示已绑定有效的 B站 账号,false 表示未绑定
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* 判断逻辑:
|
|
53
|
+
* 1. 优先使用新字段 `hasBuidBind`(如果存在)
|
|
54
|
+
* 2. 降级到旧逻辑:检查 `buidUid` 非空
|
|
55
|
+
*/
|
|
56
|
+
static hasValidBuidBind(bind) {
|
|
57
|
+
if (!bind)
|
|
58
|
+
return false;
|
|
59
|
+
// 优先使用新字段
|
|
60
|
+
if (bind.hasBuidBind !== undefined) {
|
|
61
|
+
return bind.hasBuidBind;
|
|
62
|
+
}
|
|
63
|
+
// 降级到旧逻辑
|
|
64
|
+
return !!(bind.buidUid && bind.buidUid.length > 0);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 获取显示用的 MC 用户名
|
|
68
|
+
*
|
|
69
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
70
|
+
* @param fallback - 当无有效绑定时的默认值(默认为 '未绑定')
|
|
71
|
+
* @returns MC 用户名或 fallback 值
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const mcName = BindStatus.getDisplayMcUsername(bind, '未设置')
|
|
76
|
+
* // 结果:'Notch' 或 '未设置'
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
static getDisplayMcUsername(bind, fallback = '未绑定') {
|
|
80
|
+
if (!bind || !this.hasValidMcBind(bind)) {
|
|
81
|
+
return fallback;
|
|
82
|
+
}
|
|
83
|
+
return bind.mcUsername || fallback;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 获取显示用的 B站 用户名
|
|
87
|
+
*
|
|
88
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
89
|
+
* @param fallback - 当无有效绑定时的默认值(默认为 '未绑定')
|
|
90
|
+
* @returns B站 用户名或 fallback 值
|
|
91
|
+
*/
|
|
92
|
+
static getDisplayBuidUsername(bind, fallback = '未绑定') {
|
|
93
|
+
if (!bind || !this.hasValidBuidBind(bind)) {
|
|
94
|
+
return fallback;
|
|
95
|
+
}
|
|
96
|
+
return bind.buidUsername || fallback;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 检查是否完成全部绑定(MC + B站)
|
|
100
|
+
*
|
|
101
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
102
|
+
* @returns true 表示已完成 MC 和 B站 两项绑定
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* if (BindStatus.hasCompletedAllBinds(bind)) {
|
|
107
|
+
* console.log('用户已完成所有绑定!')
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
static hasCompletedAllBinds(bind) {
|
|
112
|
+
return this.hasValidMcBind(bind) && this.hasValidBuidBind(bind);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 获取绑定状态摘要信息
|
|
116
|
+
*
|
|
117
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
118
|
+
* @returns 包含绑定状态详细信息的对象
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const status = BindStatus.getBindingSummary(bind)
|
|
123
|
+
* console.log(`MC: ${status.mcStatus}, B站: ${status.buidStatus}`)
|
|
124
|
+
* // 输出: MC: 已绑定(Notch), B站: 已绑定(UID123456)
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
static getBindingSummary(bind) {
|
|
128
|
+
const hasMcBind = this.hasValidMcBind(bind);
|
|
129
|
+
const hasBuidBind = this.hasValidBuidBind(bind);
|
|
130
|
+
return {
|
|
131
|
+
hasMcBind,
|
|
132
|
+
hasBuidBind,
|
|
133
|
+
hasCompletedAll: hasMcBind && hasBuidBind,
|
|
134
|
+
mcStatus: hasMcBind
|
|
135
|
+
? `已绑定(${bind?.mcUsername})`
|
|
136
|
+
: '未绑定',
|
|
137
|
+
buidStatus: hasBuidBind
|
|
138
|
+
? `已绑定(UID${bind?.buidUid})`
|
|
139
|
+
: '未绑定'
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 检查是否为临时绑定状态(仅用于过渡期诊断)
|
|
144
|
+
*
|
|
145
|
+
* @param bind - 绑定记录(可为 null 或 undefined)
|
|
146
|
+
* @returns true 表示使用了临时用户名机制
|
|
147
|
+
*
|
|
148
|
+
* @deprecated 该方法仅用于重构过渡期,最终会被移除
|
|
149
|
+
*/
|
|
150
|
+
static isTempBinding(bind) {
|
|
151
|
+
if (!bind || !bind.mcUsername)
|
|
152
|
+
return false;
|
|
153
|
+
return bind.mcUsername.startsWith('_temp_');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.BindStatus = BindStatus;
|
package/lib/utils/helpers.js
CHANGED
|
@@ -376,10 +376,6 @@ function normalizeUsername(username, logger) {
|
|
|
376
376
|
}
|
|
377
377
|
// 移除首尾空格
|
|
378
378
|
const trimmed = username.trim();
|
|
379
|
-
// 检查是否为临时用户名,临时用户名不做转换
|
|
380
|
-
if (trimmed.startsWith('_temp_')) {
|
|
381
|
-
return trimmed;
|
|
382
|
-
}
|
|
383
379
|
// 转小写
|
|
384
380
|
const normalized = trimmed.toLowerCase();
|
|
385
381
|
if (normalized !== trimmed) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utils 模块统一导出
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.BindStatus = void 0;
|
|
21
|
+
// 绑定状态工具类
|
|
22
|
+
var bind_status_1 = require("./bind-status");
|
|
23
|
+
Object.defineProperty(exports, "BindStatus", { enumerable: true, get: function () { return bind_status_1.BindStatus; } });
|
|
24
|
+
// 其他工具函数(按需导出)
|
|
25
|
+
__exportStar(require("./helpers"), exports);
|
|
26
|
+
__exportStar(require("./error-utils"), exports);
|
|
27
|
+
__exportStar(require("./message-utils"), exports);
|
|
@@ -162,8 +162,8 @@ class MessageUtils {
|
|
|
162
162
|
// 如果指定了目标用户ID,使用目标用户ID,否则使用session的用户ID
|
|
163
163
|
const actualUserId = targetUserId || session.userId;
|
|
164
164
|
const normalizedUserId = (0, helpers_1.normalizeQQId)(actualUserId);
|
|
165
|
-
// 根据MC
|
|
166
|
-
const mcInfo = mcUsername
|
|
165
|
+
// 根据MC绑定状态设置不同的格式
|
|
166
|
+
const mcInfo = mcUsername || '未绑定';
|
|
167
167
|
let currentBuidUsername = buidUsername;
|
|
168
168
|
const newNickname = `${currentBuidUsername}(ID:${mcInfo})`;
|
|
169
169
|
// 使用指定的群ID,如果没有指定则使用配置的默认群ID
|