mioku-plugin-chat 3.0.3 → 3.0.4
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/handlers/idle-debug.ts +1 -1
- package/handlers/message.ts +0 -20
- package/handlers/tts-command.ts +1 -1
- package/index.ts +54 -2
- package/package.json +2 -30
package/handlers/idle-debug.ts
CHANGED
|
@@ -11,7 +11,7 @@ export async function handleIdleCheckDebug(
|
|
|
11
11
|
cfg: ChatConfig,
|
|
12
12
|
): Promise<void> {
|
|
13
13
|
const ctx: MiokuContext = pluginCtx.ctx;
|
|
14
|
-
const isOwner = ctx.
|
|
14
|
+
const isOwner = ctx.isMaster?.(e) ?? false;
|
|
15
15
|
if (!isOwner) {
|
|
16
16
|
await e.reply("只有主人才能使用这个指令~");
|
|
17
17
|
return;
|
package/handlers/message.ts
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
summarizeHistoryVideo,
|
|
23
23
|
} from "../core/media/history-media";
|
|
24
24
|
import { handleIdleCheckDebug } from "./idle-debug";
|
|
25
|
-
import { handleTtsCommand } from "./tts-command";
|
|
26
25
|
import { processChat } from "../core/chat-turn";
|
|
27
26
|
|
|
28
27
|
const POKE_COOLDOWN_MS = 10 * 60_000;
|
|
@@ -55,25 +54,6 @@ export function createMessageHandler(
|
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
if (text.startsWith("/tts")) {
|
|
59
|
-
const payload = text.replace(/^\/tts\s*/, "");
|
|
60
|
-
await handleTtsCommand(pluginCtx, e, payload);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (text === "/重置会话") {
|
|
65
|
-
if (groupId) {
|
|
66
|
-
pluginCtx.sessionManager.resetBotMessages(`group:${groupId}`);
|
|
67
|
-
pluginCtx.groupStructuredHistory.clear(`group:${groupId}`);
|
|
68
|
-
await e.reply("已清除本群会话中 AI 发送的消息~");
|
|
69
|
-
} else {
|
|
70
|
-
pluginCtx.sessionManager.resetBotMessages(`personal:${userId}`);
|
|
71
|
-
pluginCtx.groupStructuredHistory.clear(`personal:${userId}`);
|
|
72
|
-
await e.reply("已清除你的个人会话中 AI 发送的消息~");
|
|
73
|
-
}
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
57
|
if (groupId && !isGroupAllowed(groupId, cfg)) return;
|
|
78
58
|
|
|
79
59
|
// 媒体分析
|
package/handlers/tts-command.ts
CHANGED
|
@@ -15,7 +15,7 @@ export async function handleTtsCommand(
|
|
|
15
15
|
payload: string,
|
|
16
16
|
): Promise<void> {
|
|
17
17
|
const { ctx } = pluginCtx;
|
|
18
|
-
const isOwner = ctx.
|
|
18
|
+
const isOwner = ctx.isMaster?.(e) ?? false;
|
|
19
19
|
// if (!isOwner) {
|
|
20
20
|
// await e.reply("只有主人才能使用 /tts 指令~");
|
|
21
21
|
// return;
|
package/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { RateLimitGuard } from "./manage/rate-limit-guard";
|
|
|
43
43
|
import { createChatRuntime } from "./runtime/chat-runtime";
|
|
44
44
|
import { createMessageHandler } from "./handlers/message";
|
|
45
45
|
import { createPokeHandler } from "./handlers/poke";
|
|
46
|
+
import { handleTtsCommand } from "./handlers/tts-command";
|
|
46
47
|
import { buildHistoryMediaOptions } from "./core/media/segment";
|
|
47
48
|
import type { ChatConfigProvider } from "./humanize";
|
|
48
49
|
import type { ChatPluginContext, ChatHandlerState } from "./context";
|
|
@@ -115,8 +116,6 @@ function resolveRoleInstances(aiService: AIService): {
|
|
|
115
116
|
|
|
116
117
|
export default definePlugin({
|
|
117
118
|
name: "chat",
|
|
118
|
-
version: "1.1.0",
|
|
119
|
-
description: "AI 智能聊天插件",
|
|
120
119
|
async setup(ctx: MiokuContext) {
|
|
121
120
|
ctx.logger.info("聊天插件正在初始化...");
|
|
122
121
|
|
|
@@ -511,6 +510,59 @@ roleModels = resolved.models;
|
|
|
511
510
|
const runtime = createChatRuntime(pluginCtx, getConfig);
|
|
512
511
|
aiService.registerChatRuntime(runtime);
|
|
513
512
|
|
|
513
|
+
ctx.command({
|
|
514
|
+
name: "/重置会话",
|
|
515
|
+
match: /^\/重置会话$/,
|
|
516
|
+
prefixes: false,
|
|
517
|
+
description: "重置自己的AI聊天记录",
|
|
518
|
+
handler: async ({ event }) => {
|
|
519
|
+
if (event.user_id === event.self_id) return;
|
|
520
|
+
const groupId =
|
|
521
|
+
event.message_type === "group" ? Number(event.group_id) : undefined;
|
|
522
|
+
if (groupId) {
|
|
523
|
+
pluginCtx.sessionManager.resetBotMessages(`group:${groupId}`);
|
|
524
|
+
pluginCtx.groupStructuredHistory.clear(`group:${groupId}`);
|
|
525
|
+
await event.reply("已清除本群会话中 AI 发送的消息~");
|
|
526
|
+
} else {
|
|
527
|
+
const userId = Number(event.user_id || event.sender?.user_id || 0);
|
|
528
|
+
pluginCtx.sessionManager.resetBotMessages(`personal:${userId}`);
|
|
529
|
+
pluginCtx.groupStructuredHistory.clear(`personal:${userId}`);
|
|
530
|
+
await event.reply("已清除你的个人会话中 AI 发送的消息~");
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
});
|
|
534
|
+
ctx.command({
|
|
535
|
+
name: "/重置群会话",
|
|
536
|
+
match: /^\/重置群会话$/,
|
|
537
|
+
prefixes: false,
|
|
538
|
+
permission: "admin",
|
|
539
|
+
description: "重置当前群的AI聊天记录",
|
|
540
|
+
handler: async ({ event }) => {
|
|
541
|
+
if (event.user_id === event.self_id) return;
|
|
542
|
+
const groupId =
|
|
543
|
+
event.message_type === "group" ? Number(event.group_id) : undefined;
|
|
544
|
+
if (!groupId) {
|
|
545
|
+
await event.reply("在群里使用试试看吧~", true);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
pluginCtx.sessionManager.resetBotMessages(`group:${groupId}`);
|
|
549
|
+
pluginCtx.groupStructuredHistory.clear(`group:${groupId}`);
|
|
550
|
+
await event.reply("已清除本群会话中 AI 发送的消息~");
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
ctx.command({
|
|
554
|
+
name: "/tts",
|
|
555
|
+
match: /^\/tts\s*(.*)$/,
|
|
556
|
+
prefixes: false,
|
|
557
|
+
permission: "owner",
|
|
558
|
+
description: "TTS 推理",
|
|
559
|
+
usage: "/tts <文本>",
|
|
560
|
+
handler: async ({ event, match }) => {
|
|
561
|
+
if (event.user_id === event.self_id) return;
|
|
562
|
+
await handleTtsCommand(pluginCtx, event, String(match?.[1] ?? "").trim());
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
|
|
514
566
|
ctx.handle("message", createMessageHandler(pluginCtx, handlerState));
|
|
515
567
|
ctx.handle("notice.group.poke", createPokeHandler(pluginCtx, handlerState));
|
|
516
568
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mioku-plugin-chat",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "AI 智能聊天插件",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -17,35 +17,7 @@
|
|
|
17
17
|
"config",
|
|
18
18
|
"help",
|
|
19
19
|
"screenshot"
|
|
20
|
-
]
|
|
21
|
-
"accessHooks": [
|
|
22
|
-
{
|
|
23
|
-
"id": "戳一戳触发对话",
|
|
24
|
-
"event": "notice.group.poke",
|
|
25
|
-
"description": "群内戳一戳 bot"
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
"help": {
|
|
29
|
-
"title": "AI 聊天",
|
|
30
|
-
"description": "智能 AI 聊天插件",
|
|
31
|
-
"commands": [
|
|
32
|
-
{
|
|
33
|
-
"cmd": "/重置会话",
|
|
34
|
-
"desc": "重置自己的AI聊天记录",
|
|
35
|
-
"role": "member"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"cmd": "/重置群会话",
|
|
39
|
-
"desc": "重置当前群的AI聊天记录",
|
|
40
|
-
"role": "admin"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"cmd": "/tts <文本>",
|
|
44
|
-
"desc": "TTS 推理",
|
|
45
|
-
"role": "owner"
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
20
|
+
]
|
|
49
21
|
},
|
|
50
22
|
"dependencies": {
|
|
51
23
|
"openai": "^4.0.0",
|