koishi-plugin-group-command-blocker 0.0.1 → 0.0.2

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 CHANGED
@@ -6,6 +6,7 @@ export declare const Config: Schema<Config>;
6
6
  declare module 'koishi' {
7
7
  interface Tables {
8
8
  group_disabled_plugins: GroupDisabledPlugin;
9
+ group_disabled_commands: GroupDisabledCommand;
9
10
  group_blocked_users: GroupBlockedUser;
10
11
  }
11
12
  }
@@ -14,6 +15,11 @@ export interface GroupDisabledPlugin {
14
15
  guildId: string;
15
16
  pluginName: string;
16
17
  }
18
+ export interface GroupDisabledCommand {
19
+ id: number;
20
+ guildId: string;
21
+ commandName: string;
22
+ }
17
23
  export interface GroupBlockedUser {
18
24
  id: number;
19
25
  guildId: string;
package/lib/index.js CHANGED
@@ -29,77 +29,68 @@ var import_koishi = require("koishi");
29
29
  var name = "group-command-blocker";
30
30
  var Config = import_koishi.Schema.object({});
31
31
  function apply(ctx) {
32
- ctx.model.extend("group_disabled_plugins", {
33
- id: "unsigned",
34
- guildId: "string",
35
- pluginName: "string"
36
- }, { primary: "id", autoInc: true });
37
- ctx.model.extend("group_blocked_users", {
38
- id: "unsigned",
39
- guildId: "string",
40
- userId: "string"
41
- }, { primary: "id", autoInc: true });
42
- ctx.command("plugin.disable <name:string>", "在本群禁用指定插件的指令").action(async ({ session }, name2) => {
43
- if (!session?.guildId || !name2) return "参数不对,得在群里用并指定插件名";
44
- const [record] = await ctx.database.get("group_disabled_plugins", {
45
- guildId: session.guildId,
46
- pluginName: name2
47
- });
48
- if (record) return "这个插件早就在禁用名单里了";
49
- await ctx.database.create("group_disabled_plugins", {
50
- guildId: session.guildId,
51
- pluginName: name2
52
- });
53
- return `设置成功,已在此群禁用插件: ${name2}`;
32
+ ctx.model.extend("group_disabled_plugins", { id: "unsigned", guildId: "string", pluginName: "string" }, { primary: "id", autoInc: true });
33
+ ctx.model.extend("group_disabled_commands", { id: "unsigned", guildId: "string", commandName: "string" }, { primary: "id", autoInc: true });
34
+ ctx.model.extend("group_blocked_users", { id: "unsigned", guildId: "string", userId: "string" }, { primary: "id", autoInc: true });
35
+ ctx.command("plugin.disable <name:string>", "在本群禁用指定插件").action(async ({ session }, name2) => {
36
+ if (!session?.guildId || !name2) return "缺少参数";
37
+ const [record] = await ctx.database.get("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
38
+ if (record) return "该插件已在禁用名单";
39
+ await ctx.database.create("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
40
+ return `已禁用插件: ${name2}`;
54
41
  });
55
- ctx.command("plugin.enable <name:string>", "在本群启用指定插件的指令").action(async ({ session }, name2) => {
56
- if (!session?.guildId || !name2) return "参数不对";
57
- await ctx.database.remove("group_disabled_plugins", {
58
- guildId: session.guildId,
59
- pluginName: name2
60
- });
61
- return `设置成功,已在此群恢复插件: ${name2}`;
42
+ ctx.command("plugin.enable <name:string>", "在本群启用指定插件").action(async ({ session }, name2) => {
43
+ if (!session?.guildId) return "";
44
+ await ctx.database.remove("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
45
+ return `已恢复插件: ${name2}`;
46
+ });
47
+ ctx.command("cmd.disable <name:string>", "在本群禁用指定指令(如 jrrp)").action(async ({ session }, name2) => {
48
+ if (!session?.guildId || !name2) return "缺少参数";
49
+ const [record] = await ctx.database.get("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
50
+ if (record) return "该指令已在禁用名单";
51
+ await ctx.database.create("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
52
+ return `已禁用指令: ${name2}`;
53
+ });
54
+ ctx.command("cmd.enable <name:string>", "在本群恢复指定指令").action(async ({ session }, name2) => {
55
+ if (!session?.guildId) return "";
56
+ await ctx.database.remove("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
57
+ return `已恢复指令: ${name2}`;
62
58
  });
63
- ctx.command("block.user <target:user>", "屏蔽指定群员的消息").action(async ({ session }, target) => {
64
- if (!session?.guildId || !target) return "请指定要屏蔽的人";
59
+ ctx.command("block.user <target:user>", "在本群屏蔽特定用户消息").action(async ({ session }, target) => {
60
+ if (!session?.guildId || !target) return "请指定用户";
65
61
  const userId = import_koishi.h.parse(target)[0]?.attrs?.id || target;
66
- const [record] = await ctx.database.get("group_blocked_users", {
67
- guildId: session.guildId,
68
- userId
69
- });
70
- if (record) return "这人已经在黑名单里了";
71
- await ctx.database.create("group_blocked_users", {
72
- guildId: session.guildId,
73
- userId
74
- });
75
- return `已成功屏蔽用户: ${userId}`;
62
+ await ctx.database.create("group_blocked_users", { guildId: session.guildId, userId });
63
+ return `已屏蔽用户: ${userId}`;
76
64
  });
77
- ctx.command("unblock.user <target:user>", "取消屏蔽指定群员").action(async ({ session }, target) => {
78
- if (!session?.guildId || !target) return "请指定要解封的人";
65
+ ctx.command("unblock.user <target:user>", "在本群解除用户屏蔽").action(async ({ session }, target) => {
66
+ if (!session?.guildId) return "";
79
67
  const userId = import_koishi.h.parse(target)[0]?.attrs?.id || target;
80
- await ctx.database.remove("group_blocked_users", {
81
- guildId: session.guildId,
82
- userId
83
- });
84
- return `已解除对用户 ${userId} 的屏蔽`;
68
+ await ctx.database.remove("group_blocked_users", { guildId: session.guildId, userId });
69
+ return `已解除屏蔽`;
85
70
  });
86
71
  ctx.middleware(async (session, next) => {
87
72
  if (!session?.guildId || !session?.userId || session.userId === session.selfId) return next();
88
- const [blocked] = await ctx.database.get("group_blocked_users", {
89
- guildId: session.guildId,
90
- userId: session.userId
91
- });
73
+ const [blocked] = await ctx.database.get("group_blocked_users", { guildId: session.guildId, userId: session.userId });
92
74
  if (blocked) return;
93
75
  return next();
94
76
  });
95
77
  ctx.on("command/before-execute", async ({ command, session }) => {
78
+ if (!command || !session?.guildId) return;
96
79
  const pluginName = command?.plugin?.name;
97
- if (!session?.guildId || !pluginName || pluginName === "group-command-blocker") return;
98
- const [disabled] = await ctx.database.get("group_disabled_plugins", {
80
+ const cmdName = command.name;
81
+ if (pluginName === "group-command-blocker") return;
82
+ const [disabledCmd] = await ctx.database.get("group_disabled_commands", {
99
83
  guildId: session.guildId,
100
- pluginName
84
+ commandName: cmdName
101
85
  });
102
- if (disabled) return "";
86
+ if (disabledCmd) return "";
87
+ if (pluginName) {
88
+ const [disabledPlg] = await ctx.database.get("group_disabled_plugins", {
89
+ guildId: session.guildId,
90
+ pluginName
91
+ });
92
+ if (disabledPlg) return "";
93
+ }
103
94
  });
104
95
  }
105
96
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-group-command-blocker",
3
3
  "description": "这个东西也可以用来屏蔽群员",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [