koishi-plugin-bind-bot 2.0.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.d.ts +49 -0
- package/lib/export-utils.js +305 -0
- package/lib/force-bind-utils.d.ts +40 -0
- package/lib/force-bind-utils.js +242 -0
- package/lib/handlers/base.handler.d.ts +61 -0
- package/lib/handlers/base.handler.js +22 -0
- package/lib/handlers/binding.handler.d.ts +45 -0
- package/lib/handlers/binding.handler.js +285 -0
- package/lib/handlers/buid.handler.d.ts +71 -0
- package/lib/handlers/buid.handler.js +694 -0
- package/lib/handlers/index.d.ts +6 -0
- package/lib/handlers/index.js +22 -0
- package/lib/handlers/mcid.handler.d.ts +101 -0
- package/lib/handlers/mcid.handler.js +1045 -0
- package/lib/handlers/tag.handler.d.ts +14 -0
- package/lib/handlers/tag.handler.js +382 -0
- package/lib/handlers/whitelist.handler.d.ts +84 -0
- package/lib/handlers/whitelist.handler.js +1011 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +2693 -0
- package/lib/managers/rcon-manager.d.ts +24 -0
- package/lib/managers/rcon-manager.js +308 -0
- package/lib/repositories/mcidbind.repository.d.ts +105 -0
- package/lib/repositories/mcidbind.repository.js +288 -0
- package/lib/repositories/schedule-mute.repository.d.ts +68 -0
- package/lib/repositories/schedule-mute.repository.js +175 -0
- package/lib/types/api.d.ts +135 -0
- package/lib/types/api.js +6 -0
- package/lib/types/common.d.ts +40 -0
- package/lib/types/common.js +6 -0
- package/lib/types/config.d.ts +55 -0
- package/lib/types/config.js +6 -0
- package/lib/types/database.d.ts +47 -0
- package/lib/types/database.js +6 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.js +28 -0
- package/lib/utils/helpers.d.ts +76 -0
- package/lib/utils/helpers.js +275 -0
- package/lib/utils/logger.d.ts +75 -0
- package/lib/utils/logger.js +134 -0
- package/lib/utils/message-utils.d.ts +46 -0
- package/lib/utils/message-utils.js +234 -0
- package/lib/utils/rate-limiter.d.ts +26 -0
- package/lib/utils/rate-limiter.js +47 -0
- package/lib/utils/session-manager.d.ts +70 -0
- package/lib/utils/session-manager.js +120 -0
- package/package.json +39 -0
- package/readme.md +281 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCIDBINDRepository = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* MCIDBIND 数据仓储类
|
|
6
|
+
* 封装所有 MCIDBIND 表的数据库操作
|
|
7
|
+
*/
|
|
8
|
+
class MCIDBINDRepository {
|
|
9
|
+
ctx;
|
|
10
|
+
logger;
|
|
11
|
+
constructor(ctx, logger) {
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 根据 QQ 号查询绑定信息
|
|
17
|
+
* @param qqId QQ号(已规范化)
|
|
18
|
+
* @returns 绑定信息或 null
|
|
19
|
+
*/
|
|
20
|
+
async findByQQId(qqId) {
|
|
21
|
+
try {
|
|
22
|
+
this.logger.debug('数据库', `查询QQ(${qqId})的绑定信息`);
|
|
23
|
+
const binds = await this.ctx.database.get('mcidbind', { qqId });
|
|
24
|
+
return binds.length > 0 ? binds[0] : null;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
this.logger.error('数据库', `查询QQ(${qqId})绑定信息失败: ${error.message}`);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 根据 MC 用户名查询绑定信息
|
|
33
|
+
* @param mcUsername MC用户名
|
|
34
|
+
* @returns 绑定信息或 null
|
|
35
|
+
*/
|
|
36
|
+
async findByMCUsername(mcUsername) {
|
|
37
|
+
try {
|
|
38
|
+
this.logger.debug('数据库', `查询MC用户名(${mcUsername})的绑定信息`);
|
|
39
|
+
const binds = await this.ctx.database.get('mcidbind', { mcUsername });
|
|
40
|
+
return binds.length > 0 ? binds[0] : null;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
this.logger.error('数据库', `查询MC用户名(${mcUsername})绑定信息失败: ${error.message}`);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 根据 B站 UID 查询绑定信息
|
|
49
|
+
* @param buidUid B站UID
|
|
50
|
+
* @returns 绑定信息或 null
|
|
51
|
+
*/
|
|
52
|
+
async findByBuidUid(buidUid) {
|
|
53
|
+
try {
|
|
54
|
+
this.logger.debug('数据库', `查询B站UID(${buidUid})的绑定信息`);
|
|
55
|
+
const binds = await this.ctx.database.get('mcidbind', { buidUid });
|
|
56
|
+
return binds.length > 0 ? binds[0] : null;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
this.logger.error('数据库', `查询B站UID(${buidUid})绑定信息失败: ${error.message}`);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 获取所有绑定记录
|
|
65
|
+
* @param options 查询选项
|
|
66
|
+
* @returns 绑定记录列表
|
|
67
|
+
*/
|
|
68
|
+
async findAll(options) {
|
|
69
|
+
try {
|
|
70
|
+
this.logger.debug('数据库', `获取所有绑定记录${options?.limit ? ` (limit: ${options.limit})` : ''}`);
|
|
71
|
+
const records = await this.ctx.database.get('mcidbind', {}, options);
|
|
72
|
+
return records;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
this.logger.error('数据库', `获取所有绑定记录失败: ${error.message}`);
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 根据标签查询绑定记录
|
|
81
|
+
* @param tag 标签名称
|
|
82
|
+
* @returns 包含该标签的绑定记录列表
|
|
83
|
+
*/
|
|
84
|
+
async findByTag(tag) {
|
|
85
|
+
try {
|
|
86
|
+
this.logger.debug('数据库', `查询包含标签"${tag}"的绑定记录`);
|
|
87
|
+
const allRecords = await this.ctx.database.get('mcidbind', {});
|
|
88
|
+
return allRecords.filter(record => record.tags && record.tags.includes(tag));
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.logger.error('数据库', `查询标签"${tag}"的绑定记录失败: ${error.message}`);
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 创建新的绑定记录
|
|
97
|
+
* @param data 绑定数据
|
|
98
|
+
* @returns 创建的记录
|
|
99
|
+
*/
|
|
100
|
+
async create(data) {
|
|
101
|
+
try {
|
|
102
|
+
this.logger.debug('数据库', `创建QQ(${data.qqId})的绑定记录`);
|
|
103
|
+
const created = await this.ctx.database.create('mcidbind', data);
|
|
104
|
+
this.logger.info('数据库', `成功创建QQ(${data.qqId})的绑定记录`, true);
|
|
105
|
+
return created;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
this.logger.error('数据库', `创建QQ(${data.qqId})绑定记录失败: ${error.message}`);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 更新绑定记录(部分字段)
|
|
114
|
+
* @param qqId QQ号
|
|
115
|
+
* @param data 要更新的字段
|
|
116
|
+
*/
|
|
117
|
+
async update(qqId, data) {
|
|
118
|
+
try {
|
|
119
|
+
this.logger.debug('数据库', `更新QQ(${qqId})的绑定记录`);
|
|
120
|
+
await this.ctx.database.set('mcidbind', { qqId }, data);
|
|
121
|
+
this.logger.info('数据库', `成功更新QQ(${qqId})的绑定记录`, true);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.logger.error('数据库', `更新QQ(${qqId})绑定记录失败: ${error.message}`);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 删除绑定记录
|
|
130
|
+
* @param qqId QQ号
|
|
131
|
+
* @returns 删除的记录数
|
|
132
|
+
*/
|
|
133
|
+
async delete(qqId) {
|
|
134
|
+
try {
|
|
135
|
+
this.logger.debug('数据库', `删除QQ(${qqId})的绑定记录`);
|
|
136
|
+
const result = await this.ctx.database.remove('mcidbind', { qqId });
|
|
137
|
+
this.logger.info('数据库', `成功删除QQ(${qqId})的绑定记录(删除${result.removed}条)`, true);
|
|
138
|
+
return result.removed;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
this.logger.error('数据库', `删除QQ(${qqId})绑定记录失败: ${error.message}`);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 删除所有绑定记录
|
|
147
|
+
* @returns 删除的记录数
|
|
148
|
+
*/
|
|
149
|
+
async deleteAll() {
|
|
150
|
+
try {
|
|
151
|
+
this.logger.debug('数据库', `删除所有绑定记录`);
|
|
152
|
+
const result = await this.ctx.database.remove('mcidbind', {});
|
|
153
|
+
this.logger.info('数据库', `成功删除所有绑定记录(删除${result.removed}条)`, true);
|
|
154
|
+
return result.removed;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
this.logger.error('数据库', `删除所有绑定记录失败: ${error.message}`);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 批量创建绑定记录
|
|
163
|
+
* @param records 绑定记录列表
|
|
164
|
+
*/
|
|
165
|
+
async batchCreate(records) {
|
|
166
|
+
try {
|
|
167
|
+
this.logger.debug('数据库', `批量创建${records.length}条绑定记录`);
|
|
168
|
+
for (const record of records) {
|
|
169
|
+
await this.ctx.database.create('mcidbind', record);
|
|
170
|
+
}
|
|
171
|
+
this.logger.info('数据库', `成功批量创建${records.length}条绑定记录`, true);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
this.logger.error('数据库', `批量创建绑定记录失败: ${error.message}`);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 为用户添加标签
|
|
180
|
+
* @param qqId QQ号
|
|
181
|
+
* @param tag 标签名称
|
|
182
|
+
*/
|
|
183
|
+
async addTag(qqId, tag) {
|
|
184
|
+
try {
|
|
185
|
+
const bind = await this.findByQQId(qqId);
|
|
186
|
+
if (!bind) {
|
|
187
|
+
throw new Error(`QQ(${qqId})的绑定记录不存在`);
|
|
188
|
+
}
|
|
189
|
+
const tags = bind.tags || [];
|
|
190
|
+
if (!tags.includes(tag)) {
|
|
191
|
+
tags.push(tag);
|
|
192
|
+
await this.update(qqId, { tags });
|
|
193
|
+
this.logger.info('数据库', `成功为QQ(${qqId})添加标签"${tag}"`, true);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
this.logger.error('数据库', `为QQ(${qqId})添加标签"${tag}"失败: ${error.message}`);
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 为用户移除标签
|
|
203
|
+
* @param qqId QQ号
|
|
204
|
+
* @param tag 标签名称
|
|
205
|
+
*/
|
|
206
|
+
async removeTag(qqId, tag) {
|
|
207
|
+
try {
|
|
208
|
+
const bind = await this.findByQQId(qqId);
|
|
209
|
+
if (!bind) {
|
|
210
|
+
throw new Error(`QQ(${qqId})的绑定记录不存在`);
|
|
211
|
+
}
|
|
212
|
+
const tags = bind.tags || [];
|
|
213
|
+
const index = tags.indexOf(tag);
|
|
214
|
+
if (index > -1) {
|
|
215
|
+
tags.splice(index, 1);
|
|
216
|
+
await this.update(qqId, { tags });
|
|
217
|
+
this.logger.info('数据库', `成功为QQ(${qqId})移除标签"${tag}"`, true);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
this.logger.error('数据库', `为QQ(${qqId})移除标签"${tag}"失败: ${error.message}`);
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 为用户添加白名单服务器
|
|
227
|
+
* @param qqId QQ号
|
|
228
|
+
* @param serverId 服务器ID
|
|
229
|
+
*/
|
|
230
|
+
async addWhitelist(qqId, serverId) {
|
|
231
|
+
try {
|
|
232
|
+
const bind = await this.findByQQId(qqId);
|
|
233
|
+
if (!bind) {
|
|
234
|
+
throw new Error(`QQ(${qqId})的绑定记录不存在`);
|
|
235
|
+
}
|
|
236
|
+
const whitelist = bind.whitelist || [];
|
|
237
|
+
if (!whitelist.includes(serverId)) {
|
|
238
|
+
whitelist.push(serverId);
|
|
239
|
+
await this.update(qqId, { whitelist });
|
|
240
|
+
this.logger.info('数据库', `成功为QQ(${qqId})添加白名单服务器"${serverId}"`, true);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
this.logger.error('数据库', `为QQ(${qqId})添加白名单服务器"${serverId}"失败: ${error.message}`);
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 为用户移除白名单服务器
|
|
250
|
+
* @param qqId QQ号
|
|
251
|
+
* @param serverId 服务器ID
|
|
252
|
+
*/
|
|
253
|
+
async removeWhitelist(qqId, serverId) {
|
|
254
|
+
try {
|
|
255
|
+
const bind = await this.findByQQId(qqId);
|
|
256
|
+
if (!bind) {
|
|
257
|
+
throw new Error(`QQ(${qqId})的绑定记录不存在`);
|
|
258
|
+
}
|
|
259
|
+
const whitelist = bind.whitelist || [];
|
|
260
|
+
const index = whitelist.indexOf(serverId);
|
|
261
|
+
if (index > -1) {
|
|
262
|
+
whitelist.splice(index, 1);
|
|
263
|
+
await this.update(qqId, { whitelist });
|
|
264
|
+
this.logger.info('数据库', `成功为QQ(${qqId})移除白名单服务器"${serverId}"`, true);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
this.logger.error('数据库', `为QQ(${qqId})移除白名单服务器"${serverId}"失败: ${error.message}`);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 获取所有管理员
|
|
274
|
+
* @returns 管理员列表
|
|
275
|
+
*/
|
|
276
|
+
async findAllAdmins() {
|
|
277
|
+
try {
|
|
278
|
+
this.logger.debug('数据库', `获取所有管理员`);
|
|
279
|
+
const allRecords = await this.ctx.database.get('mcidbind', {});
|
|
280
|
+
return allRecords.filter(record => record.isAdmin);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
this.logger.error('数据库', `获取所有管理员失败: ${error.message}`);
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.MCIDBINDRepository = MCIDBINDRepository;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { LoggerService } from '../utils/logger';
|
|
3
|
+
import type { SCHEDULE_MUTE_TASKS } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* 定时禁言任务数据仓储类
|
|
6
|
+
* 封装所有 SCHEDULE_MUTE_TASKS 表的数据库操作
|
|
7
|
+
*/
|
|
8
|
+
export declare class ScheduleMuteRepository {
|
|
9
|
+
private ctx;
|
|
10
|
+
private logger;
|
|
11
|
+
constructor(ctx: Context, logger: LoggerService);
|
|
12
|
+
/**
|
|
13
|
+
* 根据 ID 查询定时禁言任务
|
|
14
|
+
* @param id 任务ID
|
|
15
|
+
* @returns 任务信息或 null
|
|
16
|
+
*/
|
|
17
|
+
findById(id: number): Promise<SCHEDULE_MUTE_TASKS | null>;
|
|
18
|
+
/**
|
|
19
|
+
* 根据群组 ID 查询定时禁言任务
|
|
20
|
+
* @param groupId 群组ID
|
|
21
|
+
* @returns 任务列表
|
|
22
|
+
*/
|
|
23
|
+
findByGroupId(groupId: string): Promise<SCHEDULE_MUTE_TASKS[]>;
|
|
24
|
+
/**
|
|
25
|
+
* 获取所有定时禁言任务
|
|
26
|
+
* @returns 任务列表
|
|
27
|
+
*/
|
|
28
|
+
findAll(): Promise<SCHEDULE_MUTE_TASKS[]>;
|
|
29
|
+
/**
|
|
30
|
+
* 获取所有已启用的定时禁言任务
|
|
31
|
+
* @returns 任务列表
|
|
32
|
+
*/
|
|
33
|
+
findAllEnabled(): Promise<SCHEDULE_MUTE_TASKS[]>;
|
|
34
|
+
/**
|
|
35
|
+
* 创建定时禁言任务
|
|
36
|
+
* @param data 任务数据
|
|
37
|
+
* @returns 创建的任务
|
|
38
|
+
*/
|
|
39
|
+
create(data: Omit<SCHEDULE_MUTE_TASKS, 'id'>): Promise<SCHEDULE_MUTE_TASKS>;
|
|
40
|
+
/**
|
|
41
|
+
* 更新定时禁言任务
|
|
42
|
+
* @param id 任务ID
|
|
43
|
+
* @param data 要更新的字段
|
|
44
|
+
*/
|
|
45
|
+
update(id: number, data: Partial<Omit<SCHEDULE_MUTE_TASKS, 'id'>>): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 删除定时禁言任务
|
|
48
|
+
* @param id 任务ID
|
|
49
|
+
* @returns 删除的记录数
|
|
50
|
+
*/
|
|
51
|
+
delete(id: number): Promise<number>;
|
|
52
|
+
/**
|
|
53
|
+
* 启用定时禁言任务
|
|
54
|
+
* @param id 任务ID
|
|
55
|
+
*/
|
|
56
|
+
enable(id: number): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* 禁用定时禁言任务
|
|
59
|
+
* @param id 任务ID
|
|
60
|
+
*/
|
|
61
|
+
disable(id: number): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* 删除群组的所有定时禁言任务
|
|
64
|
+
* @param groupId 群组ID
|
|
65
|
+
* @returns 删除的记录数
|
|
66
|
+
*/
|
|
67
|
+
deleteByGroupId(groupId: string): Promise<number>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScheduleMuteRepository = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 定时禁言任务数据仓储类
|
|
6
|
+
* 封装所有 SCHEDULE_MUTE_TASKS 表的数据库操作
|
|
7
|
+
*/
|
|
8
|
+
class ScheduleMuteRepository {
|
|
9
|
+
ctx;
|
|
10
|
+
logger;
|
|
11
|
+
constructor(ctx, logger) {
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 根据 ID 查询定时禁言任务
|
|
17
|
+
* @param id 任务ID
|
|
18
|
+
* @returns 任务信息或 null
|
|
19
|
+
*/
|
|
20
|
+
async findById(id) {
|
|
21
|
+
try {
|
|
22
|
+
this.logger.debug('数据库', `查询定时禁言任务ID(${id})`);
|
|
23
|
+
const tasks = await this.ctx.database.get('schedule_mute_tasks', { id });
|
|
24
|
+
return tasks.length > 0 ? tasks[0] : null;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
this.logger.error('数据库', `查询定时禁言任务ID(${id})失败: ${error.message}`);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 根据群组 ID 查询定时禁言任务
|
|
33
|
+
* @param groupId 群组ID
|
|
34
|
+
* @returns 任务列表
|
|
35
|
+
*/
|
|
36
|
+
async findByGroupId(groupId) {
|
|
37
|
+
try {
|
|
38
|
+
this.logger.debug('数据库', `查询群${groupId}的定时禁言任务`);
|
|
39
|
+
const tasks = await this.ctx.database.get('schedule_mute_tasks', { groupId });
|
|
40
|
+
return tasks;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
this.logger.error('数据库', `查询群${groupId}的定时禁言任务失败: ${error.message}`);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 获取所有定时禁言任务
|
|
49
|
+
* @returns 任务列表
|
|
50
|
+
*/
|
|
51
|
+
async findAll() {
|
|
52
|
+
try {
|
|
53
|
+
this.logger.debug('数据库', `获取所有定时禁言任务`);
|
|
54
|
+
const tasks = await this.ctx.database.get('schedule_mute_tasks', {});
|
|
55
|
+
return tasks;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this.logger.error('数据库', `获取所有定时禁言任务失败: ${error.message}`);
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 获取所有已启用的定时禁言任务
|
|
64
|
+
* @returns 任务列表
|
|
65
|
+
*/
|
|
66
|
+
async findAllEnabled() {
|
|
67
|
+
try {
|
|
68
|
+
this.logger.debug('数据库', `获取所有已启用的定时禁言任务`);
|
|
69
|
+
const tasks = await this.ctx.database.get('schedule_mute_tasks', { enabled: true });
|
|
70
|
+
return tasks;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
this.logger.error('数据库', `获取所有已启用的定时禁言任务失败: ${error.message}`);
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 创建定时禁言任务
|
|
79
|
+
* @param data 任务数据
|
|
80
|
+
* @returns 创建的任务
|
|
81
|
+
*/
|
|
82
|
+
async create(data) {
|
|
83
|
+
try {
|
|
84
|
+
this.logger.debug('数据库', `创建群${data.groupId}的定时禁言任务`);
|
|
85
|
+
const created = await this.ctx.database.create('schedule_mute_tasks', data);
|
|
86
|
+
this.logger.info('数据库', `成功创建群${data.groupId}的定时禁言任务(ID:${created.id})`, true);
|
|
87
|
+
return created;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.logger.error('数据库', `创建群${data.groupId}的定时禁言任务失败: ${error.message}`);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 更新定时禁言任务
|
|
96
|
+
* @param id 任务ID
|
|
97
|
+
* @param data 要更新的字段
|
|
98
|
+
*/
|
|
99
|
+
async update(id, data) {
|
|
100
|
+
try {
|
|
101
|
+
this.logger.debug('数据库', `更新定时禁言任务ID(${id})`);
|
|
102
|
+
await this.ctx.database.set('schedule_mute_tasks', { id }, data);
|
|
103
|
+
this.logger.info('数据库', `成功更新定时禁言任务ID(${id})`, true);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
this.logger.error('数据库', `更新定时禁言任务ID(${id})失败: ${error.message}`);
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 删除定时禁言任务
|
|
112
|
+
* @param id 任务ID
|
|
113
|
+
* @returns 删除的记录数
|
|
114
|
+
*/
|
|
115
|
+
async delete(id) {
|
|
116
|
+
try {
|
|
117
|
+
this.logger.debug('数据库', `删除定时禁言任务ID(${id})`);
|
|
118
|
+
const result = await this.ctx.database.remove('schedule_mute_tasks', { id });
|
|
119
|
+
this.logger.info('数据库', `成功删除定时禁言任务ID(${id})(删除${result.removed}条)`, true);
|
|
120
|
+
return result.removed;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
this.logger.error('数据库', `删除定时禁言任务ID(${id})失败: ${error.message}`);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 启用定时禁言任务
|
|
129
|
+
* @param id 任务ID
|
|
130
|
+
*/
|
|
131
|
+
async enable(id) {
|
|
132
|
+
try {
|
|
133
|
+
this.logger.debug('数据库', `启用定时禁言任务ID(${id})`);
|
|
134
|
+
await this.ctx.database.set('schedule_mute_tasks', { id }, { enabled: true });
|
|
135
|
+
this.logger.info('数据库', `成功启用定时禁言任务ID(${id})`, true);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
this.logger.error('数据库', `启用定时禁言任务ID(${id})失败: ${error.message}`);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 禁用定时禁言任务
|
|
144
|
+
* @param id 任务ID
|
|
145
|
+
*/
|
|
146
|
+
async disable(id) {
|
|
147
|
+
try {
|
|
148
|
+
this.logger.debug('数据库', `禁用定时禁言任务ID(${id})`);
|
|
149
|
+
await this.ctx.database.set('schedule_mute_tasks', { id }, { enabled: false });
|
|
150
|
+
this.logger.info('数据库', `成功禁用定时禁言任务ID(${id})`, true);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
this.logger.error('数据库', `禁用定时禁言任务ID(${id})失败: ${error.message}`);
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 删除群组的所有定时禁言任务
|
|
159
|
+
* @param groupId 群组ID
|
|
160
|
+
* @returns 删除的记录数
|
|
161
|
+
*/
|
|
162
|
+
async deleteByGroupId(groupId) {
|
|
163
|
+
try {
|
|
164
|
+
this.logger.debug('数据库', `删除群${groupId}的所有定时禁言任务`);
|
|
165
|
+
const result = await this.ctx.database.remove('schedule_mute_tasks', { groupId });
|
|
166
|
+
this.logger.info('数据库', `成功删除群${groupId}的所有定时禁言任务(删除${result.removed}条)`, true);
|
|
167
|
+
return result.removed;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
this.logger.error('数据库', `删除群${groupId}的所有定时禁言任务失败: ${error.message}`);
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.ScheduleMuteRepository = ScheduleMuteRepository;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 外部API响应接口类型定义
|
|
3
|
+
* 包含 Mojang API、ZMINFO API 和 Bilibili API
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Mojang API 响应接口
|
|
7
|
+
* 用于获取MC用户UUID和用户名
|
|
8
|
+
*/
|
|
9
|
+
export interface MojangProfile {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* ZMINFO API - 用户信息接口
|
|
15
|
+
*/
|
|
16
|
+
export interface ZminfoUser {
|
|
17
|
+
uid: string;
|
|
18
|
+
username: string;
|
|
19
|
+
avatar_url: string;
|
|
20
|
+
guard_level: number;
|
|
21
|
+
guard_level_text: string;
|
|
22
|
+
max_guard_level: number;
|
|
23
|
+
max_guard_level_text: string;
|
|
24
|
+
medal: {
|
|
25
|
+
name: string;
|
|
26
|
+
level: number;
|
|
27
|
+
uid: string;
|
|
28
|
+
room: number;
|
|
29
|
+
} | null;
|
|
30
|
+
wealthMedalLevel: number;
|
|
31
|
+
last_active_time: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ZMINFO API 响应接口
|
|
35
|
+
*/
|
|
36
|
+
export interface ZminfoApiResponse {
|
|
37
|
+
success: boolean;
|
|
38
|
+
message: string;
|
|
39
|
+
data?: {
|
|
40
|
+
user?: ZminfoUser;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Bilibili Live API - 粉丝勋章信息接口
|
|
45
|
+
*/
|
|
46
|
+
export interface MedalInfo {
|
|
47
|
+
target_id: number;
|
|
48
|
+
level: number;
|
|
49
|
+
medal_name: string;
|
|
50
|
+
medal_color_start: number;
|
|
51
|
+
medal_color_end: number;
|
|
52
|
+
medal_color_border: number;
|
|
53
|
+
guard_level: number;
|
|
54
|
+
wearing_status: number;
|
|
55
|
+
medal_id: number;
|
|
56
|
+
intimacy: number;
|
|
57
|
+
next_intimacy: number;
|
|
58
|
+
today_feed: number;
|
|
59
|
+
day_limit: number;
|
|
60
|
+
guard_icon: string;
|
|
61
|
+
honor_icon: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Bilibili Live API - 用户勋章信息接口
|
|
65
|
+
*/
|
|
66
|
+
export interface UinfoMedal {
|
|
67
|
+
name: string;
|
|
68
|
+
level: number;
|
|
69
|
+
color_start: number;
|
|
70
|
+
color_end: number;
|
|
71
|
+
color_border: number;
|
|
72
|
+
color: number;
|
|
73
|
+
id: number;
|
|
74
|
+
typ: number;
|
|
75
|
+
is_light: number;
|
|
76
|
+
ruid: number;
|
|
77
|
+
guard_level: number;
|
|
78
|
+
score: number;
|
|
79
|
+
guard_icon: string;
|
|
80
|
+
honor_icon: string;
|
|
81
|
+
v2_medal_color_start: string;
|
|
82
|
+
v2_medal_color_end: string;
|
|
83
|
+
v2_medal_color_border: string;
|
|
84
|
+
v2_medal_color_text: string;
|
|
85
|
+
v2_medal_color_level: string;
|
|
86
|
+
user_receive_count: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Bilibili Live API - 勋章列表项接口
|
|
90
|
+
*/
|
|
91
|
+
export interface MedalListItem {
|
|
92
|
+
medal_info: MedalInfo;
|
|
93
|
+
target_name: string;
|
|
94
|
+
target_icon: string;
|
|
95
|
+
link: string;
|
|
96
|
+
live_status: number;
|
|
97
|
+
official: number;
|
|
98
|
+
uinfo_medal: UinfoMedal;
|
|
99
|
+
data?: {
|
|
100
|
+
icon?: string;
|
|
101
|
+
uid?: number;
|
|
102
|
+
name?: string;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Bilibili Live API - 响应接口
|
|
107
|
+
*/
|
|
108
|
+
export interface BilibiliMedalAPIResponse {
|
|
109
|
+
code: number;
|
|
110
|
+
message: string;
|
|
111
|
+
ttl: number;
|
|
112
|
+
data?: {
|
|
113
|
+
list: MedalListItem[];
|
|
114
|
+
count: number;
|
|
115
|
+
close_space_medal: number;
|
|
116
|
+
only_show_wearing: number;
|
|
117
|
+
name: string;
|
|
118
|
+
icon: string;
|
|
119
|
+
uid: number;
|
|
120
|
+
level: number;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 扩展的ZMINFO用户信息接口
|
|
125
|
+
* 包含目标粉丝牌数据(用于强制绑定)
|
|
126
|
+
*/
|
|
127
|
+
export interface EnhancedZminfoUser extends ZminfoUser {
|
|
128
|
+
targetMedal?: {
|
|
129
|
+
found: boolean;
|
|
130
|
+
name?: string;
|
|
131
|
+
level?: number;
|
|
132
|
+
guard_level?: number;
|
|
133
|
+
wearing_status?: number;
|
|
134
|
+
};
|
|
135
|
+
}
|