From e4b8865f9978960941f276ffa8dd0fdb3ee94f33 Mon Sep 17 00:00:00 2001 From: Hosigus Date: Mon, 10 Mar 2025 14:33:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=AB=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E4=BB=A5=E7=94=A8=E4=B8=8D=E5=90=8C=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=8F=AC=E5=94=A4=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/installation_cute.md | 3 ++- docs/installation_standard.md | 3 +++ src/plugins/chat/config.py | 4 +++- src/plugins/chat/prompt_builder.py | 9 +++++---- src/plugins/chat/utils.py | 16 +++++----------- template/bot_config_template.toml | 3 ++- 6 files changed, 20 insertions(+), 18 deletions(-) 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 cf8e7eb9b..ec5a05149 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/src/plugins/chat/config.py b/src/plugins/chat/config.py index c37d23a46..8c45d1664 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 @@ -16,6 +16,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 # 最小处理文本长度 @@ -190,6 +191,7 @@ class BotConfig: bot_qq = bot_config.get("qq") config.BOT_QQ = int(bot_qq) config.BOT_NICKNAME = bot_config.get("nickname", config.BOT_NICKNAME) + config.BOT_ALIAS_NAMES = bot_config.get("alias_names", config.BOT_ALIAS_NAMES) def response(parent: dict): response_config = parent["response"] 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 = [ From 00e02edc73c46d3bcb250b3bcdc6b063447e0f08 Mon Sep 17 00:00:00 2001 From: Rikki Date: Tue, 11 Mar 2025 04:00:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=200.0.5=20=E7=89=88=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E5=B1=82=E6=8E=A7=E5=88=B6=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/chat/config.py b/src/plugins/chat/config.py index bc69ffd4e..c088e1a76 100644 --- a/src/plugins/chat/config.py +++ b/src/plugins/chat/config.py @@ -17,7 +17,7 @@ class BotConfig: BOT_QQ: Optional[int] = 1 BOT_NICKNAME: Optional[str] = None - BOT_ALIAS_NAMES: List[str] = field(default_factory=list) # 别名,可以通过这个叫它 + BOT_ALIAS_NAMES: List[str] = field(default_factory=list) # 别名,可以通过这个叫它 # 消息处理相关配置 MIN_TEXT_LENGTH: int = 2 # 最小处理文本长度 @@ -191,7 +191,9 @@ class BotConfig: bot_qq = bot_config.get("qq") config.BOT_QQ = int(bot_qq) config.BOT_NICKNAME = bot_config.get("nickname", config.BOT_NICKNAME) - config.BOT_ALIAS_NAMES = bot_config.get("alias_names", config.BOT_ALIAS_NAMES) + + 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"] From eede406e55f1b25130ce65d37d9c08018166fcf8 Mon Sep 17 00:00:00 2001 From: Rikki Date: Tue, 11 Mar 2025 04:00:39 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dnonebot=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=8A=A0=E8=BD=BD=E9=A1=B9=E7=9B=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruff.toml => pyproject.toml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) rename ruff.toml => pyproject.toml (77%) 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" From 9e41c4f4c5c7ea90297507d9670c38f0abf04e97 Mon Sep 17 00:00:00 2001 From: Rikki Date: Tue, 11 Mar 2025 04:07:56 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=20bot=5Fconfig?= =?UTF-8?q?=200.0.5=20=E7=89=88=E6=9C=AC=E7=9A=84=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog_config.md | 6 ++++++ 1 file changed, 6 insertions(+) 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` 配置项,用于指定不希望记忆的词汇。 + +