koishi-plugin-group-command-blocker 0.0.1 → 0.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/lib/index.d.ts +8 -1
- package/lib/index.js +62 -54
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
2
|
export declare const name = "group-command-blocker";
|
|
3
3
|
export interface Config {
|
|
4
|
+
admins: string[];
|
|
4
5
|
}
|
|
5
6
|
export declare const Config: Schema<Config>;
|
|
6
7
|
declare module 'koishi' {
|
|
7
8
|
interface Tables {
|
|
8
9
|
group_disabled_plugins: GroupDisabledPlugin;
|
|
10
|
+
group_disabled_commands: GroupDisabledCommand;
|
|
9
11
|
group_blocked_users: GroupBlockedUser;
|
|
10
12
|
}
|
|
11
13
|
}
|
|
@@ -14,9 +16,14 @@ export interface GroupDisabledPlugin {
|
|
|
14
16
|
guildId: string;
|
|
15
17
|
pluginName: string;
|
|
16
18
|
}
|
|
19
|
+
export interface GroupDisabledCommand {
|
|
20
|
+
id: number;
|
|
21
|
+
guildId: string;
|
|
22
|
+
commandName: string;
|
|
23
|
+
}
|
|
17
24
|
export interface GroupBlockedUser {
|
|
18
25
|
id: number;
|
|
19
26
|
guildId: string;
|
|
20
27
|
userId: string;
|
|
21
28
|
}
|
|
22
|
-
export declare function apply(ctx: Context): void;
|
|
29
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -27,61 +27,60 @@ __export(src_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
28
|
var import_koishi = require("koishi");
|
|
29
29
|
var name = "group-command-blocker";
|
|
30
|
-
var Config = import_koishi.Schema.object({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, { primary: "id", autoInc: true });
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!session?.guildId || !name2) return "
|
|
44
|
-
const [record] = await ctx.database.get("group_disabled_plugins", {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
return
|
|
30
|
+
var Config = import_koishi.Schema.object({
|
|
31
|
+
admins: import_koishi.Schema.array(import_koishi.Schema.string()).description("允许执行管理指令的用户 ID 列表 (例如 QQ 号)")
|
|
32
|
+
});
|
|
33
|
+
function apply(ctx, config) {
|
|
34
|
+
ctx.model.extend("group_disabled_plugins", { id: "unsigned", guildId: "string", pluginName: "string" }, { primary: "id", autoInc: true });
|
|
35
|
+
ctx.model.extend("group_disabled_commands", { id: "unsigned", guildId: "string", commandName: "string" }, { primary: "id", autoInc: true });
|
|
36
|
+
ctx.model.extend("group_blocked_users", { id: "unsigned", guildId: "string", userId: "string" }, { primary: "id", autoInc: true });
|
|
37
|
+
const isAuthorized = /* @__PURE__ */ __name((session) => {
|
|
38
|
+
if (!config.admins || config.admins.length === 0) return true;
|
|
39
|
+
return config.admins.includes(session.userId);
|
|
40
|
+
}, "isAuthorized");
|
|
41
|
+
ctx.command("plugin.disable <name:string>", "在本群禁用指定插件").action(async ({ session }, name2) => {
|
|
42
|
+
if (!isAuthorized(session)) return "你没有权限执行这个操作";
|
|
43
|
+
if (!session?.guildId || !name2) return "参数不对";
|
|
44
|
+
const [record] = await ctx.database.get("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
|
|
45
|
+
if (record) return "该插件早已被禁用";
|
|
46
|
+
await ctx.database.create("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
|
|
47
|
+
return `设置成功,已禁用插件: ${name2}`;
|
|
48
|
+
});
|
|
49
|
+
ctx.command("plugin.enable <name:string>", "在本群恢复指定插件").action(async ({ session }, name2) => {
|
|
50
|
+
if (!isAuthorized(session)) return "你没有权限执行这个操作";
|
|
51
|
+
if (!session?.guildId) return "";
|
|
52
|
+
await ctx.database.remove("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
|
|
53
|
+
return `设置成功,已恢复插件: ${name2}`;
|
|
54
54
|
});
|
|
55
|
-
ctx.command("
|
|
55
|
+
ctx.command("cmd.disable <name:string>", "在本群禁用指定指令").action(async ({ session }, name2) => {
|
|
56
|
+
if (!isAuthorized(session)) return "你没有权限执行这个操作";
|
|
56
57
|
if (!session?.guildId || !name2) return "参数不对";
|
|
57
|
-
await ctx.database.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
return `设置成功,已在此群恢复插件: ${name2}`;
|
|
58
|
+
const [record] = await ctx.database.get("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
|
|
59
|
+
if (record) return "该指令早就在黑名单里了";
|
|
60
|
+
await ctx.database.create("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
|
|
61
|
+
return `设置成功,已禁用指令: ${name2}`;
|
|
62
62
|
});
|
|
63
|
-
ctx.command("
|
|
64
|
-
if (!session
|
|
63
|
+
ctx.command("cmd.enable <name:string>", "在本群恢复指定指令").action(async ({ session }, name2) => {
|
|
64
|
+
if (!isAuthorized(session)) return "你没有权限执行这个操作";
|
|
65
|
+
if (!session?.guildId) return "";
|
|
66
|
+
await ctx.database.remove("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
|
|
67
|
+
return `设置成功,已恢复指令: ${name2}`;
|
|
68
|
+
});
|
|
69
|
+
ctx.command("block.user <target:user>", "在本群屏蔽特定用户").action(async ({ session }, target) => {
|
|
70
|
+
if (!isAuthorized(session)) return "你没有权限执行这个操作";
|
|
71
|
+
if (!session?.guildId || !target) return "你得指定一个用户";
|
|
65
72
|
const userId = import_koishi.h.parse(target)[0]?.attrs?.id || target;
|
|
66
|
-
const [record] = await ctx.database.get("group_blocked_users", {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
if (record) return "这人已经在黑名单里了";
|
|
71
|
-
await ctx.database.create("group_blocked_users", {
|
|
72
|
-
guildId: session.guildId,
|
|
73
|
-
userId
|
|
74
|
-
});
|
|
75
|
-
return `已成功屏蔽用户: ${userId}`;
|
|
73
|
+
const [record] = await ctx.database.get("group_blocked_users", { guildId: session.guildId, userId });
|
|
74
|
+
if (record) return "这人已经在黑名单里呆着了";
|
|
75
|
+
await ctx.database.create("group_blocked_users", { guildId: session.guildId, userId });
|
|
76
|
+
return `设置成功,已屏蔽用户: ${userId}`;
|
|
76
77
|
});
|
|
77
|
-
ctx.command("unblock.user <target:user>", "
|
|
78
|
-
if (!session
|
|
78
|
+
ctx.command("unblock.user <target:user>", "在本群取消屏蔽用户").action(async ({ session }, target) => {
|
|
79
|
+
if (!isAuthorized(session)) return "你没有权限执行这个操作";
|
|
80
|
+
if (!session?.guildId) return "";
|
|
79
81
|
const userId = import_koishi.h.parse(target)[0]?.attrs?.id || target;
|
|
80
|
-
await ctx.database.remove("group_blocked_users", {
|
|
81
|
-
|
|
82
|
-
userId
|
|
83
|
-
});
|
|
84
|
-
return `已解除对用户 ${userId} 的屏蔽`;
|
|
82
|
+
await ctx.database.remove("group_blocked_users", { guildId: session.guildId, userId });
|
|
83
|
+
return `设置成功,已解除对用户 ${userId} 的屏蔽`;
|
|
85
84
|
});
|
|
86
85
|
ctx.middleware(async (session, next) => {
|
|
87
86
|
if (!session?.guildId || !session?.userId || session.userId === session.selfId) return next();
|
|
@@ -91,15 +90,24 @@ function apply(ctx) {
|
|
|
91
90
|
});
|
|
92
91
|
if (blocked) return;
|
|
93
92
|
return next();
|
|
94
|
-
});
|
|
93
|
+
}, true);
|
|
95
94
|
ctx.on("command/before-execute", async ({ command, session }) => {
|
|
95
|
+
if (!command || !session?.guildId) return;
|
|
96
96
|
const pluginName = command?.plugin?.name;
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
const cmdName = command.name;
|
|
98
|
+
if (pluginName === "group-command-blocker") return;
|
|
99
|
+
const [disabledCmd] = await ctx.database.get("group_disabled_commands", {
|
|
99
100
|
guildId: session.guildId,
|
|
100
|
-
|
|
101
|
+
commandName: cmdName
|
|
101
102
|
});
|
|
102
|
-
if (
|
|
103
|
+
if (disabledCmd) return "";
|
|
104
|
+
if (pluginName) {
|
|
105
|
+
const [disabledPlg] = await ctx.database.get("group_disabled_plugins", {
|
|
106
|
+
guildId: session.guildId,
|
|
107
|
+
pluginName
|
|
108
|
+
});
|
|
109
|
+
if (disabledPlg) return "";
|
|
110
|
+
}
|
|
103
111
|
});
|
|
104
112
|
}
|
|
105
113
|
__name(apply, "apply");
|