koishi-plugin-chat-model 1.0.3 → 1.1.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/README.md +4 -0
- package/index.js +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -81,7 +81,9 @@ exports.apply = (ctx, config) => {
|
|
|
81
81
|
// 检查用户使用限制
|
|
82
82
|
if (config.usageLimit?.enabled && !await checkUsageLimit(ctx, session.userId, config)) {
|
|
83
83
|
await session.send('今日对话次数已达上限,请明天再来')
|
|
84
|
-
|
|
84
|
+
// 设置标记但不返回true
|
|
85
|
+
session._handled = true
|
|
86
|
+
return
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
try {
|
|
@@ -107,17 +109,20 @@ exports.apply = (ctx, config) => {
|
|
|
107
109
|
await updateUsageCount(ctx, session.userId)
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
+
// 标记消息为已处理,但不显式返回true
|
|
113
|
+
session._handled = true
|
|
114
|
+
// 这里不返回任何值,避免"true"被发送出去
|
|
112
115
|
} catch (error) {
|
|
113
116
|
ctx.logger.error('处理消息时出错:', error)
|
|
114
117
|
await session.send(`处理消息时出错: ${error.message}`)
|
|
115
|
-
|
|
118
|
+
// 标记已处理但不返回true
|
|
119
|
+
session._handled = true
|
|
116
120
|
}
|
|
117
121
|
}, true) // true表示这个中间件应该在所有其他中间件之后执行
|
|
118
122
|
|
|
119
123
|
// 注册清理上下文的命令
|
|
120
124
|
ctx.command('清除上下文', '清除与AI助手的对话上下文')
|
|
125
|
+
.alias('/清除上下文')
|
|
121
126
|
.action(async ({ session }) => {
|
|
122
127
|
await clearUserContext(ctx, session.userId)
|
|
123
128
|
return '已清除对话上下文'
|