diff --git a/model/command/command.py b/model/command/command.py index bffbc8ac9..9b58f2463 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -19,6 +19,13 @@ class Command: return True, self.help() return False, None + # 接受可变参数 + def command_start_with(self, message: str, *args): + for arg in args: + if message.startswith(arg) or message.startswith('/'+arg): + return True + return False + def update(self, message: str): l = message.split(" ") if len(l) == 1: diff --git a/model/command/command_openai_official.py b/model/command/command_openai_official.py index 6fe4a276c..223bb1227 100644 --- a/model/command/command_openai_official.py +++ b/model/command/command_openai_official.py @@ -7,33 +7,35 @@ class CommandOpenAIOfficial(Command): self.provider = provider def check_command(self, message: str, session_id: str, user_name: str): - if message.startswith("reset") or message.startswith("重置"): + if self.command_start_with(message, "reset", "重置"): return True, self.reset(session_id) - elif message.startswith("his") or message.startswith("历史"): + elif self.command_start_with(message, "his", "历史"): return True, self.his(message, session_id, user_name) - elif message.startswith("token"): + elif self.command_start_with(message, "token"): return True, self.token(session_id) - elif message.startswith("gpt"): + elif self.command_start_with(message, "gpt"): return True, self.gpt() - elif message.startswith("status") or message.startswith("状态"): + elif self.command_start_with(message, "status"): return True, self.status() - elif message.startswith("count") or message.startswith("统计"): + elif self.command_start_with(message, "count"): return True, self.count() - elif message.startswith("help") or message.startswith("帮助"): + elif self.command_start_with(message, "help", "帮助"): return True, self.help() - elif message.startswith("key") or message.startswith("动态添加key"): + elif self.command_start_with(message, "key"): return True, self.key(message, user_name) - elif message.startswith("unset"): + elif self.command_start_with(message, "unset"): return True, self.unset(session_id) - elif message.startswith("set"): + elif self.command_start_with(message, "set"): return True, self.set(message, session_id) - elif message.startswith("画"): + elif self.command_start_with(message, "update"): return True, self.draw(message) - elif message.startswith("update"): + elif self.command_start_with(message, "画"): return True, self.update(message) return False, None + + def reset(self, session_id: str): self.provider.forget(session_id) return True, "重置成功" diff --git a/model/command/command_rev_chatgpt.py b/model/command/command_rev_chatgpt.py index f73ce3f48..35ac5b9eb 100644 --- a/model/command/command_rev_chatgpt.py +++ b/model/command/command_rev_chatgpt.py @@ -6,14 +6,9 @@ class CommandRevChatGPT(Command): self.provider = provider def check_command(self, message: str): - # hit, res = super().check_command(message) - # if hit: - # return res - # if message.startswith("reset") or message.startswith("重置"): - # return True, self.reset() - if message.startswith("help") or message.startswith("帮助"): + if self.command_start_with(message, "help", "帮助"): return True, self.help() - elif message.startswith("update"): + elif self.command_start_with(message, "update"): return True, self.update(message) return False, None diff --git a/model/command/command_rev_edgegpt.py b/model/command/command_rev_edgegpt.py index 5e9fdf46a..cfe5a62e9 100644 --- a/model/command/command_rev_edgegpt.py +++ b/model/command/command_rev_edgegpt.py @@ -6,11 +6,11 @@ class CommandRevEdgeGPT(Command): self.provider = provider def check_command(self, message: str, loop): - if message.startswith("reset") or message.startswith("重置"): + if self.command_start_with(message, "reset"): return True, self.reset(loop) - elif message.startswith("help") or message.startswith("帮助"): + elif self.command_start_with(message, "help"): return True, self.help() - elif message.startswith("update"): + elif self.command_start_with(message, "update"): return True, self.update(message) return False, None