mioku-plugin-admin 2.3.5 → 3.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/commands/group.ts +34 -54
- package/commands/notice.ts +3 -3
- package/commands/personal.ts +112 -184
- package/commands/verify.ts +43 -35
- package/config.ts +29 -17
- package/index.ts +5 -5
- package/notify/index.ts +108 -138
- package/notify/welcome.ts +52 -44
- package/package.json +3 -5
- package/skills/group.ts +87 -143
- package/skills/message-image.ts +8 -9
- package/skills/personal.ts +72 -98
- package/verify/chiral.ts +4 -4
- package/verify/index.ts +59 -45
- package/verify/number.ts +4 -4
- package/verify/reaction.ts +62 -14
- package/verify/state.ts +1 -1
- package/verify/types.ts +18 -8
package/commands/group.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MiokuContext } from "mioku";
|
|
2
|
+
|
|
2
3
|
import {
|
|
3
4
|
extractImageUrl,
|
|
4
5
|
getAtUserId,
|
|
@@ -13,8 +14,8 @@ function formatGroupRole(role: string): string {
|
|
|
13
14
|
return "群成员";
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export function registerGroupAdminCommands(ctx:
|
|
17
|
-
ctx.handle("message", async (event
|
|
17
|
+
export function registerGroupAdminCommands(ctx: MiokuContext) {
|
|
18
|
+
ctx.handle("message", async (event) => {
|
|
18
19
|
const text = ctx.text(event)?.trim();
|
|
19
20
|
if (!text) return;
|
|
20
21
|
if (event.user_id === event.self_id) return;
|
|
@@ -47,15 +48,15 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
47
48
|
|
|
48
49
|
try {
|
|
49
50
|
const selfId = event.self_id;
|
|
50
|
-
const bot =
|
|
51
|
+
const bot = event.bot;
|
|
51
52
|
if (!bot) return;
|
|
52
53
|
|
|
53
54
|
const isGroup = event.message_type === "group";
|
|
54
|
-
const
|
|
55
|
-
if (!isGroup || !
|
|
55
|
+
const groupIdNum = isGroup && event.group_id ? Number(event.group_id) : undefined;
|
|
56
|
+
if (!isGroup || !groupIdNum) return;
|
|
56
57
|
|
|
57
58
|
const isMaster = ctx.isOwner?.(event) ?? false;
|
|
58
|
-
const senderRole = await getMemberRole(bot,
|
|
59
|
+
const senderRole = await getMemberRole(bot, groupIdNum, Number(event.user_id));
|
|
59
60
|
const hasAdminPermission =
|
|
60
61
|
isMaster || senderRole === "owner" || senderRole === "admin";
|
|
61
62
|
|
|
@@ -78,7 +79,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
78
79
|
targetUserId: number,
|
|
79
80
|
actionName: string,
|
|
80
81
|
) => {
|
|
81
|
-
const targetRole = await getMemberRole(bot,
|
|
82
|
+
const targetRole = await getMemberRole(bot, groupIdNum, targetUserId);
|
|
82
83
|
if (senderRole !== targetRole) return true;
|
|
83
84
|
|
|
84
85
|
await replyAdminErrorNotice({
|
|
@@ -90,10 +91,9 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
90
91
|
return false;
|
|
91
92
|
};
|
|
92
93
|
|
|
93
|
-
// 普通群员只能给自己设置头衔。
|
|
94
94
|
if (text.startsWith("我要头衔")) {
|
|
95
95
|
const atUser = getAtUserId(event.message);
|
|
96
|
-
if (atUser && atUser !== event.user_id) {
|
|
96
|
+
if (atUser != null && atUser !== Number(event.user_id)) {
|
|
97
97
|
await event.reply("管好自己呗~", true);
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
@@ -105,11 +105,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
try {
|
|
108
|
-
await (
|
|
109
|
-
groupId,
|
|
110
|
-
event.user_id,
|
|
111
|
-
title,
|
|
112
|
-
);
|
|
108
|
+
await bot.setMemberTitle(groupIdNum, event.user_id!, title);
|
|
113
109
|
await replyDone();
|
|
114
110
|
} catch (err) {
|
|
115
111
|
await replyAdminErrorNotice({
|
|
@@ -123,7 +119,6 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
123
119
|
return;
|
|
124
120
|
}
|
|
125
121
|
|
|
126
|
-
// 改头衔
|
|
127
122
|
if (text.startsWith("改头衔") || text.startsWith("/改头衔")) {
|
|
128
123
|
if (!(await ensureAdminPermission())) return;
|
|
129
124
|
|
|
@@ -166,7 +161,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
try {
|
|
169
|
-
await
|
|
164
|
+
await bot.setMemberTitle(groupIdNum, targetUser, title);
|
|
170
165
|
await replyDone();
|
|
171
166
|
} catch (err) {
|
|
172
167
|
await replyAdminErrorNotice({
|
|
@@ -201,10 +196,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
201
196
|
}
|
|
202
197
|
if (!(await ensureDangerousTargetPermission(atUser, "踢出"))) return;
|
|
203
198
|
try {
|
|
204
|
-
await bot.
|
|
205
|
-
group_id: groupId,
|
|
206
|
-
user_id: atUser,
|
|
207
|
-
});
|
|
199
|
+
await bot.kickMember(groupIdNum, atUser);
|
|
208
200
|
await replyDone();
|
|
209
201
|
} catch (err) {
|
|
210
202
|
await replyAdminErrorNotice({
|
|
@@ -251,7 +243,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
251
243
|
const durationStr = rest.replace(/@\d+\s*/, "").trim();
|
|
252
244
|
const durationSec = parseDuration(durationStr) || 10 * 60;
|
|
253
245
|
try {
|
|
254
|
-
await bot.
|
|
246
|
+
await bot.banMember(groupIdNum, atUser, durationSec);
|
|
255
247
|
await replyDone();
|
|
256
248
|
} catch (err) {
|
|
257
249
|
await replyAdminErrorNotice({
|
|
@@ -293,7 +285,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
293
285
|
return;
|
|
294
286
|
}
|
|
295
287
|
try {
|
|
296
|
-
await bot.
|
|
288
|
+
await bot.banMember(groupIdNum, atUser, 0);
|
|
297
289
|
await replyDone();
|
|
298
290
|
} catch (err) {
|
|
299
291
|
await replyAdminErrorNotice({
|
|
@@ -326,11 +318,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
326
318
|
return;
|
|
327
319
|
}
|
|
328
320
|
try {
|
|
329
|
-
await bot.
|
|
330
|
-
group_id: groupId,
|
|
331
|
-
user_id: atUser,
|
|
332
|
-
enable: true,
|
|
333
|
-
});
|
|
321
|
+
await bot.setMemberAdmin(groupIdNum, atUser, true);
|
|
334
322
|
await replyDone();
|
|
335
323
|
} catch (err) {
|
|
336
324
|
await replyAdminErrorNotice({
|
|
@@ -347,10 +335,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
347
335
|
if (text === "/全体禁言") {
|
|
348
336
|
if (!(await ensureAdminPermission())) return;
|
|
349
337
|
try {
|
|
350
|
-
await bot.
|
|
351
|
-
group_id: groupId,
|
|
352
|
-
enable: true,
|
|
353
|
-
});
|
|
338
|
+
await bot.setGroupWholeBan(groupIdNum, true);
|
|
354
339
|
await replyDone();
|
|
355
340
|
} catch (err) {
|
|
356
341
|
await replyAdminErrorNotice({
|
|
@@ -367,10 +352,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
367
352
|
if (text === "/全体解禁") {
|
|
368
353
|
if (!(await ensureAdminPermission())) return;
|
|
369
354
|
try {
|
|
370
|
-
await bot.
|
|
371
|
-
group_id: groupId,
|
|
372
|
-
enable: false,
|
|
373
|
-
});
|
|
355
|
+
await bot.setGroupWholeBan(groupIdNum, false);
|
|
374
356
|
await replyDone();
|
|
375
357
|
} catch (err) {
|
|
376
358
|
await replyAdminErrorNotice({
|
|
@@ -385,8 +367,9 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
385
367
|
}
|
|
386
368
|
|
|
387
369
|
if (text.startsWith("改群名片") || text.startsWith("/改群名片")) {
|
|
388
|
-
if (!isGroup || !
|
|
389
|
-
|
|
370
|
+
if (!isGroup || !groupIdNum) {
|
|
371
|
+
await event.reply("这个要在群里用哦~", true);
|
|
372
|
+
return;
|
|
390
373
|
}
|
|
391
374
|
if (!(await ensureAdminPermission())) return;
|
|
392
375
|
const card = text.replace(/^\/?改群名片\s*/, "").trim();
|
|
@@ -400,7 +383,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
400
383
|
return;
|
|
401
384
|
}
|
|
402
385
|
try {
|
|
403
|
-
await bot.
|
|
386
|
+
await bot.setMemberCard(groupIdNum, selfId, card);
|
|
404
387
|
await event.reply("done");
|
|
405
388
|
} catch (err) {
|
|
406
389
|
await replyAdminErrorNotice({
|
|
@@ -415,8 +398,9 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
415
398
|
}
|
|
416
399
|
|
|
417
400
|
if (text.startsWith("/改群昵称")) {
|
|
418
|
-
if (!isGroup || !
|
|
419
|
-
|
|
401
|
+
if (!isGroup || !groupIdNum) {
|
|
402
|
+
await event.reply("这个要在群里用哦~", true);
|
|
403
|
+
return;
|
|
420
404
|
}
|
|
421
405
|
if (!(await ensureAdminPermission())) return;
|
|
422
406
|
const groupName = text.replace(/^\/改群昵称\s*/, "").trim();
|
|
@@ -431,10 +415,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
431
415
|
return;
|
|
432
416
|
}
|
|
433
417
|
try {
|
|
434
|
-
await bot.
|
|
435
|
-
group_id: groupId,
|
|
436
|
-
group_name: groupName,
|
|
437
|
-
});
|
|
418
|
+
await bot.setGroupName(groupIdNum, groupName);
|
|
438
419
|
await event.reply("done");
|
|
439
420
|
} catch (err) {
|
|
440
421
|
await replyAdminErrorNotice({
|
|
@@ -449,8 +430,9 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
449
430
|
}
|
|
450
431
|
|
|
451
432
|
if (text.startsWith("/改群头像")) {
|
|
452
|
-
if (!isGroup || !
|
|
453
|
-
|
|
433
|
+
if (!isGroup || !groupIdNum) {
|
|
434
|
+
await event.reply("这个要在群里用哦~", true);
|
|
435
|
+
return;
|
|
454
436
|
}
|
|
455
437
|
if (!(await ensureAdminPermission())) return;
|
|
456
438
|
const imageUrl = extractImageUrl(event.message);
|
|
@@ -465,10 +447,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
465
447
|
return;
|
|
466
448
|
}
|
|
467
449
|
try {
|
|
468
|
-
await bot.
|
|
469
|
-
group_id: groupId,
|
|
470
|
-
file: imageUrl,
|
|
471
|
-
});
|
|
450
|
+
await bot.setGroupPortrait(groupIdNum, imageUrl);
|
|
472
451
|
await event.reply("done");
|
|
473
452
|
} catch (err) {
|
|
474
453
|
await replyAdminErrorNotice({
|
|
@@ -484,8 +463,9 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
484
463
|
|
|
485
464
|
// 撤回 — 引用一条消息后,bot 撤回该消息
|
|
486
465
|
if (text === "/撤回" || text === "撤回") {
|
|
487
|
-
if (!isGroup || !
|
|
488
|
-
|
|
466
|
+
if (!isGroup || !groupIdNum) {
|
|
467
|
+
await event.reply("这个要在群里用哦~", true);
|
|
468
|
+
return;
|
|
489
469
|
}
|
|
490
470
|
if (!(await ensureAdminPermission())) return;
|
|
491
471
|
|
|
@@ -502,7 +482,7 @@ export function registerGroupAdminCommands(ctx: MiokiContext) {
|
|
|
502
482
|
}
|
|
503
483
|
|
|
504
484
|
try {
|
|
505
|
-
await bot.
|
|
485
|
+
await bot.recallMessage(quotedId);
|
|
506
486
|
await replyDone();
|
|
507
487
|
} catch (err) {
|
|
508
488
|
await replyAdminErrorNotice({
|
package/commands/notice.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MessageEvent, MiokuContext } from "mioku";
|
|
2
2
|
import { getService, Services } from "mioku";
|
|
3
3
|
|
|
4
4
|
function normalizeErrorMessage(error: unknown): string {
|
|
@@ -16,8 +16,8 @@ function normalizeErrorMessage(error: unknown): string {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export async function replyAdminErrorNotice(options: {
|
|
19
|
-
ctx:
|
|
20
|
-
event:
|
|
19
|
+
ctx: MiokuContext;
|
|
20
|
+
event: MessageEvent;
|
|
21
21
|
instruction: string;
|
|
22
22
|
fallbackMessage: string;
|
|
23
23
|
error?: unknown;
|