koishi-plugin-without-assignee 0.0.1 → 0.1.0

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.
Files changed (3) hide show
  1. package/lib/index.js +21 -20
  2. package/package.json +1 -1
  3. package/src/index.ts +28 -27
package/lib/index.js CHANGED
@@ -56,28 +56,29 @@ var Config = import_koishi.Schema.intersect([
56
56
  }).description("调试设置")
57
57
  ]);
58
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}`);
59
+ ctx.on("ready", async () => {
60
+ function logInfo(...args) {
61
+ if (config.loggerinfo) {
62
+ ctx.logger.info(...args);
63
+ }
78
64
  }
65
+ __name(logInfo, "logInfo");
66
+ ctx.on("attach-channel", (session) => {
67
+ if (!ctx.database) {
68
+ ctx.logger.warn("数据库服务未启用,插件无法工作");
69
+ return;
70
+ }
71
+ if (session.isDirect) return;
72
+ const channel = session.channel;
73
+ if (!channel) return;
74
+ const originalAssignee = channel.assignee;
75
+ if (originalAssignee && originalAssignee !== session.selfId) {
76
+ logInfo(`检测到频道 ${session.channelId} 的 assignee 为 ${originalAssignee},当前 bot 为 ${session.selfId}`);
77
+ channel.assignee = session.selfId;
78
+ logInfo(`已将频道 ${session.channelId} 的 assignee 临时修改为 ${session.selfId}`);
79
+ }
80
+ });
79
81
  });
80
- ctx.logger.info("without-assignee 插件已加载,assignee 机制已禁用");
81
82
  }
82
83
  __name(apply, "apply");
83
84
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-without-assignee",
3
3
  "description": "禁用 Koishi 的 assignee 机制,允许同一频道内的多个机器人同时响应无前缀指令",
4
- "version": "0.0.1",
4
+ "version": "0.1.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/src/index.ts CHANGED
@@ -35,40 +35,41 @@ export const Config: Schema<Config> = Schema.intersect([
35
35
  ])
36
36
 
37
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);
38
+ ctx.on("ready", async () => {
39
+ // 日志输出函数
40
+ function logInfo(...args: any[]) {
41
+ if (config.loggerinfo) {
42
+ (ctx.logger.info as (...args: any[]) => void)(...args);
43
+ }
42
44
  }
43
- }
44
45
 
45
- // 如果没有数据库服务,无需处理
46
- if (!ctx.database) {
47
- ctx.logger.warn('数据库服务未启用,插件无法工作');
48
- return;
49
- }
46
+ // 在 observeChannel 之后、assignee 检查之前触发
47
+ ctx.on('attach-channel', (session: Session) => {
50
48
 
51
- // 在 observeChannel 之后、assignee 检查之前触发
52
- ctx.on('attach-channel', (session: Session) => {
53
- // 只处理群组消息
54
- if (session.isDirect) return;
49
+ // 如果没有数据库服务,无需处理
50
+ if (!ctx.database) {
51
+ ctx.logger.warn('数据库服务未启用,插件无法工作');
52
+ return;
53
+ }
55
54
 
56
- const channel = session.channel;
57
- if (!channel) return;
55
+ // 只处理群组消息
56
+ if (session.isDirect) return;
58
57
 
59
- // 获取原始的 assignee
60
- const originalAssignee = (channel as any).assignee;
58
+ const channel = session.channel;
59
+ if (!channel) return;
61
60
 
62
- // 如果 assignee 存在且不是当前 bot
63
- if (originalAssignee && originalAssignee !== session.selfId) {
64
- logInfo(`检测到频道 ${session.channelId} 的 assignee 为 ${originalAssignee},当前 bot 为 ${session.selfId}`);
61
+ // 获取原始的 assignee
62
+ const originalAssignee = (channel as any).assignee;
65
63
 
66
- // 临时修改 assignee 为当前 bot,绕过后续的 assignee 检查
67
- (channel as any).assignee = session.selfId;
64
+ // 如果 assignee 存在且不是当前 bot
65
+ if (originalAssignee && originalAssignee !== session.selfId) {
66
+ logInfo(`检测到频道 ${session.channelId} 的 assignee 为 ${originalAssignee},当前 bot 为 ${session.selfId}`);
68
67
 
69
- logInfo(`已将频道 ${session.channelId} assignee 临时修改为 ${session.selfId}`);
70
- }
71
- });
68
+ // 临时修改 assignee 为当前 bot,绕过后续的 assignee 检查
69
+ (channel as any).assignee = session.selfId;
72
70
 
73
- ctx.logger.info('without-assignee 插件已加载,assignee 机制已禁用');
71
+ logInfo(`已将频道 ${session.channelId} 的 assignee 临时修改为 ${session.selfId}`);
72
+ }
73
+ });
74
+ })
74
75
  }