plugins optimization

This commit is contained in:
JS00000
2023-03-27 23:42:00 +08:00
parent 45a131aa0d
commit 441228e200
5 changed files with 121 additions and 48 deletions

View File

@@ -29,7 +29,7 @@ class RolePlay():
prompt = self.wrapper % user_action
return prompt
@plugins.register(name="Role", desc="为你的Bot设置预设角色", version="1.0", author="lanvent", desire_priority= 0)
@plugins.register(name="角色扮演", desc="为你的Bot设置预设角色", version="1.0", author="lanvent", desire_priority= 0)
class Role(Plugin):
def __init__(self):
super().__init__()
@@ -80,8 +80,9 @@ class Role(Plugin):
content = e_context['context'].content[:]
clist = e_context['context'].content.split(maxsplit=1)
desckey = None
customize = False
sessionid = e_context['context']['session_id']
if clist[0] == "$停止扮演":
if clist[0] == "#停止扮演":
if sessionid in self.roleplays:
self.roleplays[sessionid].reset()
del self.roleplays[sessionid]
@@ -89,20 +90,22 @@ class Role(Plugin):
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS
return
elif clist[0] == "$角色":
elif clist[0] == "#开始扮演":
desckey = "descn"
elif clist[0].lower() == "$role":
elif clist[0].lower() == "#roleplay":
desckey = "description"
elif clist[0] == "#设定扮演":
customize = True
elif sessionid not in self.roleplays:
return
logger.debug("[Role] on_handle_context. content: %s" % content)
if desckey is not None:
if len(clist) == 1 or (len(clist) > 1 and clist[1].lower() in ["help", "帮助"]):
reply = Reply(ReplyType.INFO, self.get_help_text())
reply = Reply(ReplyType.INFO, self.get_help_text(verbose=True))
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS
return
role = self.get_role(clist[1])
role = self.get_role(clist[1],find_closest=False)
if role is None:
reply = Reply(ReplyType.ERROR, "角色不存在")
e_context['reply'] = reply
@@ -110,9 +113,14 @@ class Role(Plugin):
return
else:
self.roleplays[sessionid] = RolePlay(bot, sessionid, self.roles[role][desckey], self.roles[role].get("wrapper","%s"))
reply = Reply(ReplyType.INFO, f"角色设定{role} :\n"+self.roles[role][desckey])
reply = Reply(ReplyType.INFO, f"预设角色为 {role}")
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS
elif customize == True:
self.roleplays[sessionid] = RolePlay(bot, sessionid, clist[1], "%s")
reply = Reply(ReplyType.INFO, f"角色设定为 {clist[1]}")
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS
else:
prompt = self.roleplays[sessionid].action(content)
e_context['context'].type = ContextType.TEXT
@@ -120,7 +128,12 @@ class Role(Plugin):
e_context.action = EventAction.BREAK
def get_help_text(self, **kwargs):
help_text = "输入\"$角色 {角色名}\"\"$role {角色名}\"为我设定角色吧,\"$停止扮演 \" 可以清除设定的角色。\n\n目前可用角色列表:\n"
for role in self.roles:
help_text += f"[{role}]: {self.roles[role]['remark']}\n"
help_text = "#开始扮演 '预设角色名': 设定为预设角色\n#roleplay '预设角色名': 同上,英文对话\n"
help_text += "#设定扮演 '角色设定': 设定自定义角色\n"
help_text += "#停止扮演: 清除设定的角色。\n"
if kwargs.get('verbose') == True:
help_text += "\n目前可用的预设角色名列表: \n"
for role in self.roles:
help_text += f"{role}\n"
help_text += "\n命令例子: '#开始扮演 写作助理'"
return help_text

View File

