mioku-plugin-chat 2.1.1 → 2.1.2

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/index.ts CHANGED
@@ -15,7 +15,6 @@ import {
15
15
  getQuotedContent,
16
16
  isGroupAllowed,
17
17
  isQuotingBot,
18
- safeText,
19
18
  shouldTrigger,
20
19
  } from "./utils";
21
20
  import { BASE_CONFIG } from "./configs/base";
@@ -613,9 +612,12 @@ const chatPlugin = definePlugin({
613
612
  if (overrideContent?.trim()) {
614
613
  return overrideContent.trim();
615
614
  }
616
- // 戳一戳、入群通知等没有 message 字段的事件直接走默认提示,
617
- // 避免 ctx.text 触底 mioki 的 (event.message).filter(...) 抛 TypeError。
618
- const text = safeText(ctx, event).trim();
615
+ // If no event or event has no message property (synthetic event like group_member_increase),
616
+ // return the default prompt
617
+ if (!event || !event.message || !Array.isArray(event.message)) {
618
+ return "[No new user message in this turn. Reply naturally based on the runtime instruction and recent context.]";
619
+ }
620
+ const text = ctx.text(event)?.trim() || "";
619
621
  if (text) {
620
622
  return text;
621
623
  }
@@ -1037,7 +1039,9 @@ const chatPlugin = definePlugin({
1037
1039
  const cfg = await getConfig();
1038
1040
  if (!cfg.apiKey) return;
1039
1041
 
1040
- const text = safeText(ctx, e);
1042
+ if (!e?.message || !Array.isArray(e.message)) return;
1043
+
1044
+ const text = ctx.text(e) || "";
1041
1045
  const isGroup = e.message_type === "group";
1042
1046
  const groupId: number | undefined = isGroup ? e.group_id : undefined;
1043
1047
  const userId: number = e.user_id || e.sender?.user_id;
@@ -1681,7 +1685,7 @@ async function processChat(
1681
1685
  }
1682
1686
  if (quotedInfo?.imageUrl) imageUrls.push(quotedInfo.imageUrl);
1683
1687
 
1684
- let messageContent = safeText(ctx, e);
1688
+ let messageContent = ctx.text(e) || "";
1685
1689
  let extraContext = "";
1686
1690
  if (quotedInfo) {
1687
1691
  const parts = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-plugin-chat",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "AI 智能聊天插件",
5
5
  "main": "index.ts",
6
6
  "type": "module",
package/utils/index.ts CHANGED
@@ -6,5 +6,4 @@ export {
6
6
  getBotRole,
7
7
  getQuotedContent,
8
8
  getGroupHistory,
9
- safeText,
10
9
  } from "./message";
package/utils/message.ts CHANGED
@@ -11,15 +11,6 @@ import { getImageTag } from "../core/media/image-analyzer";
11
11
 
12
12
  const HISTORY_MEDIA_CONCURRENCY = 8;
13
13
 
14
- export function safeText(ctx: MiokiContext, e: any): string {
15
- if (!e || !Array.isArray(e.message)) return "";
16
- try {
17
- return ctx.text(e) || "";
18
- } catch {
19
- return "";
20
- }
21
- }
22
-
23
14
  export function shouldTrigger(
24
15
  e: any,
25
16
  text: string,
@@ -124,7 +115,10 @@ export function extractContent(
124
115
  cfg: ChatConfig,
125
116
  ctx: MiokiContext,
126
117
  ): { text: string; multimodal: any[] | null } {
127
- let text = safeText(ctx, e);
118
+ let text = "";
119
+ try {
120
+ text = ctx.text(e) || "";
121
+ } catch {}
128
122
 
129
123
  // If text is empty but user @'d the bot, describe the action
130
124
  if (!text.trim() && e.message) {