koishi-plugin-group-command-blocker 0.0.2 → 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 CHANGED
@@ -1,6 +1,7 @@
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' {
@@ -25,4 +26,4 @@ export interface GroupBlockedUser {
25
26
  guildId: string;
26
27
  userId: string;
27
28
  }
28
- export declare function apply(ctx: Context): void;
29
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -27,53 +27,70 @@ __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
- function apply(ctx) {
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) {
32
34
  ctx.model.extend("group_disabled_plugins", { id: "unsigned", guildId: "string", pluginName: "string" }, { primary: "id", autoInc: true });
33
35
  ctx.model.extend("group_disabled_commands", { id: "unsigned", guildId: "string", commandName: "string" }, { primary: "id", autoInc: true });
34
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");
35
41
  ctx.command("plugin.disable <name:string>", "在本群禁用指定插件").action(async ({ session }, name2) => {
36
- if (!session?.guildId || !name2) return "缺少参数";
42
+ if (!isAuthorized(session)) return "你没有权限执行这个操作";
43
+ if (!session?.guildId || !name2) return "参数不对";
37
44
  const [record] = await ctx.database.get("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
38
- if (record) return "该插件已在禁用名单";
45
+ if (record) return "该插件早已被禁用";
39
46
  await ctx.database.create("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
40
- return `已禁用插件: ${name2}`;
47
+ return `设置成功,已禁用插件: ${name2}`;
41
48
  });
42
- ctx.command("plugin.enable <name:string>", "在本群启用指定插件").action(async ({ session }, name2) => {
49
+ ctx.command("plugin.enable <name:string>", "在本群恢复指定插件").action(async ({ session }, name2) => {
50
+ if (!isAuthorized(session)) return "你没有权限执行这个操作";
43
51
  if (!session?.guildId) return "";
44
52
  await ctx.database.remove("group_disabled_plugins", { guildId: session.guildId, pluginName: name2 });
45
- return `已恢复插件: ${name2}`;
53
+ return `设置成功,已恢复插件: ${name2}`;
46
54
  });
47
- ctx.command("cmd.disable <name:string>", "在本群禁用指定指令(如 jrrp)").action(async ({ session }, name2) => {
48
- if (!session?.guildId || !name2) return "缺少参数";
55
+ ctx.command("cmd.disable <name:string>", "在本群禁用指定指令").action(async ({ session }, name2) => {
56
+ if (!isAuthorized(session)) return "你没有权限执行这个操作";
57
+ if (!session?.guildId || !name2) return "参数不对";
49
58
  const [record] = await ctx.database.get("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
50
- if (record) return "该指令已在禁用名单";
59
+ if (record) return "该指令早就在黑名单里了";
51
60
  await ctx.database.create("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
52
- return `已禁用指令: ${name2}`;
61
+ return `设置成功,已禁用指令: ${name2}`;
53
62
  });
54
63
  ctx.command("cmd.enable <name:string>", "在本群恢复指定指令").action(async ({ session }, name2) => {
64
+ if (!isAuthorized(session)) return "你没有权限执行这个操作";
55
65
  if (!session?.guildId) return "";
56
66
  await ctx.database.remove("group_disabled_commands", { guildId: session.guildId, commandName: name2 });
57
- return `已恢复指令: ${name2}`;
67
+ return `设置成功,已恢复指令: ${name2}`;
58
68
  });
59
- ctx.command("block.user <target:user>", "在本群屏蔽特定用户消息").action(async ({ session }, target) => {
60
- if (!session?.guildId || !target) return "请指定用户";
69
+ ctx.command("block.user <target:user>", "在本群屏蔽特定用户").action(async ({ session }, target) => {
70
+ if (!isAuthorized(session)) return "你没有权限执行这个操作";
71
+ if (!session?.guildId || !target) return "你得指定一个用户";
61
72
  const userId = import_koishi.h.parse(target)[0]?.attrs?.id || target;
73
+ const [record] = await ctx.database.get("group_blocked_users", { guildId: session.guildId, userId });
74
+ if (record) return "这人已经在黑名单里呆着了";
62
75
  await ctx.database.create("group_blocked_users", { guildId: session.guildId, userId });
63
- return `已屏蔽用户: ${userId}`;
76
+ return `设置成功,已屏蔽用户: ${userId}`;
64
77
  });
65
- ctx.command("unblock.user <target:user>", "在本群解除用户屏蔽").action(async ({ session }, target) => {
78
+ ctx.command("unblock.user <target:user>", "在本群取消屏蔽用户").action(async ({ session }, target) => {
79
+ if (!isAuthorized(session)) return "你没有权限执行这个操作";
66
80
  if (!session?.guildId) return "";
67
81
  const userId = import_koishi.h.parse(target)[0]?.attrs?.id || target;
68
82
  await ctx.database.remove("group_blocked_users", { guildId: session.guildId, userId });
69
- return `已解除屏蔽`;
83
+ return `设置成功,已解除对用户 ${userId} 的屏蔽`;
70
84
  });
71
85
  ctx.middleware(async (session, next) => {
72
86
  if (!session?.guildId || !session?.userId || session.userId === session.selfId) return next();
73
- const [blocked] = await ctx.database.get("group_blocked_users", { guildId: session.guildId, userId: session.userId });
87
+ const [blocked] = await ctx.database.get("group_blocked_users", {
88
+ guildId: session.guildId,
89
+ userId: session.userId
90
+ });
74
91
  if (blocked) return;
75
92
  return next();
76
- });
93
+ }, true);
77
94
  ctx.on("command/before-execute", async ({ command, session }) => {
78
95
  if (!command || !session?.guildId) return;
79
96
  const pluginName = command?.plugin?.name;
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.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [