mioku-plugin-admin 2.3.4 → 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 +5 -5
- package/commands/personal.ts +112 -184
- package/commands/verify.ts +43 -35
- package/config.ts +29 -17
- package/index.ts +24 -9
- package/notify/index.ts +108 -138
- package/notify/welcome.ts +54 -46
- package/package.json +3 -5
- package/skills/group.ts +87 -143
- package/skills/message-image.ts +8 -9
- package/skills/personal.ts +73 -99
- package/verify/chiral.ts +4 -4
- package/verify/index.ts +65 -51
- 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/skills.ts +0 -7
package/verify/reaction.ts
CHANGED
|
@@ -1,38 +1,86 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MiokuContext } from "mioku";
|
|
2
2
|
import type { VerifyConfig } from "./config";
|
|
3
3
|
import type { PendingVerify } from "./types";
|
|
4
4
|
|
|
5
5
|
export async function sendReactionPrompt(
|
|
6
|
-
ctx:
|
|
6
|
+
ctx: MiokuContext,
|
|
7
7
|
cfg: VerifyConfig,
|
|
8
8
|
p: PendingVerify,
|
|
9
9
|
): Promise<void> {
|
|
10
|
-
const bot =
|
|
10
|
+
const bot = p.bot;
|
|
11
11
|
if (!bot) return;
|
|
12
|
-
let messageId: number | undefined;
|
|
12
|
+
let messageId: string | number | undefined;
|
|
13
13
|
try {
|
|
14
|
-
const res = await bot.
|
|
14
|
+
const res = await bot.sendMessage({ type: "group", group_id: p.groupId }, [
|
|
15
15
|
ctx.segment.at(String(p.userId)),
|
|
16
16
|
ctx.segment.text(` ${cfg.reactionPrompt}`),
|
|
17
17
|
]);
|
|
18
|
-
messageId =
|
|
18
|
+
messageId = res?.message_id;
|
|
19
19
|
} catch (err) {
|
|
20
20
|
ctx.logger.warn(`admin verify 发送回应提示失败: ${err}`);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
23
|
+
if (messageId == null || messageId === "") return;
|
|
24
24
|
p.promptMessageId = messageId;
|
|
25
|
+
if (bot.adapter === "onebotv11") {
|
|
26
|
+
try {
|
|
27
|
+
await bot.sendApi("set_msg_emoji_like", {
|
|
28
|
+
message_id: messageId,
|
|
29
|
+
emoji_id: cfg.reactionEmojiId,
|
|
30
|
+
set: true,
|
|
31
|
+
});
|
|
32
|
+
} catch (err) {
|
|
33
|
+
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}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** icqq GroupReactionEvent 的 seq 提取(cqhttp message_id 为 base64,seq 在第 9-12 字节,与 icqq parseGroupMessageId 同布局) */
|
|
46
|
+
function seqOfIcqqMessageId(messageId: string | number): number {
|
|
25
47
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
48
|
+
const buf = Buffer.from(String(messageId), "base64");
|
|
49
|
+
return buf.length >= 12 ? buf.readUInt32BE(8) : 0;
|
|
50
|
+
} catch {
|
|
51
|
+
return 0;
|
|
29
52
|
}
|
|
30
53
|
}
|
|
31
54
|
|
|
32
|
-
export function isReactionPass(p: PendingVerify, event:
|
|
55
|
+
export function isReactionPass(p: PendingVerify, event: unknown): boolean {
|
|
33
56
|
if (!p.promptMessageId) return false;
|
|
34
|
-
|
|
57
|
+
const ev = event as { raw?: unknown };
|
|
58
|
+
const raw = (ev.raw ?? event) as {
|
|
59
|
+
message_id?: unknown;
|
|
60
|
+
likes?: unknown;
|
|
61
|
+
notice_type?: unknown;
|
|
62
|
+
sub_type?: unknown;
|
|
63
|
+
set?: unknown;
|
|
64
|
+
seq?: unknown;
|
|
65
|
+
id?: unknown;
|
|
66
|
+
};
|
|
35
67
|
const emojiId = String(p.reactionEmojiId || "");
|
|
36
|
-
|
|
37
|
-
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
raw?.sub_type === "reaction" &&
|
|
71
|
+
String(raw.notice_type ?? "") === "group"
|
|
72
|
+
) {
|
|
73
|
+
if (raw.set === false) return false;
|
|
74
|
+
const seq = seqOfIcqqMessageId(p.promptMessageId);
|
|
75
|
+
return (
|
|
76
|
+
seq > 0 && Number(raw.seq) === seq && String(raw.id ?? "") === emojiId
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (Number(raw?.message_id || 0) !== Number(p.promptMessageId)) return false;
|
|
81
|
+
const likes: unknown[] = Array.isArray(raw?.likes) ? raw.likes : [];
|
|
82
|
+
return likes.some((l) => {
|
|
83
|
+
const item = l as { emoji_id?: unknown };
|
|
84
|
+
return String(item?.emoji_id || "") === emojiId;
|
|
85
|
+
});
|
|
38
86
|
}
|
package/verify/state.ts
CHANGED
package/verify/types.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MiokuContext } from "mioku";
|
|
2
2
|
import type { AIService } from "mioku";
|
|
3
3
|
import type { AdminConfig } from "../config";
|
|
4
4
|
import type { VerifyConfig, VerifyMode } from "./config";
|
|
5
5
|
|
|
6
6
|
export interface VerifyControllerOptions {
|
|
7
|
-
ctx:
|
|
7
|
+
ctx: MiokuContext;
|
|
8
8
|
aiService?: AIService;
|
|
9
9
|
getConfig: () => AdminConfig;
|
|
10
10
|
getVerifyConfig: () => VerifyConfig;
|
|
@@ -13,20 +13,21 @@ export interface VerifyControllerOptions {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface MemberJoinInfo {
|
|
16
|
-
selfId: number;
|
|
16
|
+
selfId: string | number;
|
|
17
17
|
groupId: number;
|
|
18
18
|
userId: number;
|
|
19
19
|
groupName: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface PendingVerify {
|
|
23
|
-
selfId: number;
|
|
23
|
+
selfId: string | number;
|
|
24
24
|
groupId: number;
|
|
25
25
|
userId: number;
|
|
26
26
|
memberName: string;
|
|
27
27
|
groupName: string;
|
|
28
28
|
mode: VerifyMode;
|
|
29
|
-
|
|
29
|
+
bot?: import("mioku").Bot;
|
|
30
|
+
promptMessageId?: string | number;
|
|
30
31
|
reactionEmojiId?: string;
|
|
31
32
|
numberAnswer?: number;
|
|
32
33
|
requiredRegions?: string[];
|
|
@@ -39,9 +40,18 @@ export interface PendingVerify {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export interface VerifyController {
|
|
42
|
-
handleMemberJoin(
|
|
43
|
-
|
|
43
|
+
handleMemberJoin(
|
|
44
|
+
info: MemberJoinInfo,
|
|
45
|
+
bot?: import("mioku").Bot,
|
|
46
|
+
): Promise<boolean>;
|
|
47
|
+
restartVerification(
|
|
48
|
+
info: MemberJoinInfo,
|
|
49
|
+
bot?: import("mioku").Bot,
|
|
50
|
+
): Promise<boolean>;
|
|
44
51
|
bypassVerification(info: MemberJoinInfo): Promise<void>;
|
|
45
|
-
trySendCustomWelcome(
|
|
52
|
+
trySendCustomWelcome(
|
|
53
|
+
info: MemberJoinInfo,
|
|
54
|
+
bot?: import("mioku").Bot,
|
|
55
|
+
): Promise<boolean>;
|
|
46
56
|
dispose(): void;
|
|
47
57
|
}
|