koishi-plugin-without-assignee 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 ADDED
@@ -0,0 +1,14 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "without-assignee";
3
+ export declare const reusable = false;
4
+ export declare const filter = false;
5
+ export declare const inject: {
6
+ optional: string[];
7
+ required: any[];
8
+ };
9
+ export declare const usage = "\n---\n\n\n\u7981\u7528 Koishi \u7684 assignee \u673A\u5236\uFF0C\u5141\u8BB8\u540C\u4E00\u9891\u9053\u5185\u7684\u591A\u4E2A\u673A\u5668\u4EBA\u540C\u65F6\u54CD\u5E94\u65E0\u524D\u7F00\u6307\u4EE4\u3002\n\n\u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0C\u5F53\u540C\u4E00\u5E73\u53F0\u7684\u540C\u4E00\u9891\u9053\u5185\u6709\u591A\u4E2A\u673A\u5668\u4EBA\u65F6\uFF0CKoishi \u4F1A\u542F\u7528 assignee \u673A\u5236\uFF0C\n\u53EA\u5141\u8BB8\u88AB\u5206\u914D\u7684\u673A\u5668\u4EBA\u54CD\u5E94\u65E0\u524D\u7F00\u6307\u4EE4\uFF0C\u5176\u4ED6\u673A\u5668\u4EBA\u9700\u8981\u901A\u8FC7 @\u673A\u5668\u4EBA \u7684\u65B9\u5F0F\u8C03\u7528\u3002\n\n\u542F\u7528\u6B64\u63D2\u4EF6\u540E\uFF0C\u6240\u6709\u673A\u5668\u4EBA\u90FD\u53EF\u4EE5\u54CD\u5E94\u65E0\u524D\u7F00\u6307\u4EE4\u3002\n\n---\n";
10
+ export interface Config {
11
+ loggerinfo?: boolean;
12
+ }
13
+ export declare const Config: Schema<Config>;
14
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js ADDED
@@ -0,0 +1,92 @@
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
+ filter: () => filter,
26
+ inject: () => inject,
27
+ name: () => name,
28
+ reusable: () => reusable,
29
+ usage: () => usage
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+ var import_koishi = require("koishi");
33
+ var name = "without-assignee";
34
+ var reusable = false;
35
+ var filter = false;
36
+ var inject = {
37
+ optional: ["database", "logger"],
38
+ required: []
39
+ };
40
+ var usage = `
41
+ ---
42
+
43
+
44
+ 禁用 Koishi 的 assignee 机制,允许同一频道内的多个机器人同时响应无前缀指令。
45
+
46
+ 默认情况下,当同一平台的同一频道内有多个机器人时,Koishi 会启用 assignee 机制,
47
+ 只允许被分配的机器人响应无前缀指令,其他机器人需要通过 @机器人 的方式调用。
48
+
49
+ 启用此插件后,所有机器人都可以响应无前缀指令。
50
+
51
+ ---
52
+ `;
53
+ var Config = import_koishi.Schema.intersect([
54
+ import_koishi.Schema.object({
55
+ loggerinfo: import_koishi.Schema.boolean().default(false).description("日志调试模式").experimental()
56
+ }).description("调试设置")
57
+ ]);
58
+ function apply(ctx, config) {
59
+ function logInfo(...args) {
60
+ if (config.loggerinfo) {
61
+ ctx.logger.info(...args);
62
+ }
63
+ }
64
+ __name(logInfo, "logInfo");
65
+ if (!ctx.database) {
66
+ ctx.logger.warn("数据库服务未启用,插件无法工作");
67
+ return;
68
+ }
69
+ ctx.on("attach-channel", (session) => {
70
+ if (session.isDirect) return;
71
+ const channel = session.channel;
72
+ if (!channel) return;
73
+ const originalAssignee = channel.assignee;
74
+ if (originalAssignee && originalAssignee !== session.selfId) {
75
+ logInfo(`检测到频道 ${session.channelId} 的 assignee 为 ${originalAssignee},当前 bot 为 ${session.selfId}`);
76
+ channel.assignee = session.selfId;
77
+ logInfo(`已将频道 ${session.channelId} 的 assignee 临时修改为 ${session.selfId}`);
78
+ }
79
+ });
80
+ ctx.logger.info("without-assignee 插件已加载,assignee 机制已禁用");
81
+ }
82
+ __name(apply, "apply");
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ Config,
86
+ apply,
87
+ filter,
88
+ inject,
89
+ name,
90
+ reusable,
91
+ usage
92
+ });
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "koishi-plugin-without-assignee",
3
+ "description": "禁用 Koishi 的 assignee 机制,允许同一频道内的多个机器人同时响应无前缀指令",
4
+ "version": "0.0.1",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "dist",
10
+ "src",
11
+ "client"
12
+ ],
13
+ "license": "MIT",
14
+ "keywords": [
15
+ "chatbot",
16
+ "koishi",
17
+ "plugin",
18
+ "without-assignee"
19
+ ],
20
+ "homepage": "https://github.com/koishi-shangxue-plugins/koishi-shangxue-apps",
21
+ "bugs": {
22
+ "url": "https://github.com/koishi-shangxue-plugins/koishi-shangxue-apps/issues"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/koishi-shangxue-plugins/koishi-shangxue-apps.git"
27
+ },
28
+ "peerDependencies": {
29
+ "koishi": "^4.18.9"
30
+ }
31
+ }
package/readme.md ADDED
@@ -0,0 +1,31 @@
1
+ # koishi-plugin-without-assignee
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-without-assignee?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-without-assignee)
4
+
5
+ ## 功能说明
6
+
7
+ 禁用 Koishi 的 assignee 机制,允许同一频道内的多个机器人同时响应无前缀指令。
8
+
9
+ ### 什么是 assignee 机制?
10
+
11
+ 默认情况下,当同一平台的同一频道内有多个机器人时,Koishi 会启用 assignee 机制:
12
+
13
+ - 只允许被分配的机器人(assignee)响应无前缀指令
14
+ - 其他机器人需要通过 `@机器人 指令` 的方式调用
15
+ - Koishi 会在数据库的 channel 表中记录 assignee 字段
16
+
17
+ ### 插件作用
18
+
19
+ 启用此插件后:
20
+
21
+ - 所有机器人都可以响应无前缀指令
22
+ - 不会修改数据库中的 assignee 值
23
+ - 仅在运行时临时绕过 assignee 检查
24
+
25
+ ## 技术原理
26
+
27
+ 插件通过监听 `attach-channel` 事件,在 Koishi 执行 assignee 检查之前,临时修改 `session.channel.assignee` 的值为当前机器人的 selfId,从而绕过检查。
28
+
29
+ ## 许可证
30
+
31
+ MIT License
package/src/index.ts ADDED
@@ -0,0 +1,74 @@
1
+ import { Context, Schema, Session } from 'koishi'
2
+
3
+ export const name = 'without-assignee'
4
+ export const reusable = false
5
+ export const filter = false
6
+
7
+ export const inject = {
8
+ optional: ['database', 'logger'],
9
+ required: []
10
+ }
11
+
12
+ export const usage = `
13
+ ---
14
+
15
+
16
+ 禁用 Koishi 的 assignee 机制,允许同一频道内的多个机器人同时响应无前缀指令。
17
+
18
+ 默认情况下,当同一平台的同一频道内有多个机器人时,Koishi 会启用 assignee 机制,
19
+ 只允许被分配的机器人响应无前缀指令,其他机器人需要通过 @机器人 的方式调用。
20
+
21
+ 启用此插件后,所有机器人都可以响应无前缀指令。
22
+
23
+ ---
24
+ `;
25
+
26
+
27
+ export interface Config {
28
+ loggerinfo?: boolean;
29
+ }
30
+
31
+ export const Config: Schema<Config> = Schema.intersect([
32
+ Schema.object({
33
+ loggerinfo: Schema.boolean().default(false).description("日志调试模式").experimental(),
34
+ }).description("调试设置"),
35
+ ])
36
+
37
+ export function apply(ctx: Context, config: Config) {
38
+ // 日志输出函数
39
+ function logInfo(...args: any[]) {
40
+ if (config.loggerinfo) {
41
+ (ctx.logger.info as (...args: any[]) => void)(...args);
42
+ }
43
+ }
44
+
45
+ // 如果没有数据库服务,无需处理
46
+ if (!ctx.database) {
47
+ ctx.logger.warn('数据库服务未启用,插件无法工作');
48
+ return;
49
+ }
50
+
51
+ // 在 observeChannel 之后、assignee 检查之前触发
52
+ ctx.on('attach-channel', (session: Session) => {
53
+ // 只处理群组消息
54
+ if (session.isDirect) return;
55
+
56
+ const channel = session.channel;
57
+ if (!channel) return;
58
+
59
+ // 获取原始的 assignee 值
60
+ const originalAssignee = (channel as any).assignee;
61
+
62
+ // 如果 assignee 存在且不是当前 bot
63
+ if (originalAssignee && originalAssignee !== session.selfId) {
64
+ logInfo(`检测到频道 ${session.channelId} 的 assignee 为 ${originalAssignee},当前 bot 为 ${session.selfId}`);
65
+
66
+ // 临时修改 assignee 为当前 bot,绕过后续的 assignee 检查
67
+ (channel as any).assignee = session.selfId;
68
+
69
+ logInfo(`已将频道 ${session.channelId} 的 assignee 临时修改为 ${session.selfId}`);
70
+ }
71
+ });
72
+
73
+ ctx.logger.info('without-assignee 插件已加载,assignee 机制已禁用');
74
+ }