From 0d11be7ade3971f466fefbdad661175444a59bd5 Mon Sep 17 00:00:00 2001 From: Asankilp Date: Fri, 25 Oct 2024 00:32:53 +0800 Subject: [PATCH] =?UTF-8?q?v0.3.2=EF=BC=8C=E5=AE=9E=E7=8E=B0nickname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- marshoai/__plugin__.py | 25 +++++++++++++++++++++++-- marshoai/constants.py | 5 ++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/marshoai/__plugin__.py b/marshoai/__plugin__.py index e0b24dc..45da596 100644 --- a/marshoai/__plugin__.py +++ b/marshoai/__plugin__.py @@ -45,6 +45,20 @@ async def reset(event: Union[GroupMessageEvent, PrivateMessageEvent]): context.reset(get_target_id(event), event.is_private) await send_text("上下文已重置") +@on_start_match("nickname") +async def nickname(event: MessageEvent): + nicknames = await get_nicknames() + user_id = str(event.sender.user_id) + name = event.text.lstrip("nickname ") + if not name: + await send_text("你的昵称为:"+str(nicknames[user_id])) + return + if name == "reset": + await set_nickname(user_id, "") + await send_text("已重置昵称") + else: + await set_nickname(user_id, name) + await send_text("已设置昵称为:"+name) @on_start_match("marsho") async def marsho(event: Union[GroupMessageEvent, PrivateMessageEvent]): @@ -60,8 +74,15 @@ async def marsho_main(event: Union[GroupMessageEvent, PrivateMessageEvent], is_g try: is_support_image_model = model_name.lower() in SUPPORT_IMAGE_MODELS usermsg = [] if is_support_image_model else "" - user_id = event.sender.user_id + user_id = str(event.sender.user_id) target_id = get_target_id(event) + nicknames = await get_nicknames() + nickname = nicknames.get(user_id, "") + if nickname != "": + nickname_prompt = f"\n*此消息的说话者:{nickname}*" + else: + nickname_prompt = "" + await send_text("*你未设置自己的昵称。推荐使用'nickname [昵称]'命令设置昵称来获得个性化(可能)回答。") nickname_prompt = "" marsho_string_removed = False for i in event.get_segments("image"): @@ -126,4 +147,4 @@ async def poke(event: PokeNotifyEvent, adapter: Adapter): # 尚未实现私聊 class MarshoAI(Plugin): version = VERSION - flows = [changemodel,marsho,reset,poke,contexts,praises] + flows = [changemodel,marsho,reset,poke,contexts,praises,nickname] diff --git a/marshoai/constants.py b/marshoai/constants.py index 918b679..e20b6f9 100644 --- a/marshoai/constants.py +++ b/marshoai/constants.py @@ -1,16 +1,15 @@ -__version__ = "0.3.1.1" +__version__ = "0.3.2" VERSION = __version__ PLUGIN_NAME = "marshoai" USAGE: str = f"""MarshoAI-Melobot Beta v{__version__} by Asankilp 用法: marsho <聊天内容> : 与 Marsho 进行对话。当模型为 GPT-4o(-mini) 等时,可以带上图片进行对话。 + nickname [昵称] : 为自己设定昵称,设置昵称后,Marsho 会根据你的昵称进行回答。使用'nickname reset'命令可清除自己设定的昵称。 reset : 重置当前会话的上下文。 超级用户命令(均需要加上命令前缀使用): /changemodel <模型名> : 切换全局 AI 模型。 /contexts : 返回当前会话的上下文列表。 ※当上下文包含图片时,不要使用此命令。 /praises : 返回夸赞名单的提示词。 - - ※本AI的回答"按原样"提供,不提供任何担保。AI也会犯错,请仔细甄别回答的准确性。""" SUPPORT_IMAGE_MODELS: list = ["gpt-4o","gpt-4o-mini","llama-3.2-90b-vision-instruct","llama-3.2-11b-vision-instruct"]