mioku-plugin-admin 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.
- package/commands/group.ts +461 -451
- package/commands/personal.ts +129 -99
- package/commands/verify.ts +315 -306
- package/index.ts +0 -2
- package/notify/index.ts +2 -2
- package/package.json +2 -279
package/commands/personal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Bot, MessageEvent, MessageInput, MessageTarget, MiokuContext, MessageSegment } from "mioku";
|
|
1
|
+
import type { Bot, CommandDefinition, MessageEvent, MessageInput, MessageTarget, MiokuContext, MessageSegment } from "mioku";
|
|
2
2
|
import {createGroupRef} from "mioku";
|
|
3
3
|
import { extractImageUrl } from "../config";
|
|
4
4
|
import { replyAdminErrorNotice } from "./notice";
|
|
@@ -150,28 +150,30 @@ async function sendForwardByEvent(options: {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
export function registerPersonalCommands(ctx: MiokuContext) {
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
const register = (command: CommandDefinition) => {
|
|
154
|
+
const { handler, ...rest } = command;
|
|
155
|
+
ctx.command({
|
|
156
|
+
...rest,
|
|
157
|
+
prefixes: false,
|
|
158
|
+
handler: async (c) => {
|
|
159
|
+
if (c.event.user_id === c.event.self_id) return;
|
|
160
|
+
await handler(c);
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
};
|
|
157
164
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (text.startsWith("/改头像")) {
|
|
167
|
-
if (!isMaster) {
|
|
168
|
-
ctx.logger.warn("[admin] 改头像功能仅主人可用");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
165
|
+
register({
|
|
166
|
+
name: "/改头像",
|
|
167
|
+
match: /^\/改头像/,
|
|
168
|
+
permission: "master",
|
|
169
|
+
description: "修改Bot头像",
|
|
170
|
+
handler: async ({ event }) => {
|
|
171
|
+
const bot = event.bot;
|
|
172
|
+
if (!bot) return;
|
|
171
173
|
const imageUrl = extractImageUrl(event.message);
|
|
172
174
|
if (!imageUrl) {
|
|
173
175
|
await event.reply("图片呢图片呢~", true);
|
|
174
|
-
|
|
176
|
+
return;
|
|
175
177
|
}
|
|
176
178
|
try {
|
|
177
179
|
await bot.setAvatar(imageUrl);
|
|
@@ -184,20 +186,22 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
184
186
|
fallbackMessage: `出错了,笨蛋~ ${String(err)}`,
|
|
185
187
|
error: err,
|
|
186
188
|
});
|
|
187
|
-
return;
|
|
188
189
|
}
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
},
|
|
191
|
+
});
|
|
191
192
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
register({
|
|
194
|
+
name: "/改昵称",
|
|
195
|
+
match: /^\/改昵称/,
|
|
196
|
+
permission: "master",
|
|
197
|
+
description: "修改Bot昵称",
|
|
198
|
+
handler: async ({ event, body }) => {
|
|
199
|
+
const bot = event.bot;
|
|
200
|
+
if (!bot) return;
|
|
201
|
+
const nickname = body.replace(/^\/改昵称\s*/, "").trim();
|
|
198
202
|
if (!nickname) {
|
|
199
203
|
await event.reply("想改成什么昵称呀~", true);
|
|
200
|
-
|
|
204
|
+
return;
|
|
201
205
|
}
|
|
202
206
|
try {
|
|
203
207
|
await bot.setProfile({ nickname });
|
|
@@ -211,18 +215,21 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
211
215
|
error: err,
|
|
212
216
|
});
|
|
213
217
|
}
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
},
|
|
219
|
+
});
|
|
216
220
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
register({
|
|
222
|
+
name: "/改签名",
|
|
223
|
+
match: /^\/改签名/,
|
|
224
|
+
permission: "master",
|
|
225
|
+
description: "修改Bot个性签名",
|
|
226
|
+
handler: async ({ event, body }) => {
|
|
227
|
+
const bot = event.bot;
|
|
228
|
+
if (!bot) return;
|
|
229
|
+
const personalNote = body.replace(/^\/改签名\s*/, "").trim();
|
|
223
230
|
if (!personalNote) {
|
|
224
231
|
await event.reply("想改成什么签名呀~", true);
|
|
225
|
-
|
|
232
|
+
return;
|
|
226
233
|
}
|
|
227
234
|
try {
|
|
228
235
|
await bot.setProfile({ personal_note: personalNote });
|
|
@@ -236,16 +243,18 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
236
243
|
error: err,
|
|
237
244
|
});
|
|
238
245
|
}
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
},
|
|
247
|
+
});
|
|
241
248
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
+
register({
|
|
250
|
+
name: "/改性别",
|
|
251
|
+
match: /^\/改性别/,
|
|
252
|
+
permission: "master",
|
|
253
|
+
description: "修改Bot性别",
|
|
254
|
+
handler: async ({ event, body }) => {
|
|
255
|
+
const bot = event.bot;
|
|
256
|
+
if (!bot) return;
|
|
257
|
+
const sex = parseProfileSex(body.replace(/^\/改性别\s*/, ""));
|
|
249
258
|
try {
|
|
250
259
|
await bot.setProfile({ sex });
|
|
251
260
|
await event.reply("done");
|
|
@@ -258,15 +267,19 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
258
267
|
error: err,
|
|
259
268
|
});
|
|
260
269
|
}
|
|
261
|
-
|
|
262
|
-
|
|
270
|
+
},
|
|
271
|
+
});
|
|
263
272
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
register({
|
|
274
|
+
name: "/删好友",
|
|
275
|
+
match: /^\/删好友(?:\s|$)/,
|
|
276
|
+
permission: "master",
|
|
277
|
+
description: "删除好友",
|
|
278
|
+
usage: "/删好友 qq号",
|
|
279
|
+
handler: async ({ event, body }) => {
|
|
280
|
+
const bot = event.bot;
|
|
281
|
+
if (!bot) return;
|
|
282
|
+
const qq = parseInt(body.replace(/^\/删好友\s*/, "").trim(), 10);
|
|
270
283
|
if (!qq) {
|
|
271
284
|
await replyAdminErrorNotice({
|
|
272
285
|
ctx,
|
|
@@ -288,15 +301,19 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
288
301
|
error: err,
|
|
289
302
|
});
|
|
290
303
|
}
|
|
291
|
-
|
|
292
|
-
|
|
304
|
+
},
|
|
305
|
+
});
|
|
293
306
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
307
|
+
register({
|
|
308
|
+
name: "/退群",
|
|
309
|
+
match: /^\/退群(?:\s|$)/,
|
|
310
|
+
permission: "master",
|
|
311
|
+
description: "退出群聊",
|
|
312
|
+
usage: "/退群 群号",
|
|
313
|
+
handler: async ({ event, body }) => {
|
|
314
|
+
const bot = event.bot;
|
|
315
|
+
if (!bot) return;
|
|
316
|
+
const targetGroup = parseInt(body.replace(/^\/退群\s*/, "").trim(), 10);
|
|
300
317
|
if (!targetGroup) {
|
|
301
318
|
await replyAdminErrorNotice({
|
|
302
319
|
ctx,
|
|
@@ -318,15 +335,19 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
318
335
|
error: err,
|
|
319
336
|
});
|
|
320
337
|
}
|
|
321
|
-
|
|
322
|
-
|
|
338
|
+
},
|
|
339
|
+
});
|
|
323
340
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
341
|
+
register({
|
|
342
|
+
name: "/发好友",
|
|
343
|
+
match: /^\/发好友(?:\s|$)/,
|
|
344
|
+
permission: "master",
|
|
345
|
+
description: "给好友发送私聊消息",
|
|
346
|
+
usage: "/发好友 qq号 内容",
|
|
347
|
+
handler: async ({ event, body }) => {
|
|
348
|
+
const bot = event.bot;
|
|
349
|
+
if (!bot) return;
|
|
350
|
+
const matched = body.match(/^\/发好友\s*(\d+)\s*([\s\S]*)$/);
|
|
330
351
|
if (!matched) {
|
|
331
352
|
await replyAdminErrorNotice({
|
|
332
353
|
ctx,
|
|
@@ -367,15 +388,19 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
367
388
|
error: err,
|
|
368
389
|
});
|
|
369
390
|
}
|
|
370
|
-
|
|
371
|
-
|
|
391
|
+
},
|
|
392
|
+
});
|
|
372
393
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
394
|
+
register({
|
|
395
|
+
name: "/发群聊",
|
|
396
|
+
match: /^\/发群聊(?:\s|$)/,
|
|
397
|
+
permission: "master",
|
|
398
|
+
description: "给群聊发送消息",
|
|
399
|
+
usage: "/发群聊 群号 内容",
|
|
400
|
+
handler: async ({ event, body }) => {
|
|
401
|
+
const bot = event.bot;
|
|
402
|
+
if (!bot) return;
|
|
403
|
+
const matched = body.match(/^\/发群聊\s*(\d+)\s*([\s\S]*)$/);
|
|
379
404
|
if (!matched) {
|
|
380
405
|
await replyAdminErrorNotice({
|
|
381
406
|
ctx,
|
|
@@ -416,15 +441,18 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
416
441
|
error: err,
|
|
417
442
|
});
|
|
418
443
|
}
|
|
419
|
-
|
|
420
|
-
|
|
444
|
+
},
|
|
445
|
+
});
|
|
421
446
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
447
|
+
register({
|
|
448
|
+
name: "/全部好友",
|
|
449
|
+
match: /^\/全部好友$/,
|
|
450
|
+
permission: "master",
|
|
451
|
+
description: "获取全部好友列表",
|
|
452
|
+
handler: async ({ event }) => {
|
|
453
|
+
const bot = event.bot;
|
|
454
|
+
if (!bot) return;
|
|
455
|
+
if (event.message_type === "group") {
|
|
428
456
|
await event.reply("在私聊使用试试看吧~", true);
|
|
429
457
|
return;
|
|
430
458
|
}
|
|
@@ -464,15 +492,18 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
464
492
|
error: err,
|
|
465
493
|
});
|
|
466
494
|
}
|
|
467
|
-
|
|
468
|
-
|
|
495
|
+
},
|
|
496
|
+
});
|
|
469
497
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
498
|
+
register({
|
|
499
|
+
name: "/全部群聊",
|
|
500
|
+
match: /^\/全部群聊$/,
|
|
501
|
+
permission: "master",
|
|
502
|
+
description: "获取全部群聊列表",
|
|
503
|
+
handler: async ({ event }) => {
|
|
504
|
+
const bot = event.bot;
|
|
505
|
+
if (!bot) return;
|
|
506
|
+
if (event.message_type === "group") {
|
|
476
507
|
await event.reply("在私聊使用试试看吧~", true);
|
|
477
508
|
return;
|
|
478
509
|
}
|
|
@@ -489,8 +520,8 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
489
520
|
}
|
|
490
521
|
const nodes = groupList.map((group) =>
|
|
491
522
|
ctx.segment.raw("node", {
|
|
492
|
-
user_id:
|
|
493
|
-
nickname: String(
|
|
523
|
+
user_id: event.self_id ?? "",
|
|
524
|
+
nickname: String(event.self_id ?? ""),
|
|
494
525
|
content: [
|
|
495
526
|
ctx.segment.image(
|
|
496
527
|
`https://p.qlogo.cn/gh/${group.group_id}/${group.group_id}/640/`,
|
|
@@ -511,7 +542,6 @@ export function registerPersonalCommands(ctx: MiokuContext) {
|
|
|
511
542
|
error: err,
|
|
512
543
|
});
|
|
513
544
|
}
|
|
514
|
-
|
|
515
|
-
}
|
|
545
|
+
},
|
|
516
546
|
});
|
|
517
547
|
}
|