mioku-plugin-admin 3.0.1 → 3.0.3
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 +41 -52
- package/commands/notice.ts +2 -2
- package/commands/personal.ts +29 -30
- package/commands/verify.ts +15 -16
- package/config.ts +20 -10
- package/notify/index.ts +64 -57
- package/notify/welcome.ts +31 -31
- package/package.json +1 -1
- package/skills/group.ts +9 -7
- package/skills/message-image.ts +18 -8
- package/skills/personal.ts +2 -2
- package/utils/prompt-image-store.ts +7 -7
- package/verify/config.ts +6 -6
- package/verify/index.ts +16 -31
- package/verify/reaction.ts +35 -10
- package/verify/state.ts +2 -2
- package/verify/types.ts +7 -7
package/verify/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
VerifyControllerOptions,
|
|
16
16
|
} from "./types";
|
|
17
17
|
import { clearTimers, getPendingMap, pendingKey } from "./state";
|
|
18
|
-
import { isReactionPass, sendReactionPrompt } from "./reaction";
|
|
18
|
+
import { addReaction, isReactionPass, sendReactionPrompt } from "./reaction";
|
|
19
19
|
import { isNumberAnswerCorrect, sendNumberPrompt } from "./number";
|
|
20
20
|
import { checkChiralAnswer, prepareChiral } from "./chiral";
|
|
21
21
|
import { getGroupPromptImagePath } from "../utils/prompt-image-store";
|
|
@@ -40,7 +40,7 @@ export function createVerifyController(
|
|
|
40
40
|
} = options;
|
|
41
41
|
const pending = getPendingMap();
|
|
42
42
|
|
|
43
|
-
async function disableGroupVerify(groupId:
|
|
43
|
+
async function disableGroupVerify(groupId: string, reason: string) {
|
|
44
44
|
ctx.logger.warn(`admin verify 关闭群 ${groupId} 验证:${reason}`);
|
|
45
45
|
try {
|
|
46
46
|
await setVerifyConfig(
|
|
@@ -51,7 +51,7 @@ export function createVerifyController(
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async function recallMessage(bot: Bot, messageId:
|
|
54
|
+
async function recallMessage(bot: Bot, messageId: string) {
|
|
55
55
|
try {
|
|
56
56
|
await bot.recallMessage(messageId);
|
|
57
57
|
} catch (err) {
|
|
@@ -59,7 +59,7 @@ export function createVerifyController(
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
async function kickMember(bot: Bot, groupId:
|
|
62
|
+
async function kickMember(bot: Bot, groupId: string, userId: string) {
|
|
63
63
|
try {
|
|
64
64
|
await bot.kickMember(groupId, userId, false);
|
|
65
65
|
} catch (err) {
|
|
@@ -84,24 +84,9 @@ export function createVerifyController(
|
|
|
84
84
|
if (
|
|
85
85
|
p.mode === "reaction" &&
|
|
86
86
|
p.promptMessageId &&
|
|
87
|
-
bot
|
|
88
|
-
(bot.adapter === "onebotv11" || bot.adapter === "icqq")
|
|
87
|
+
bot
|
|
89
88
|
) {
|
|
90
|
-
|
|
91
|
-
if (bot.adapter === "onebotv11") {
|
|
92
|
-
// onebot:set_msg_emoji_like 专属 action
|
|
93
|
-
await bot.sendApi("set_msg_emoji_like", {
|
|
94
|
-
message_id: p.promptMessageId,
|
|
95
|
-
emoji_id: PASS_REACTION_EMOJI_ID,
|
|
96
|
-
set: true,
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
// icqq:Group.setReaction(0x9082)
|
|
100
|
-
await bot.setReaction(p.promptMessageId, PASS_REACTION_EMOJI_ID, true);
|
|
101
|
-
}
|
|
102
|
-
} catch (err) {
|
|
103
|
-
ctx.logger.warn(`admin verify 通过表态失败: ${err}`);
|
|
104
|
-
}
|
|
89
|
+
await addReaction(bot, p.promptMessageId, PASS_REACTION_EMOJI_ID, ctx);
|
|
105
90
|
}
|
|
106
91
|
|
|
107
92
|
if (!getWelcomeEnabled()) return;
|
|
@@ -252,9 +237,9 @@ export function createVerifyController(
|
|
|
252
237
|
|
|
253
238
|
async function onGroupMessage(event: RouteEvent<"message.group">) {
|
|
254
239
|
if (event?.message_type !== "group") return;
|
|
255
|
-
const selfId =
|
|
256
|
-
const groupId =
|
|
257
|
-
const userId =
|
|
240
|
+
const selfId = String(event?.self_id ?? "").trim();
|
|
241
|
+
const groupId = String(event?.group_id ?? "").trim();
|
|
242
|
+
const userId = String(event?.user_id ?? "").trim();
|
|
258
243
|
if (!selfId || !groupId || !userId) return;
|
|
259
244
|
if (userId === selfId) return;
|
|
260
245
|
|
|
@@ -264,7 +249,7 @@ export function createVerifyController(
|
|
|
264
249
|
|
|
265
250
|
const cfg = getVerifyConfig();
|
|
266
251
|
const text = ctx.text(event) || "";
|
|
267
|
-
const messageId =
|
|
252
|
+
const messageId = String(event?.message_id ?? "").trim();
|
|
268
253
|
const bot = event.bot;
|
|
269
254
|
|
|
270
255
|
if (p.mode === "number" && isNumberAnswerCorrect(p, text)) {
|
|
@@ -304,9 +289,9 @@ export function createVerifyController(
|
|
|
304
289
|
}
|
|
305
290
|
|
|
306
291
|
async function onGroupReaction(event: RouteEvent<"notice.group.reaction">) {
|
|
307
|
-
const selfId =
|
|
308
|
-
const groupId =
|
|
309
|
-
const userId =
|
|
292
|
+
const selfId = String(event?.self_id ?? "").trim();
|
|
293
|
+
const groupId = String(event?.group_id ?? "").trim();
|
|
294
|
+
const userId = String(event?.user_id ?? "").trim();
|
|
310
295
|
if (!selfId || !groupId || !userId) return;
|
|
311
296
|
if (userId === selfId) return;
|
|
312
297
|
const raw = event.raw as { is_add?: boolean } | undefined;
|
|
@@ -346,9 +331,9 @@ export function createVerifyController(
|
|
|
346
331
|
const decreaseDispose = ctx.handle(
|
|
347
332
|
"notice.group.decrease",
|
|
348
333
|
async (event) => {
|
|
349
|
-
const selfId =
|
|
350
|
-
const groupId =
|
|
351
|
-
const userId =
|
|
334
|
+
const selfId = String(event?.self_id ?? "").trim();
|
|
335
|
+
const groupId = String(event?.group_id ?? "").trim();
|
|
336
|
+
const userId = String(event?.user_id ?? "").trim();
|
|
352
337
|
if (!selfId || !groupId || !userId) return;
|
|
353
338
|
const key = pendingKey(selfId, groupId, userId);
|
|
354
339
|
if (!pending.has(key)) return;
|
package/verify/reaction.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MiokuContext } from "mioku";
|
|
1
|
+
import type { Bot, MiokuContext } from "mioku";
|
|
2
2
|
import type { VerifyConfig } from "./config";
|
|
3
3
|
import type { PendingVerify } from "./types";
|
|
4
4
|
|
|
@@ -22,24 +22,47 @@ export async function sendReactionPrompt(
|
|
|
22
22
|
}
|
|
23
23
|
if (messageId == null || messageId === "") return;
|
|
24
24
|
p.promptMessageId = messageId;
|
|
25
|
+
await addReaction(bot, messageId, cfg.reactionEmojiId, ctx);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 表态能力按平台探测:icqq 扩展方法优先,其次 OneBot 原生 action */
|
|
29
|
+
export async function addReaction(
|
|
30
|
+
bot: Bot,
|
|
31
|
+
messageId: string,
|
|
32
|
+
emojiId: string,
|
|
33
|
+
ctx: { logger: { warn(message: string): void } },
|
|
34
|
+
): Promise<boolean> {
|
|
35
|
+
const extended = bot as unknown as {
|
|
36
|
+
setReaction?: (
|
|
37
|
+
messageId: string,
|
|
38
|
+
emojiId: string,
|
|
39
|
+
set: boolean,
|
|
40
|
+
) => Promise<unknown>;
|
|
41
|
+
};
|
|
42
|
+
if (typeof extended.setReaction === "function") {
|
|
43
|
+
try {
|
|
44
|
+
await extended.setReaction(messageId, emojiId, true);
|
|
45
|
+
return true;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
ctx.logger.warn(`admin verify 添加表态失败: ${err}`);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
25
51
|
if (bot.adapter === "onebotv11") {
|
|
26
52
|
try {
|
|
27
53
|
await bot.sendApi("set_msg_emoji_like", {
|
|
28
54
|
message_id: messageId,
|
|
29
|
-
emoji_id:
|
|
55
|
+
emoji_id: emojiId,
|
|
30
56
|
set: true,
|
|
31
57
|
});
|
|
58
|
+
return true;
|
|
32
59
|
} catch (err) {
|
|
33
60
|
ctx.logger.warn(`admin verify 添加表态失败: ${err}`);
|
|
34
|
-
|
|
35
|
-
} else if (bot.adapter === "icqq") {
|
|
36
|
-
// icqq:Group.setReaction(0x9082),message_id 为群消息 cqhttp 格式
|
|
37
|
-
try {
|
|
38
|
-
await bot.setReaction(messageId, cfg.reactionEmojiId, true);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
ctx.logger.warn(`admin verify 添加表态失败: ${err}`);
|
|
61
|
+
return false;
|
|
41
62
|
}
|
|
42
63
|
}
|
|
64
|
+
ctx.logger.warn(`admin verify 当前平台(${bot.adapter})不支持消息表态`);
|
|
65
|
+
return false;
|
|
43
66
|
}
|
|
44
67
|
|
|
45
68
|
/** icqq GroupReactionEvent 的 seq 提取(cqhttp message_id 为 base64,seq 在第 9-12 字节,与 icqq parseGroupMessageId 同布局) */
|
|
@@ -77,7 +100,9 @@ export function isReactionPass(p: PendingVerify, event: unknown): boolean {
|
|
|
77
100
|
);
|
|
78
101
|
}
|
|
79
102
|
|
|
80
|
-
if (
|
|
103
|
+
if (String(raw?.message_id ?? "") !== String(p.promptMessageId ?? "")) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
81
106
|
const likes: unknown[] = Array.isArray(raw?.likes) ? raw.likes : [];
|
|
82
107
|
return likes.some((l) => {
|
|
83
108
|
const item = l as { emoji_id?: unknown };
|
package/verify/state.ts
CHANGED
|
@@ -13,8 +13,8 @@ export function getPendingMap(): Map<string, PendingVerify> {
|
|
|
13
13
|
|
|
14
14
|
export function pendingKey(
|
|
15
15
|
selfId: string | number,
|
|
16
|
-
groupId:
|
|
17
|
-
userId:
|
|
16
|
+
groupId: string,
|
|
17
|
+
userId: string,
|
|
18
18
|
): string {
|
|
19
19
|
return `${selfId}:${groupId}:${userId}`;
|
|
20
20
|
}
|
package/verify/types.ts
CHANGED
|
@@ -13,21 +13,21 @@ export interface VerifyControllerOptions {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface MemberJoinInfo {
|
|
16
|
-
selfId: string
|
|
17
|
-
groupId:
|
|
18
|
-
userId:
|
|
16
|
+
selfId: string;
|
|
17
|
+
groupId: string;
|
|
18
|
+
userId: string;
|
|
19
19
|
groupName: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface PendingVerify {
|
|
23
|
-
selfId: string
|
|
24
|
-
groupId:
|
|
25
|
-
userId:
|
|
23
|
+
selfId: string;
|
|
24
|
+
groupId: string;
|
|
25
|
+
userId: string;
|
|
26
26
|
memberName: string;
|
|
27
27
|
groupName: string;
|
|
28
28
|
mode: VerifyMode;
|
|
29
29
|
bot?: import("mioku").Bot;
|
|
30
|
-
promptMessageId?: string
|
|
30
|
+
promptMessageId?: string;
|
|
31
31
|
reactionEmojiId?: string;
|
|
32
32
|
numberAnswer?: number;
|
|
33
33
|
requiredRegions?: string[];
|