koishi-plugin-onebot-verifier 1.0.6 → 1.0.7
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/index.d.ts +1 -0
- package/lib/index.js +35 -7
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -45,7 +45,8 @@ var usage = `
|
|
|
45
45
|
var Config = import_koishi.Schema.intersect([
|
|
46
46
|
import_koishi.Schema.object({
|
|
47
47
|
notifyTarget: import_koishi.Schema.string().description("通知目标(guild/private:number)").required(),
|
|
48
|
-
debugMode: import_koishi.Schema.boolean().description("输出调试日志").default(false)
|
|
48
|
+
debugMode: import_koishi.Schema.boolean().description("输出调试日志").default(false),
|
|
49
|
+
kickBan: import_koishi.Schema.boolean().description("被踢自动处理").default(false)
|
|
49
50
|
}).description("基础配置"),
|
|
50
51
|
import_koishi.Schema.object({
|
|
51
52
|
timeout: import_koishi.Schema.number().description("请求超时时长").default(360).min(0),
|
|
@@ -78,10 +79,12 @@ var Config = import_koishi.Schema.intersect([
|
|
|
78
79
|
function apply(ctx, config = {}) {
|
|
79
80
|
const logger = new import_koishi.Logger("onebot-verifier");
|
|
80
81
|
const activeTasks = /* @__PURE__ */ new Map();
|
|
82
|
+
const inviterMap = /* @__PURE__ */ new Map();
|
|
81
83
|
const executeAction = /* @__PURE__ */ __name(async (session, kind, pass, reason = "", remark = "") => {
|
|
82
84
|
try {
|
|
83
85
|
const eventData = session.event?._data || {};
|
|
84
86
|
if (config.debugMode) logger.info(`[执行操作] 类型:${kind} 结果:${pass ? "同意" : "拒绝"} 原因:${reason || "无"}`);
|
|
87
|
+
if (pass && kind === "guild" && session.guildId && session.userId) inviterMap.set(session.guildId, session.userId);
|
|
85
88
|
if (!pass && kind === "guild" && session.guildId && (session.event?.type === "guild-added" || eventData.notice_type === "group_increase")) {
|
|
86
89
|
if (reason) {
|
|
87
90
|
try {
|
|
@@ -111,14 +114,26 @@ function apply(ctx, config = {}) {
|
|
|
111
114
|
const eventData = session.event?._data || {};
|
|
112
115
|
const userInfo = session.userId ? await session.bot.getUser?.(session.userId)?.catch(() => null) : null;
|
|
113
116
|
const groupInfo = kind !== "friend" && session.guildId ? await session.bot.getGuild?.(session.guildId)?.catch(() => null) : null;
|
|
114
|
-
const
|
|
117
|
+
const adminId = eventData.operator_id || session.event.operator?.id;
|
|
118
|
+
const adminInfo = adminId && session.userId && adminId !== session.userId ? await session.bot.getUser?.(adminId)?.catch(() => null) : null;
|
|
115
119
|
const infoLines = [];
|
|
116
120
|
if (userInfo?.avatar) infoLines.push(`<image url="${userInfo.avatar}"/>`);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (kind
|
|
121
|
-
if (
|
|
121
|
+
let typeName = "";
|
|
122
|
+
if (kind === "friend") typeName = "好友申请";
|
|
123
|
+
else if (kind === "member") typeName = "加群请求";
|
|
124
|
+
else if (kind === "guild") typeName = "群组邀请";
|
|
125
|
+
else if (kind === "removed") typeName = eventData.sub_type === "kick_me" ? "机器人被踢" : "机器人退群";
|
|
126
|
+
let statusText = "";
|
|
127
|
+
if (kind === "removed") {
|
|
128
|
+
if (eventData.sub_type === "kick_me" && config.kickBan) statusText = " [自动清理]";
|
|
129
|
+
} else {
|
|
130
|
+
statusText = status === "auto_pass" ? " [自动通过]" : status === "auto_reject" ? " [自动拒绝]" : " [等待处理]";
|
|
131
|
+
}
|
|
132
|
+
infoLines.push(`类型:${typeName}${statusText}`);
|
|
133
|
+
if (kind !== "guild" && kind !== "removed" || session.userId !== session.selfId) {
|
|
134
|
+
infoLines.push(`用户:${userInfo?.name || session.userId}${session.userId ? `(${session.userId})` : ""}`);
|
|
135
|
+
}
|
|
136
|
+
if (adminInfo) infoLines.push(`管理:${adminInfo.name ? `${adminInfo.name}(${adminId})` : adminId}`);
|
|
122
137
|
if (groupInfo) infoLines.push(`群组:${groupInfo.name ? `${groupInfo.name}(${session.guildId})` : session.guildId}`);
|
|
123
138
|
if (eventData.comment) infoLines.push(`验证信息:${eventData.comment}`);
|
|
124
139
|
const content = infoLines.join("\n");
|
|
@@ -250,6 +265,19 @@ function apply(ctx, config = {}) {
|
|
|
250
265
|
ctx.on("guild-request", hookEvent("guild"));
|
|
251
266
|
ctx.on("guild-member-request", hookEvent("member"));
|
|
252
267
|
ctx.on("guild-added", hookEvent("guild"));
|
|
268
|
+
ctx.on("guild-removed", async (session) => {
|
|
269
|
+
const subType = session.event?._data?.sub_type;
|
|
270
|
+
if (subType === "kick_me") {
|
|
271
|
+
const inviterId = inviterMap.get(session.guildId);
|
|
272
|
+
if (inviterId) {
|
|
273
|
+
await session.onebot?.deleteFriend(inviterId);
|
|
274
|
+
inviterMap.delete(session.guildId);
|
|
275
|
+
}
|
|
276
|
+
await session.execute(`analyse.clear -g ${session.guildId}`).catch(() => {
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
await sendNotice(session, "removed");
|
|
280
|
+
});
|
|
253
281
|
ctx.middleware(async (session, next) => {
|
|
254
282
|
if (typeof session.content !== "string" || !session.quote?.id) return next();
|
|
255
283
|
const activeTask = activeTasks.get(session.quote.id);
|