diff --git a/changelog_config.md b/changelog_config.md index 7101fe828..c4c560644 100644 --- a/changelog_config.md +++ b/changelog_config.md @@ -1,6 +1,12 @@ # Changelog +## [0.0.5] - 2025-3-11 +### Added +- 新增了 `alias_names` 配置项,用于指定麦麦的别名。 + ## [0.0.4] - 2025-3-9 ### Added - 新增了 `memory_ban_words` 配置项,用于指定不希望记忆的词汇。 + + diff --git a/docs/installation_cute.md b/docs/installation_cute.md index 3a63988f1..4465660f9 100644 --- a/docs/installation_cute.md +++ b/docs/installation_cute.md @@ -110,7 +110,8 @@ PLUGINS=["src2.plugins.chat"] # 这里是机器人的插件列表呢 ```toml [bot] qq = "把这里改成你的机器人QQ号喵" # 填写你的机器人QQ号 -nickname = "麦麦" # 机器人的名字,你可以改成你喜欢的任何名字哦 +nickname = "麦麦" # 机器人的名字,你可以改成你喜欢的任何名字哦,建议和机器人QQ名称/群昵称一样哦 +alias_names = ["小麦", "阿麦"] # 也可以用这个招呼机器人,可以不设置呢 [personality] # 这里可以设置机器人的性格呢,让它更有趣一些喵 diff --git a/docs/installation_standard.md b/docs/installation_standard.md index b3a9867f9..03b66dc46 100644 --- a/docs/installation_standard.md +++ b/docs/installation_standard.md @@ -72,6 +72,9 @@ PLUGINS=["src2.plugins.chat"] [bot] qq = "机器人QQ号" # 必填 nickname = "麦麦" # 机器人昵称 +# alias_names: 配置机器人可使用的别名。当机器人在群聊或对话中被调用时,别名可以作为直接命令或提及机器人的关键字使用。 +# 该配置项为字符串数组。例如: ["小麦", "阿麦"] +alias_names = ["小麦", "阿麦"] # 机器人别名 [personality] prompt_personality = [ diff --git a/ruff.toml b/pyproject.toml similarity index 77% rename from ruff.toml rename to pyproject.toml index 54231339f..0a4805744 100644 --- a/ruff.toml +++ b/pyproject.toml @@ -1,9 +1,20 @@ +[project] +name = "MaiMaiBot" +version = "0.1.0" +description = "MaiMaiBot" + +[tool.nonebot] +plugins = ["src.plugins.chat"] +plugin_dirs = ["src/plugins"] + +[tool.ruff] + include = ["*.py"] # 行长度设置 line-length = 120 -[lint] +[tool.ruff.lint] fixable = ["ALL"] unfixable = [] @@ -19,7 +30,7 @@ select = [ ignore = ["E711"] -[format] +[tool.ruff.format] docstring-code-format = true indent-style = "space" diff --git a/src/plugins/chat/config.py b/src/plugins/chat/config.py index 3888c0b94..c088e1a76 100644 --- a/src/plugins/chat/config.py +++ b/src/plugins/chat/config.py @@ -1,6 +1,6 @@ import os from dataclasses import dataclass, field -from typing import Dict, Optional +from typing import Dict, List, Optional import tomli from loguru import logger @@ -17,6 +17,7 @@ class BotConfig: BOT_QQ: Optional[int] = 1 BOT_NICKNAME: Optional[str] = None + BOT_ALIAS_NAMES: List[str] = field(default_factory=list) # 别名,可以通过这个叫它 # 消息处理相关配置 MIN_TEXT_LENGTH: int = 2 # 最小处理文本长度 @@ -191,6 +192,9 @@ class BotConfig: config.BOT_QQ = int(bot_qq) config.BOT_NICKNAME = bot_config.get("nickname", config.BOT_NICKNAME) + if config.INNER_VERSION in SpecifierSet(">=0.0.5"): + config.BOT_ALIAS_NAMES = bot_config.get("alias_names", config.BOT_ALIAS_NAMES) + def response(parent: dict): response_config = parent["response"] config.MODEL_R1_PROBABILITY = response_config.get("model_r1_probability", config.MODEL_R1_PROBABILITY) diff --git a/src/plugins/chat/prompt_builder.py b/src/plugins/chat/prompt_builder.py index 4cf21af19..0805caa5a 100644 --- a/src/plugins/chat/prompt_builder.py +++ b/src/plugins/chat/prompt_builder.py @@ -131,18 +131,19 @@ class PromptBuilder: probability_1 = global_config.PERSONALITY_1 probability_2 = global_config.PERSONALITY_2 probability_3 = global_config.PERSONALITY_3 - prompt_personality = '' + + prompt_personality = f'{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},你还有很多别名:{"/".join(global_config.BOT_ALIAS_NAMES)},' personality_choice = random.random() if personality_choice < probability_1: # 第一种人格 - prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},{personality[0]}, 你正在浏览qq群,{promt_info_prompt}, + prompt_personality += f'''{personality[0]}, 你正在浏览qq群,{promt_info_prompt}, 现在请你给出日常且口语化的回复,平淡一些,尽量简短一些。{keywords_reaction_prompt} 请注意把握群里的聊天内容,不要刻意突出自身学科背景,不要回复的太有条理,可以有个性。''' elif personality_choice < probability_1 + probability_2: # 第二种人格 - prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},{personality[1]}, 你正在浏览qq群,{promt_info_prompt}, + prompt_personality += f'''{personality[1]}, 你正在浏览qq群,{promt_info_prompt}, 现在请你给出日常且口语化的回复,请表现你自己的见解,不要一昧迎合,尽量简短一些。{keywords_reaction_prompt} 请你表达自己的见解和观点。可以有个性。''' else: # 第三种人格 - prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},{personality[2]}, 你正在浏览qq群,{promt_info_prompt}, + prompt_personality += f'''{personality[2]}, 你正在浏览qq群,{promt_info_prompt}, 现在请你给出日常且口语化的回复,请表现你自己的见解,不要一昧迎合,尽量简短一些。{keywords_reaction_prompt} 请你表达自己的见解和观点。可以有个性。''' diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 054526e94..6619f37af 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -53,19 +53,13 @@ def db_message_to_str(message_dict: Dict) -> str: return result -def is_mentioned_bot_in_message(message: Message) -> bool: - """检查消息是否提到了机器人""" - keywords = [global_config.BOT_NICKNAME] - for keyword in keywords: - if keyword in message.processed_plain_text: - return True - return False - - def is_mentioned_bot_in_txt(message: str) -> bool: """检查消息是否提到了机器人""" - keywords = [global_config.BOT_NICKNAME] - for keyword in keywords: + if global_config.BOT_NICKNAME is None: + return True + if global_config.BOT_NICKNAME in message: + return True + for keyword in global_config.BOT_ALIAS_NAMES: if keyword in message: return True return False diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index bff64d05f..24b2f93c2 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "0.0.4" +version = "0.0.5" #如果你想要修改配置文件,请在修改后将version的值进行变更 #如果新增项目,请在BotConfig类下新增相应的变量 @@ -15,6 +15,7 @@ version = "0.0.4" [bot] qq = 123 nickname = "麦麦" +alias_names = ["小麦", "阿麦"] [personality] prompt_personality = [