koishi-plugin-group-command-blocker 0.0.1
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 +22 -0
- package/lib/index.js +111 -0
- package/package.json +20 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "group-command-blocker";
|
|
3
|
+
export interface Config {
|
|
4
|
+
}
|
|
5
|
+
export declare const Config: Schema<Config>;
|
|
6
|
+
declare module 'koishi' {
|
|
7
|
+
interface Tables {
|
|
8
|
+
group_disabled_plugins: GroupDisabledPlugin;
|
|
9
|
+
group_blocked_users: GroupBlockedUser;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export interface GroupDisabledPlugin {
|
|
13
|
+
id: number;
|
|
14
|
+
guildId: string;
|
|
15
|
+
pluginName: string;
|
|
16
|
+
}
|
|
17
|
+
export interface GroupBlockedUser {
|
|
18
|
+
id: number;
|
|
19
|
+
guildId: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function apply(ctx: Context): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Config: () => Config,
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
name: () => name
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_koishi = require("koishi");
|
|
29
|
+
var name = "group-command-blocker";
|
|
30
|
+
var Config = import_koishi.Schema.object({});
|
|
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}`;
|
|
54
|
+
});
|
|
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}`;
|
|
62
|
+
});
|
|
63
|
+
ctx.command("block.user <target:user>", "屏蔽指定群员的消息").action(async ({ session }, target) => {
|
|
64
|
+
if (!session?.guildId || !target) return "请指定要屏蔽的人";
|
|
65
|
+
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}`;
|
|
76
|
+
});
|
|
77
|
+
ctx.command("unblock.user <target:user>", "取消屏蔽指定群员").action(async ({ session }, target) => {
|
|
78
|
+
if (!session?.guildId || !target) return "请指定要解封的人";
|
|
79
|
+
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} 的屏蔽`;
|
|
85
|
+
});
|
|
86
|
+
ctx.middleware(async (session, next) => {
|
|
87
|
+
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
|
+
});
|
|
92
|
+
if (blocked) return;
|
|
93
|
+
return next();
|
|
94
|
+
});
|
|
95
|
+
ctx.on("command/before-execute", async ({ command, session }) => {
|
|
96
|
+
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", {
|
|
99
|
+
guildId: session.guildId,
|
|
100
|
+
pluginName
|
|
101
|
+
});
|
|
102
|
+
if (disabled) return "";
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
__name(apply, "apply");
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
Config,
|
|
109
|
+
apply,
|
|
110
|
+
name
|
|
111
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-group-command-blocker",
|
|
3
|
+
"description": "这个东西也可以用来屏蔽群员",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"chatbot",
|
|
14
|
+
"koishi",
|
|
15
|
+
"plugin"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"koishi": "4.18.11"
|
|
19
|
+
}
|
|
20
|
+
}
|