fix: Strip leading and trailing whitespace from llm_wake_prefix

This commit is contained in:
Soulter
2024-08-02 23:17:35 +08:00
parent c50bcdbdb9
commit a481fd1a3e
2 changed files with 12 additions and 4 deletions
+5 -1
View File
@@ -112,6 +112,8 @@ class MessageHandler():
self.rate_limit_helper = RateLimitHelper(context)
self.content_safety_helper = ContentSafetyHelper(context)
self.llm_wake_prefix = self.context.base_config['llm_wake_prefix']
if self.llm_wake_prefix:
self.llm_wake_prefix = self.llm_wake_prefix.strip()
self.nicks = self.context.nick
self.provider = provider
self.reply_prefix = str(self.context.reply_prefix)
@@ -156,10 +158,12 @@ class MessageHandler():
)
# check if the message is a llm-wake-up command
if not msg_plain.startswith(self.llm_wake_prefix):
if self.llm_wake_prefix and not msg_plain.startswith(self.llm_wake_prefix):
logger.debug(f"消息 `{msg_plain}` 没有以 LLM 唤醒前缀 `{self.llm_wake_prefix}` 开头,忽略。")
return
if not provider:
logger.debug("没有任何 LLM 可用,忽略。")
return
# check the content safety
+7 -3
View File
@@ -62,14 +62,18 @@ class InternalCommandHandler:
return CommandResult().message("你没有权限使用该指令。")
l = message_str.split(" ")
if len(l) == 1:
return CommandResult().message("设置机器人唤醒词,支持多唤醒词。以唤醒词开头的消息会唤醒机器人处理,起到 @ 的效果。\n示例:wake 昵称1 昵称2 昵称3")
nick = l[1:]
return CommandResult().message(f"设置机器人唤醒词。以唤醒词开头的消息 \
会唤醒机器人处理,起到 @ 的效果。\n示例:wake 昵称。\
当前唤醒词有:{",".join(context.nick)}")
nick = l[1].strip()
if not nick:
return CommandResult().message("wake: 请指定唤醒词。")
context.config_helper.put("nick_qq", nick)
context.nick = tuple(nick)
return CommandResult(
hit=True,
success=True,
message_chain=f"已经成功将唤醒词设定为 {nick}",
message_chain=f"已经成功将唤醒词设定为 {nick}",
)
def update(self, message: AstrMessageEvent, context: Context):