koishi-plugin-group-control 1.0.4 → 1.1.0-alpha.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-group-control",
3
3
  "description": "Koishi 插件,一个多功能的群聊自管理工具。支持被踢出自动拉黑、刷屏自动屏蔽、开关控制等功能。(仅支持 OneBot 适配器)",
4
- "version": "1.0.4",
4
+ "version": "1.1.0-alpha.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -4,20 +4,22 @@
4
4
 
5
5
  Koishi 插件,多功能群聊自管理工具。仅支持 OneBot 适配器。
6
6
 
7
- > 使用 Qwen3-Coder & Gemini-3.1-Pro-Preview & Claude Sonnet/Opus 4.6 协助完成
7
+ > 使用 AI Agent 协助完成
8
8
 
9
9
  ---
10
10
 
11
11
  ## 功能概览
12
12
 
13
13
  - **黑名单管理**:被踢出群后自动拉黑,下次被邀请时自动退出
14
- - **小群自动退群**:加入人数不足的群时自动退出并通知管理员
14
+ - **小群自动退群**:加入人数不足的群时自动退出并通知管理员,统计人数时自动排除 QQ 官方机器人(仅计真人)
15
+ - **实时小群监控**:监听成员退群事件,群缩水到阈值以下时自动退出(仅针对未经审核拉入的群)
15
16
  - **合格小群通知**:未经审核被拉入人数达标的群时,通知管理员确认
16
17
  - **群聊邀请审核**:收到邀请时暂缓加入,等待管理员审核
17
18
  - **好友申请管理**:收到好友申请时通知管理员,或自动通过
18
19
  - **频率控制**:限制群聊/私聊的指令及对话频率,支持指数增长屏蔽时长
19
20
  - **Bot 开关**:按群独立开关 bot,关闭后屏蔽所有响应
20
- - **被禁言通知**:bot 被禁言时可选通知管理员
21
+ - **好友/群管理**:指令列出好友(合并转发)、删除好友、列出所在群、远程退出指定群
22
+ - **被禁言通知**:bot 被禁言时可选通知管理员;被禁言时长达到阈值时可自动退群并拉黑
21
23
  - **权限管理**:支持 Koishi authority 或内置群管理员两种权限模式
22
24
 
23
25
  ---
@@ -69,6 +71,9 @@ Koishi 插件,多功能群聊自管理工具。仅支持 OneBot 适配器。
69
71
  |--------|--------|------|
70
72
  | `smallGroupAutoQuit` | `false` | 启用小群自动退群 |
71
73
  | `smallGroupThreshold` | `30` | 人数阈值,低于等于此值时自动退出 |
74
+ | `smallGroupExcludeOfficialBots` | `true` | 统计群人数时排除 QQ 官方机器人(`is_robot`)及机器人自身,仅统计真人成员 |
75
+ | `smallGroupRealtimeMonitor` | `true` | 实时监控群人数:监听成员退群事件,群缩小到阈值以下时自动退群(仅监控未经审核拉入的群) |
76
+ | `smallGroupRecheckCooldown` | `60` | 实时监控时同一群两次复检的最小间隔(秒),避免成员批量退群时频繁调用接口 |
72
77
  | `smallGroupQuitMessage` | *(见配置)* | 退群提示,支持 `{memberCount}`, `{threshold}`, `{groupName}`, `{groupId}` |
73
78
  | `smallGroupNotifyAdmin` | `true` | 自动退群时通知管理员 |
74
79
  | `smallGroupCheckDelay` | `3000` | 加入后延迟检测的时间(毫秒) |
@@ -86,6 +91,9 @@ Koishi 插件,多功能群聊自管理工具。仅支持 OneBot 适配器。
86
91
  |--------|--------|------|
87
92
  | `notifyAdminOnMute` | `false` | bot 被禁言时通知管理员 |
88
93
  | `muteNotificationMessage` | *(见配置)* | 通知消息模板,支持 `{groupId}`, `{groupName}`, `{operatorId}`, `{duration}` |
