diff --git a/src/bot.ts b/src/bot.ts index a745638..1cd2b17 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -10,8 +10,7 @@ import { Extension, getExtensions, getFunctionPrompt, getToolSchema } from "./ex import { EmojiManager } from "./managers/emojiManager"; import { ImageViewer } from "./services/imageViewer"; import { getEmbedding } from "./utils/factory"; -import { escapeUnicodeCharacters, isEmpty, Template } from "./utils/string"; -import { getFormatDateTime, tiktokenizer } from "./utils/toolkit"; +import { escapeUnicodeCharacters, isEmpty, isNotEmpty, Template } from "./utils/string"; import { ResponseVerifier } from "./utils/verifier"; export interface Function { @@ -389,20 +388,25 @@ export class Bot { // 如果 replyTo 不是私聊会话,只保留数字部分 private extractReplyTo(replyTo: string): string { - if (replyTo && !replyTo.startsWith("private:")) { - const numericMatch = replyTo.match(/\d+/); - if (numericMatch) { - replyTo = numericMatch[0].replace(/\s/g, ""); - } - // 不合法的 channelId - if (replyTo.match(/\{.+\}/)) { - replyTo = ""; - } - if (replyTo.indexOf("sandbox") > -1) { - replyTo = ""; + try { + replyTo = replyTo.toString().trim(); + if (isNotEmpty(replyTo) && !replyTo.startsWith("private:")) { + const numericMatch = replyTo.match(/\d+/); + if (numericMatch) { + replyTo = numericMatch[0].replace(/\s/g, ""); + } + // 不合法的 channelId + if (replyTo.match(/\{.+\}/)) { + replyTo = ""; + } + if (replyTo.indexOf("sandbox") > -1) { + replyTo = ""; + } } + return replyTo; + } catch (e) { + return ""; } - return replyTo; } // async summarize(channelId, userId, content) { } diff --git a/src/commands/memory.ts b/src/commands/memory.ts index bf75330..77ef156 100644 --- a/src/commands/memory.ts +++ b/src/commands/memory.ts @@ -1,3 +1,4 @@ +// @ts-nocheck import { Context } from "koishi"; import { Metadata } from "koishi-plugin-yesimbot-memory"; diff --git a/src/extensions/ext_memory.ts b/src/extensions/ext_memory.ts index 696ff34..6db8d95 100644 --- a/src/extensions/ext_memory.ts +++ b/src/extensions/ext_memory.ts @@ -6,7 +6,7 @@ import { Description, Extension, Name, Param } from "./base"; @Param("content", "Content to write to the memory.") export class InsertArchivalMemory extends Extension { async apply(content: string) { - await this.ctx.memory.addText(content); + throw new Error("Method not implemented."); } } diff --git a/src/index.ts b/src/index.ts index 1576139..df4a243 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,7 +126,7 @@ export function apply(ctx: Context, config: Config) { } }); - applyMemoryCommands(ctx, bot); + //applyMemoryCommands(ctx, bot); applySendQueneCommands(ctx, sendQueue); ctx.middleware(async (session: Session, next: Next) => { diff --git a/src/utils/string.ts b/src/utils/string.ts index 8ed6022..64d1203 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -47,6 +47,10 @@ export function isEmpty(str: string) { return !str || String(str) == "" } +export function isNotEmpty(str: string) { + return !isEmpty(str) +} + /** * 模板引擎 *