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.
- package/lib/index.js +21 -20
- package/package.json +1 -1
- 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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
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
|
-
|
|
40
|
-
|
|
41
|
-
(
|
|
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
|
-
|
|
47
|
-
ctx.logger.warn('数据库服务未启用,插件无法工作');
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
46
|
+
// 在 observeChannel 之后、assignee 检查之前触发
|
|
47
|
+
ctx.on('attach-channel', (session: Session) => {
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
// 如果没有数据库服务,无需处理
|
|
50
|
+
if (!ctx.database) {
|
|
51
|
+
ctx.logger.warn('数据库服务未启用,插件无法工作');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
// 只处理群组消息
|
|
56
|
+
if (session.isDirect) return;
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const channel = session.channel;
|
|
59
|
+
if (!channel) return;
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
logInfo(`检测到频道 ${session.channelId} 的 assignee 为 ${originalAssignee},当前 bot 为 ${session.selfId}`);
|
|
61
|
+
// 获取原始的 assignee 值
|
|
62
|
+
const originalAssignee = (channel as any).assignee;
|
|
65
63
|
|
|
66
|
-
//
|
|
67
|
-
(
|
|
64
|
+
// 如果 assignee 存在且不是当前 bot
|
|
65
|
+
if (originalAssignee && originalAssignee !== session.selfId) {
|
|
66
|
+
logInfo(`检测到频道 ${session.channelId} 的 assignee 为 ${originalAssignee},当前 bot 为 ${session.selfId}`);
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
68
|
+
// 临时修改 assignee 为当前 bot,绕过后续的 assignee 检查
|
|
69
|
+
(channel as any).assignee = session.selfId;
|
|
72
70
|
|
|
73
|
-
|
|
71
|
+
logInfo(`已将频道 ${session.channelId} 的 assignee 临时修改为 ${session.selfId}`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
})
|
|
74
75
|
}
|