94
+ | `muteAutoQuit` | `false` | bot 被禁言达到阈值时自动退群并拉黑 |
95
+ | `muteAutoQuitThreshold` | `600` | 触发自动退群的禁言时长阈值(秒),被禁言时长 ≥ 此值即退群并拉黑 |
96
+ | `muteQuitNotificationMessage` | *(见配置)* | 自动退群时发给管理员的通知模板,支持 `{groupId}`, `{groupName}`, `{operatorId}`, `{duration}` |
89
97
 
90
98
  ### 频率控制
91
99
 
@@ -174,12 +182,16 @@ Koishi 插件,多功能群聊自管理工具。仅支持 OneBot 适配器。
174
182
  | `gc.sg-add <群号>` | 将群加入小群白名单,不受人数限制 |
175
183
  | `gc.sg-rm <群号>` | 从小群白名单移除群 |
176
184
  | `gc.sg-list` | 查看小群白名单 |
185
+ | `gc.friends` | 列出机器人的好友(合并转发形式发送) |
186
+ | `gc.delfriend <QQ号>` | 删除指定好友 |
187
+ | `gc.groups` | 列出机器人所在的群(合并转发形式发送) |
188
+ | `gc.leave <群号>` | 让机器人退出指定群 |
177
189
  | `gc.approve <群号>` | 同意加入指定群 |
178
190
  | `gc.reject <群号>` | 拒绝加入指定群 |
179
191
  | `gc.pending` | 查看待处理的群聊邀请列表 |
180
- | `gc.fa <QQ号>` | 同意好友申请 |
181
- | `gc.fr <QQ号>` | 拒绝好友申请 |
182
- | `gc.fp` | 查看待处理的好友申请列表 |
192
+ | `gc.friend-approve <QQ号>` | 同意好友申请(兼容别名:`gc.fa`) |
193
+ | `gc.friend-reject <QQ号>` | 拒绝好友申请(兼容别名:`gc.fr`) |
194
+ | `gc.friend-pending` | 查看待处理的好友申请列表(兼容别名:`gc.fp`) |
183
195
 
184
196
  ### 群聊管理
185
197
 
@@ -197,3 +209,5 @@ Koishi 插件,多功能群聊自管理工具。仅支持 OneBot 适配器。
197
209
  - 管理员通知依赖 `admin.adminQQs` 或 `admin.notificationGroupId` 的配置,未配置则无法收到通知
198
210
  - 频率控制的非指令拦截(@ 对话、私聊)不影响入群欢迎等系统事件
199
211
  - 小群合格通知仅在启用了 `smallGroupAutoQuit` 且未经 `gc.approve` 审核通过的情况下触发
