diff --git a/packages/astrbot/commands/alter_cmd.py b/packages/astrbot/commands/alter_cmd.py index bad5072c..18d6c130 100644 --- a/packages/astrbot/commands/alter_cmd.py +++ b/packages/astrbot/commands/alter_cmd.py @@ -6,26 +6,7 @@ from astrbot.core.star.star import star_map from astrbot.core.star.filter.command import CommandFilter from astrbot.core.star.filter.command_group import CommandGroupFilter from astrbot.core.star.filter.permission import PermissionTypeFilter -from enum import Enum - - -class RstScene(Enum): - GROUP_UNIQUE_ON = ("group_unique_on", "群聊+会话隔离开启") - GROUP_UNIQUE_OFF = ("group_unique_off", "群聊+会话隔离关闭") - PRIVATE = ("private", "私聊") - - @property - def key(self) -> str: - return self.value[0] - - @property - def name(self) -> str: - return self.value[1] - - @classmethod - def from_index(cls, index: int) -> "RstScene": - mapping = {1: cls.GROUP_UNIQUE_ON, 2: cls.GROUP_UNIQUE_OFF, 3: cls.PRIVATE} - return mapping[index] +from .utils.rst_scene import RstScene class AlterCmdCommands(CommandParserMixin): @@ -58,8 +39,9 @@ class AlterCmdCommands(CommandParserMixin): ) return - cmd_name = " ".join(token.tokens[1:-1]) - cmd_type = token.get(-1) + # 兼容 reset scene 的专门配置 + cmd_name = token.get(1) + cmd_type = token.get(2) if cmd_name == "reset" and cmd_type == "config": from astrbot.api import sp @@ -123,6 +105,8 @@ class AlterCmdCommands(CommandParserMixin): return # 查找指令 + cmd_name = " ".join(token.tokens[1:-1]) + cmd_type = token.get(-1) found_command = None cmd_group = False for handler in star_handlers_registry: diff --git a/packages/astrbot/commands/conversation.py b/packages/astrbot/commands/conversation.py index 49f3cdcc..1a8ce746 100644 --- a/packages/astrbot/commands/conversation.py +++ b/packages/astrbot/commands/conversation.py @@ -7,33 +7,8 @@ from astrbot.core.provider.sources.dify_source import ProviderDify from astrbot.core.provider.sources.coze_source import ProviderCoze from astrbot.api import sp, logger from ..long_term_memory import LongTermMemory +from .utils.rst_scene import RstScene from typing import Union -from enum import Enum - - -class RstScene(Enum): - GROUP_UNIQUE_ON = ("group_unique_on", "群聊+会话隔离开启") - GROUP_UNIQUE_OFF = ("group_unique_off", "群聊+会话隔离关闭") - PRIVATE = ("private", "私聊") - - @property - def key(self) -> str: - return self.value[0] - - @property - def name(self) -> str: - return self.value[1] - - @classmethod - def from_index(cls, index: int) -> "RstScene": - mapping = {1: cls.GROUP_UNIQUE_ON, 2: cls.GROUP_UNIQUE_OFF, 3: cls.PRIVATE} - return mapping[index] - - @classmethod - def get_scene(cls, is_group: bool, is_unique_session: bool) -> "RstScene": - if is_group: - return cls.GROUP_UNIQUE_ON if is_unique_session else cls.GROUP_UNIQUE_OFF - return cls.PRIVATE class ConversationCommands: diff --git a/packages/astrbot/commands/utils/rst_scene.py b/packages/astrbot/commands/utils/rst_scene.py new file mode 100644 index 00000000..d9300740 --- /dev/null +++ b/packages/astrbot/commands/utils/rst_scene.py @@ -0,0 +1,26 @@ +from enum import Enum + + +class RstScene(Enum): + GROUP_UNIQUE_ON = ("group_unique_on", "群聊+会话隔离开启") + GROUP_UNIQUE_OFF = ("group_unique_off", "群聊+会话隔离关闭") + PRIVATE = ("private", "私聊") + + @property + def key(self) -> str: + return self.value[0] + + @property + def name(self) -> str: + return self.value[1] + + @classmethod + def from_index(cls, index: int) -> "RstScene": + mapping = {1: cls.GROUP_UNIQUE_ON, 2: cls.GROUP_UNIQUE_OFF, 3: cls.PRIVATE} + return mapping[index] + + @classmethod + def get_scene(cls, is_group: bool, is_unique_session: bool) -> "RstScene": + if is_group: + return cls.GROUP_UNIQUE_ON if is_unique_session else cls.GROUP_UNIQUE_OFF + return cls.PRIVATE