Skip to content

Commit

Permalink
[fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaowFISH committed Jan 5, 2025
1 parent f38a451 commit 0701bde
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
32 changes: 18 additions & 14 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) { }
Expand Down
1 change: 1 addition & 0 deletions src/commands/memory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { Context } from "koishi";
import { Metadata } from "koishi-plugin-yesimbot-memory";

Expand Down
2 changes: 1 addition & 1 deletion src/extensions/ext_memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export function isEmpty(str: string) {
return !str || String(str) == ""
}

export function isNotEmpty(str: string) {
return !isEmpty(str)
}

/**
* 模板引擎
*
Expand Down

0 comments on commit 0701bde

Please sign in to comment.