212
+ - **小群人数统计**:开启 `smallGroupExcludeOfficialBots` 后只计真人成员(排除 `is_robot` 机器人与自身)。检测做了分级短路以减少接口调用——原始人数 ≤ 阈值直接退群、原始人数 > 阈值 + 20(单群机器人上限)直接保留,仅当人数处于中间区间时才拉取一次成员列表,且统计到足够机器人即提前结束遍历
213
+ - **实时小群监控**:纯事件驱动(仅监听成员退群),不做轮询,配合 per-群冷却限流,几乎不增加接口压力。**经 `gc.approve` 审核通过或在小群白名单中的群永久豁免**,仅监控未经审核被拉入的群;机器人退出某群后其审核标记自动清除,若日后被未经审核地重新拉入会重新接受检测
package/lib/config.d.ts DELETED
@@ -1,82 +0,0 @@
1
- import { Schema } from 'koishi';
2
- export interface GroupConfig {
3
- welcomeMessage: string;
4
- quitMessage: string;
5
- quitCommandEnabled: boolean;
6
- enableBlacklist: boolean;
7
- blacklistMessage: string;
8
- notifyAdminOnKick: boolean;
9
- kickNotificationMessage: string;
10
- smallGroupAutoQuit: boolean;
11
- smallGroupThreshold: number;
12
- smallGroupQuitMessage: string;
13
- smallGroupNotifyAdmin: boolean;
14
- smallGroupCheckDelay: number;
15
- smallGroupQualifiedNotifyAdmin: boolean;
16
- smallGroupQualifiedMessage: string;
17
- notifyAdminOnMute: boolean;
18
- muteNotificationMessage: string;
19
- }
20
- export interface AdminConfig {
21
- adminQQs: string[];
22
- notificationGroupId: string;
23
- }
24
- export interface GroupInviteConfig {
25
- enabled: boolean;
26
- inviteWaitMessage: string;
27
- inviteRequestMessage: string;
28
- autoApprove: boolean;
29
- notifyAdminOnApprove: boolean;
30
- inviteApproveMessage: string;
31
- inviteApproveNotificationMessage: string;
32
- showDetailedLog: boolean;
33
- inviteExpireDays: number;
34
- }
35
- export interface FrequencyConfig {
36
- enabled: boolean;
37
- limit: number;
38
- window: number;
39
- warnDelay: number;
40
- blockDur: number;
41
- whitelist: string[];
42
- privateEnabled: boolean;
43
- privateLimit: number;
44
- privateWindow: number;
45
- privateWarnDelay: number;
46
- privateBlockDur: number;
47
- privateWhitelist: string[];
48
- blockExpBase: number;
49
- blockExpWindow: number;
50
- blockNotifyCooldown: number;
51
- warnMsg: string;
52
- blockMsg: string;
53
- blockedMsg: string;
54
- }
55
- export interface FriendConfig {
56
- enabled: boolean;
57
- autoApprove: boolean;
58
- notifyAdminOnApprove: boolean;
59
- requestExpireDays: number;
60
- requestMessage: string;
61
- approveNotificationMessage: string;
62
- }
63
- export interface BotSwitchConfig {
64
- enabled: boolean;
65
- defaultState: boolean;
66
- disabledMessage: string;
67
- }
68
- export interface PermissionConfig {
69
- mode: 'koishi' | 'builtin';
70
- koishiAuthority: number;
71
- protectedCommands: string[];
72
- }
73
- export interface Config {
74
- admin: AdminConfig;
75
- permission: PermissionConfig;
76
- basic: GroupConfig;
77
- invite: GroupInviteConfig;
78
- friend: FriendConfig;
79
- frequency: FrequencyConfig;
80
- botSwitch: BotSwitchConfig;
81
- }
82
- export declare const Config: Schema<Config>;
package/lib/database.d.ts DELETED
@@ -1,96 +0,0 @@
1
- import { Context } from 'koishi';
2
- export interface BlacklistedGuild {
3
- platform: string;
4
- guildId: string;
5
- timestamp: number;
6
- reason: string;
7
- }
8
- export interface CommandFrequencyRecord {
9
- platform: string;
10
- guildId: string;
11
- commandCount: number;
12
- lastCommandTime: number;
13
- warningSent: boolean;
14
- blockExpiryTime: number;
15
- firstWarningTime: number;
16
- blockCount: number;
17
- lastBlockNotifyTime: number;
18
- }
19
- export interface GroupBotStatus {
20
- platform: string;
21
- guildId: string;
22
- botEnabled: boolean;
23
- }
24
- export interface SmallGroupWhitelist {
25
- platform: string;
26
- guildId: string;
27
- }
28
- export interface SelfLeftGuild {
29
- platform: string;
30
- guildId: string;
31
- timestamp: number;
32
- }
33
- export interface PendingInvite {
34
- platform: string;
35
- groupId: string;
36
- userId: string;
37
- userName: string;
38
- groupName: string;
39
- time: number;
40
- flag: string;
41
- }
42
- export interface PendingFriendRequest {
43
- platform: string;
44
- userId: string;
45
- nickname: string;
46
- comment: string;
47
- flag: string;
48
- time: number;
49
- }
50
- declare module 'koishi' {
51
- interface Tables {
52
- blacklisted_guild: BlacklistedGuild;
53
- command_frequency_record: CommandFrequencyRecord;
54
- group_bot_status: GroupBotStatus;
55
- small_group_whitelist: SmallGroupWhitelist;
56
- self_left_guild: SelfLeftGuild;
57
- pending_invite: PendingInvite;
58
- pending_friend_request: PendingFriendRequest;
59
- }
60
- }
61
- export declare const name = "group-control-database";
62
- export declare function apply(ctx: Context): void;
63
- export declare const BLACKLIST_PLATFORM = "onebot";
64
- export declare function getBlacklistedGuild(ctx: Context, guildId: string): Promise<BlacklistedGuild[]>;
65
- export declare function removeBlacklistedGuild(ctx: Context, guildId: string): Promise<import("minato").Driver.WriteResult>;
66
- export declare function createBlacklistedGuild(ctx: Context, guildId: string, reason: string): Promise<import("minato").Driver.WriteResult>;
67
- export declare function getAllBlacklistedGuilds(ctx: Context): Promise<BlacklistedGuild[]>;
68
- export declare function clearBlacklistedGuilds(ctx: Context): Promise<import("minato").Driver.WriteResult>;
69
- /** 统一写入被踢黑名单行,保证 platform = BLACKLIST_PLATFORM */
70
- export declare function blacklistKicked(ctx: Context, guildId: string): Promise<import("minato").Driver.WriteResult>;
71
- /** 在主动退群前写入标记,让 guild-removed 能区分「自己退的」和「被踢的」*/
72
- export declare function markSelfLeft(ctx: Context, guildId: string): Promise<void>;
73
- /** 消费标记(单次读取后删除),返回是否在 maxAgeSec 内。用于 guild-removed 判断是自己退的 */
74
- export declare function consumeSelfLeft(ctx: Context, guildId: string, maxAgeSec?: number): Promise<boolean>;
75
- /** 清理标记(退群失败时回滚,或 unban 时清理)*/
76
- export declare function clearSelfLeft(ctx: Context, guildId: string): Promise<void>;
77
- /** 定期清理过期的主动退群标记(超过 maxAgeSec 秒未消费的)*/
78
- export declare function clearExpiredSelfLeft(ctx: Context, maxAgeSec?: number): Promise<number>;
79
- export declare function getCommandFrequencyRecord(ctx: Context, platform: string, guildId: string): Promise<CommandFrequencyRecord>;
80
- export declare function updateCommandFrequencyRecord(ctx: Context, platform: string, guildId: string, data: Partial<CommandFrequencyRecord>): Promise<void>;
81
- export declare function getGroupBotStatus(ctx: Context, platform: string, guildId: string): Promise<GroupBotStatus | null>;
82
- export declare function setGroupBotStatus(ctx: Context, platform: string, guildId: string, botEnabled: boolean): Promise<void>;
83
- export declare function isInSmallGroupWhitelist(ctx: Context, guildId: string): Promise<boolean>;
84
- export declare function addToSmallGroupWhitelist(ctx: Context, guildId: string): Promise<void>;
85
- export declare function removeFromSmallGroupWhitelist(ctx: Context, guildId: string): Promise<void>;
86
- export declare function getAllSmallGroupWhitelist(ctx: Context): Promise<SmallGroupWhitelist[]>;
87
- export declare function getPendingInvite(ctx: Context, groupId: string): Promise<PendingInvite>;
88
- export declare function addPendingInvite(ctx: Context, inviteUser: Omit<PendingInvite, 'platform'>): Promise<void>;
89
- export declare function removePendingInvite(ctx: Context, groupId: string): Promise<void>;
90
- export declare function getAllPendingInvites(ctx: Context): Promise<PendingInvite[]>;
91
- export declare function clearExpiredPendingInvites(ctx: Context, expireTimeMs: number): Promise<number>;
92
- export declare function getPendingFriendRequest(ctx: Context, platform: string, userId: string): Promise<PendingFriendRequest>;
93
- export declare function addPendingFriendRequest(ctx: Context, platform: string, data: Omit<PendingFriendRequest, 'platform'>): Promise<void>;
94
- export declare function removePendingFriendRequest(ctx: Context, platform: string, userId: string): Promise<void>;
95
- export declare function getAllPendingFriendRequests(ctx: Context, platform: string): Promise<PendingFriendRequest[]>;
96
- export declare function clearExpiredPendingFriendRequests(ctx: Context, platform: string, expireTimeMs: number): Promise<number>;
package/lib/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Context } from 'koishi';
2
- import { Config } from './config';
3
- export * from './config';
4
- export declare const name = "group-control";
5
- export declare function apply(ctx: Context, config: Config): void;