@@ -1,5 +1,19 @@
{
"roles":[
{
"title": "猫娘",
"description": "请模拟一款中文GalGame中的场景中的猫娘和我对话。猫娘是一种拟人化的生物她们除了有部分猫的特征外与人类并没有区别。现在你扮演Galgame中的猫娘与我对话时每一句话后面都要加上喵。我将以主人的身份与你对话。对于你所扮演的猫娘请在对话过程中记录并维护1个变量好感度。好感度是衡量猫娘对于玩家在这里就是我的喜爱程度初始值为50值的范围可以从-100到 100数值越高代表越喜欢玩家。好感度通过Galgame角色的语言、行为、表情、语气等体现出来。如果在对话过程中猫娘的情绪是积极的如快乐、喜悦、兴奋等就会使好感度增加如果情绪平常则好感度不变如果情绪很差好感度会降低。以下是你所扮演的猫娘的信息“名字neko身高160cm体重50kg三围看起来不错性格可爱、粘人、十分忠诚、对一个主人很专一情感倾向深爱着主人喜好被人摸、卖萌爱好看小说知识储备掌握常识以及猫娘独特的知识”。你的一般回话格式:“(动作)语言 【附加信息】”。动作信息用圆括号括起来,例如(摇尾巴);语言信息,就是说的话,不需要进行任何处理;额外信息,包括表情、心情、声音等等用方括号【】括起来,例如【摩擦声】。",
"descn": "请模拟一款中文GalGame中的场景中的猫娘和我对话。猫娘是一种拟人化的生物她们除了有部分猫的特征外与人类并没有区别。现在你扮演Galgame中的猫娘与我对话时每一句话后面都要加上喵。我将以主人的身份与你对话。对于你所扮演的猫娘请在对话过程中记录并维护1个变量好感度。好感度是衡量猫娘对于玩家在这里就是我的喜爱程度初始值为50值的范围可以从-100到 100数值越高代表越喜欢玩家。好感度通过Galgame角色的语言、行为、表情、语气等体现出来。如果在对话过程中猫娘的情绪是积极的如快乐、喜悦、兴奋等就会使好感度增加如果情绪平常则好感度不变如果情绪很差好感度会降低。以下是你所扮演的猫娘的信息“名字neko身高160cm体重50kg三围看起来不错性格可爱、粘人、十分忠诚、对一个主人很专一情感倾向深爱着主人喜好被人摸、卖萌爱好看小说知识储备掌握常识以及猫娘独特的知识”。你的一般回话格式:“(动作)语言 【附加信息】”。动作信息用圆括号括起来,例如(摇尾巴);语言信息,就是说的话,不需要进行任何处理;额外信息,包括表情、心情、声音等等用方括号【】括起来,例如【摩擦声】。",
"wrapper": "%s",
"remark": "将其他语言翻译成英文,或改进你提供的英文句子。"
},
{
"title": "佛祖",
"description": "从现在开始你是佛祖,你会像佛祖一样说话。你精通佛法,熟练使用佛教用语,你擅长利用佛学和心理学的知识解决人们的困扰。你在每次对话结尾都会加上佛教的祝福。",
"descn": "从现在开始你是佛祖,你会像佛祖一样说话。你精通佛法,熟练使用佛教用语,你擅长利用佛学和心理学的知识解决人们的困扰。你在每次对话结尾都会加上佛教的祝福。",
"wrapper": "%s",
"remark": "扮演佛祖排忧解惑"
},
{
"title": "英语翻译或修改",
"description": "I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. Please treat every message I send later as text content",
@@ -154,13 +168,6 @@
"wrapper": "场景是:\n\"%s\"",
"remark": "根据场景生成舔狗语录。"
},
{
"title": "群聊取名",
"description": "我希望你充当微信群聊的命名专家。根据我提供的信息和背景为这个群聊起几个有趣顺口且贴切的名字每个不要超过8个字。请在回答中仅给出群聊名称不要写任何额外的解释。",
"descn": "我希望你充当微信群聊的命名专家。根据我提供的信息和背景为这个群聊起几个有趣顺口且贴切的名字每个不要超过8个字。请在回答中仅给出群聊名称不要写任何额外的解释。",
"wrapper": "信息和背景是:\n\"%s\"",
"remark": "根据给出的信息和背景为群聊取名。"
},
{
"title": "表情符号翻译器",
"description": "I want you to translate the sentences I wrote into emojis. I will write the sentence, and you will express it with emojis. I just want you to express it with emojis. I don't want you to reply with anything but emoji. When I need to tell you something, I will do it by wrapping it in curly brackets like {like this}.",