koishi-plugin-group-control 0.2.10 → 0.2.11
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/database.d.ts +9 -0
- package/lib/index.js +54 -3
- package/package.json +1 -1
package/lib/database.d.ts
CHANGED
|
@@ -19,11 +19,16 @@ export interface GroupBotStatus {
|
|
|
19
19
|
guildId: string;
|
|
20
20
|
botEnabled: boolean;
|
|
21
21
|
}
|
|
22
|
+
export interface SmallGroupWhitelist {
|
|
23
|
+
platform: string;
|
|
24
|
+
guildId: string;
|
|
25
|
+
}
|
|
22
26
|
declare module 'koishi' {
|
|
23
27
|
interface Tables {
|
|
24
28
|
blacklisted_guild: BlacklistedGuild;
|
|
25
29
|
command_frequency_record: CommandFrequencyRecord;
|
|
26
30
|
group_bot_status: GroupBotStatus;
|
|
31
|
+
small_group_whitelist: SmallGroupWhitelist;
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
export declare const name = "group-control-database";
|
|
@@ -38,3 +43,7 @@ export declare function getCommandFrequencyRecord(ctx: Context, platform: string
|
|
|
38
43
|
export declare function updateCommandFrequencyRecord(ctx: Context, platform: string, guildId: string, data: Partial<CommandFrequencyRecord>): Promise<void>;
|
|
39
44
|
export declare function getGroupBotStatus(ctx: Context, platform: string, guildId: string): Promise<GroupBotStatus | null>;
|
|
40
45
|
export declare function setGroupBotStatus(ctx: Context, platform: string, guildId: string, botEnabled: boolean): Promise<void>;
|
|
46
|
+
export declare function isInSmallGroupWhitelist(ctx: Context, guildId: string): Promise<boolean>;
|
|
47
|
+
export declare function addToSmallGroupWhitelist(ctx: Context, guildId: string): Promise<void>;
|
|
48
|
+
export declare function removeFromSmallGroupWhitelist(ctx: Context, guildId: string): Promise<void>;
|
|
49
|
+
export declare function getAllSmallGroupWhitelist(ctx: Context): Promise<SmallGroupWhitelist[]>;
|
package/lib/index.js
CHANGED
|
@@ -30,15 +30,19 @@ module.exports = __toCommonJS(src_exports);
|
|
|
30
30
|
var database_exports = {};
|
|
31
31
|
__export(database_exports, {
|
|
32
32
|
BLACKLIST_PLATFORM: () => BLACKLIST_PLATFORM,
|
|
33
|
+
addToSmallGroupWhitelist: () => addToSmallGroupWhitelist,
|
|
33
34
|
apply: () => apply,
|
|
34
35
|
clearBlacklistedGuilds: () => clearBlacklistedGuilds,
|
|
35
36
|
createBlacklistedGuild: () => createBlacklistedGuild,
|
|
36
37
|
getAllBlacklistedGuilds: () => getAllBlacklistedGuilds,
|
|
38
|
+
getAllSmallGroupWhitelist: () => getAllSmallGroupWhitelist,
|
|
37
39
|
getBlacklistedGuild: () => getBlacklistedGuild,
|
|
38
40
|
getCommandFrequencyRecord: () => getCommandFrequencyRecord,
|
|
39
41
|
getGroupBotStatus: () => getGroupBotStatus,
|
|
42
|
+
isInSmallGroupWhitelist: () => isInSmallGroupWhitelist,
|
|
40
43
|
name: () => name,
|
|
41
44
|
removeBlacklistedGuild: () => removeBlacklistedGuild,
|
|
45
|
+
removeFromSmallGroupWhitelist: () => removeFromSmallGroupWhitelist,
|
|
42
46
|
setGroupBotStatus: () => setGroupBotStatus,
|
|
43
47
|
updateCommandFrequencyRecord: () => updateCommandFrequencyRecord
|
|
44
48
|
});
|
|
@@ -64,6 +68,10 @@ function apply(ctx) {
|
|
|
64
68
|
guildId: "string",
|
|
65
69
|
botEnabled: "boolean"
|
|
66
70
|
}, { primary: ["platform", "guildId"] });
|
|
71
|
+
ctx.model.extend("small_group_whitelist", {
|
|
72
|
+
platform: "string",
|
|
73
|
+
guildId: "string"
|
|
74
|
+
}, { primary: ["platform", "guildId"] });
|
|
67
75
|
}
|
|
68
76
|
__name(apply, "apply");
|
|
69
77
|
var BLACKLIST_PLATFORM = "onebot";
|
|
@@ -114,6 +122,23 @@ async function setGroupBotStatus(ctx, platform, guildId, botEnabled) {
|
|
|
114
122
|
await ctx.model.upsert("group_bot_status", [{ platform, guildId, botEnabled }]);
|
|
115
123
|
}
|
|
116
124
|
__name(setGroupBotStatus, "setGroupBotStatus");
|
|
125
|
+
async function isInSmallGroupWhitelist(ctx, guildId) {
|
|
126
|
+
const records = await ctx.model.get("small_group_whitelist", { platform: BLACKLIST_PLATFORM, guildId });
|
|
127
|
+
return records.length > 0;
|
|
128
|
+
}
|
|
129
|
+
__name(isInSmallGroupWhitelist, "isInSmallGroupWhitelist");
|
|
130
|
+
async function addToSmallGroupWhitelist(ctx, guildId) {
|
|
131
|
+
await ctx.model.upsert("small_group_whitelist", [{ platform: BLACKLIST_PLATFORM, guildId }]);
|
|
132
|
+
}
|
|
133
|
+
__name(addToSmallGroupWhitelist, "addToSmallGroupWhitelist");
|
|
134
|
+
async function removeFromSmallGroupWhitelist(ctx, guildId) {
|
|
135
|
+
await ctx.model.remove("small_group_whitelist", { platform: BLACKLIST_PLATFORM, guildId });
|
|
136
|
+
}
|
|
137
|
+
__name(removeFromSmallGroupWhitelist, "removeFromSmallGroupWhitelist");
|
|
138
|
+
async function getAllSmallGroupWhitelist(ctx) {
|
|
139
|
+
return await ctx.model.get("small_group_whitelist", { platform: BLACKLIST_PLATFORM });
|
|
140
|
+
}
|
|
141
|
+
__name(getAllSmallGroupWhitelist, "getAllSmallGroupWhitelist");
|
|
117
142
|
|
|
118
143
|
// src/modules/basic.ts
|
|
119
144
|
var basic_exports = {};
|
|
@@ -208,7 +233,10 @@ var ADMIN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
208
233
|
"clear-blacklist",
|
|
209
234
|
"approve",
|
|
210
235
|
"reject",
|
|
211
|
-
"pending-invites"
|
|
236
|
+
"pending-invites",
|
|
237
|
+
"allow-small-group",
|
|
238
|
+
"disallow-small-group",
|
|
239
|
+
"view-small-group-whitelist"
|
|
212
240
|
]);
|
|
213
241
|
|
|
214
242
|
// src/state.ts
|
|
@@ -263,8 +291,10 @@ function apply2(ctx, config) {
|
|
|
263
291
|
}
|
|
264
292
|
}
|
|
265
293
|
if (config.basic.smallGroupAutoQuit) {
|
|
266
|
-
|
|
267
|
-
|
|
294
|
+
const inWhitelist = await isInSmallGroupWhitelist(ctx, guildId);
|
|
295
|
+
const wasApproved = approvedGroups.has(guildId);
|
|
296
|
+
if (wasApproved) approvedGroups.delete(guildId);
|
|
297
|
+
if (inWhitelist || wasApproved) {
|
|
268
298
|
} else {
|
|
269
299
|
const delay = config.basic.smallGroupCheckDelay || 3e3;
|
|
270
300
|
setTimeout(async () => {
|
|
@@ -684,6 +714,27 @@ function apply5(ctx, config) {
|
|
|
684
714
|
}
|
|
685
715
|
__name(clearBlacklist, "clearBlacklist");
|
|
686
716
|
ctx.command("clear-blacklist", "清空黑名单", { authority: 4 }).action(clearBlacklist);
|
|
717
|
+
ctx.command("allow-small-group <groupId:text>", "解除指定群聊的小群人数限制", { authority: 4 }).action(async ({}, input) => {
|
|
718
|
+
const guildId = parseGuildId(input);
|
|
719
|
+
if (!guildId) return "输入格式错误,请输入群号。";
|
|
720
|
+
const exists = await isInSmallGroupWhitelist(ctx, guildId);
|
|
721
|
+
if (exists) return `群聊 ${guildId} 已在小群白名单中。`;
|
|
722
|
+
await addToSmallGroupWhitelist(ctx, guildId);
|
|
723
|
+
return `已将群聊 ${guildId} 加入小群白名单,该群不再受小群人数限制。`;
|
|
724
|
+
});
|
|
725
|
+
ctx.command("disallow-small-group <groupId:text>", "恢复指定群聊的小群人数限制", { authority: 4 }).action(async ({}, input) => {
|
|
726
|
+
const guildId = parseGuildId(input);
|
|
727
|
+
if (!guildId) return "输入格式错误,请输入群号。";
|
|
728
|
+
const exists = await isInSmallGroupWhitelist(ctx, guildId);
|
|
729
|
+
if (!exists) return `群聊 ${guildId} 不在小群白名单中。`;
|
|
730
|
+
await removeFromSmallGroupWhitelist(ctx, guildId);
|
|
731
|
+
return `已将群聊 ${guildId} 从小群白名单移除,该群将恢复小群人数限制。`;
|
|
732
|
+
});
|
|
733
|
+
ctx.command("view-small-group-whitelist", "查看小群白名单", { authority: 4 }).action(async () => {
|
|
734
|
+
const records = await getAllSmallGroupWhitelist(ctx);
|
|
735
|
+
if (records.length === 0) return "小群白名单为空。";
|
|
736
|
+
return "小群白名单列表(以下群不受小群人数限制):\n" + records.map((r) => `- ${r.guildId}`).join("\n");
|
|
737
|
+
});
|
|
687
738
|
}
|
|
688
739
|
__name(apply5, "apply");
|
|
689
740
|
|
package/package.json
CHANGED