From 02f83ffffdfdf32b4abef95628616ac4032468d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=91=E8=B4=A8?= Date: Tue, 2 Jan 2024 16:41:01 +0800 Subject: [PATCH] =?UTF-8?q?3.0.1=EF=BC=8CKOOK=E6=96=B0=E5=A2=9E=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=8C=89=E9=92=AE=E8=BF=9B=E8=A1=8C=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OlivaStoryCore/app.json | 4 +- OlivaStoryCore/data.py | 4 +- OlivaStoryCore/msgReply.py | 82 ++++++++++++++++++++++++++++++++++---- 3 files changed, 79 insertions(+), 11 deletions(-) diff --git a/OlivaStoryCore/app.json b/OlivaStoryCore/app.json index 56e181c..44e9ee5 100644 --- a/OlivaStoryCore/app.json +++ b/OlivaStoryCore/app.json @@ -4,8 +4,8 @@ "namespace" : "OlivaStoryCore", "message_mode" : "old_string", "info" : "本模块为OlivaStory的核心模块,实现了文游引擎的主要功能。", - "version" : "3.0.0", - "svn" : 1, + "version" : "3.0.1", + "svn" : 2, "compatible_svn" : 101, "priority" : 20045, "support" : [ diff --git a/OlivaStoryCore/data.py b/OlivaStoryCore/data.py index ec2452f..b932a5b 100644 --- a/OlivaStoryCore/data.py +++ b/OlivaStoryCore/data.py @@ -15,8 +15,8 @@ ''' -OlivaStoryCore_ver = '3.0.0' -OlivaStoryCore_svn = 1 +OlivaStoryCore_ver = '3.0.1' +OlivaStoryCore_svn = 2 OlivaStoryCore_ver_short = '%s(%s)' % (str(OlivaStoryCore_ver), str(OlivaStoryCore_svn)) dataDirRoot = './plugin/data/OlivaStory' diff --git a/OlivaStoryCore/msgReply.py b/OlivaStoryCore/msgReply.py index 616ed19..0b7d4fd 100644 --- a/OlivaStoryCore/msgReply.py +++ b/OlivaStoryCore/msgReply.py @@ -18,6 +18,9 @@ import OlivaStoryCore import OlivaDiceCore +import traceback +import json + def logProc(Proc:OlivOS.pluginAPI.shallow, level, message, segment): Proc.log( log_level = level, @@ -222,12 +225,12 @@ def unity_reply(plugin_event, Proc): selectionIndex = tmp_go_index ) tmp_reply_str = getStoryTall( + plugin_event = plugin_event, dictStrCustom = dictStrCustom, dictTValue = dictTValue, nodeData = tmp_nodeData, noteList = tmp_noteList ) - replyMsg(plugin_event, tmp_reply_str) if OlivaStoryCore.storyEngine.isStoryEnd(tmp_nodeData): OlivaStoryCore.storyEngine.runStoryBySelectionIndex( botHash = tmp_botHash, @@ -247,13 +250,13 @@ def unity_reply(plugin_event, Proc): chatToken = tmp_chat_token ) tmp_reply_str = getStoryTall( + plugin_event = plugin_event, dictStrCustom = dictStrCustom, dictTValue = dictTValue, nodeData = tmp_nodeData, flagIsStart = True, noteList = tmp_noteList ) - replyMsg(plugin_event, tmp_reply_str) else: tmp_platform = plugin_event.platform['platform'] tmp_botHash = plugin_event.bot_info.hash @@ -292,13 +295,12 @@ def unity_reply(plugin_event, Proc): selectionIndex = 'ra' ) tmp_reply_str = getStoryTall( + plugin_event = plugin_event, dictStrCustom = dictStrCustom, dictTValue = dictTValue, nodeData = tmp_nodeData, noteList = tmp_noteList ) - if tmp_reply_str is not None: - replyMsg(plugin_event, tmp_reply_str) if OlivaStoryCore.storyEngine.isStoryEnd(tmp_nodeData): OlivaStoryCore.storyEngine.runStoryBySelectionIndex( botHash = tmp_botHash, @@ -338,13 +340,12 @@ def unity_reply(plugin_event, Proc): selectionIndex = tmp_go_index ) tmp_reply_str = getStoryTall( + plugin_event = plugin_event, dictStrCustom = dictStrCustom, dictTValue = dictTValue, nodeData = tmp_nodeData, noteList = tmp_noteList ) - if tmp_reply_str is not None: - replyMsg(plugin_event, tmp_reply_str) if OlivaStoryCore.storyEngine.isStoryEnd(tmp_nodeData): OlivaStoryCore.storyEngine.runStoryBySelectionIndex( botHash = tmp_botHash, @@ -368,12 +369,17 @@ def getNoteList( return res def getStoryTall( + plugin_event, dictStrCustom, dictTValue, nodeData, flagIsStart = False, noteList = None ): + selection_str_list = [] + tmp_platform = plugin_event.platform['platform'] + tmp_model = plugin_event.platform['model'] + replyMsg = OlivaDiceCore.msgReply.replyMsg res = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strStoryCoreStoryTallBreak'], dictTValue) if flagIsStart: res = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strStoryCoreStoryTallNone'], dictTValue) @@ -401,7 +407,9 @@ def getStoryTall( storyNoteList = noteList ) ): - tmp_selection_list.append(f"{i + 1} - {selection[i]['text']}") + tmp_str = f"{i + 1} - {selection[i]['text']}" + tmp_selection_list.append(tmp_str) + selection_str_list.append([f"{i + 1}", tmp_str]) if len(tmp_selection_list) > 0: dictTValue['tStoryCoreSelection'] = '选项如下:\n%s' % ('\n'.join(tmp_selection_list)) else: @@ -414,4 +422,64 @@ def getStoryTall( dictTValue['tStoryCoreSelection'] = '使用[.ra]指令完成检定以继续' dictTValue['tStoryCoreResult'] = nodeData.get('text', []) res = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strStoryCoreStoryTall'], dictTValue) + if res is not None: + replyMsg(plugin_event, res) + if len(selection_str_list) > 0: + if tmp_platform == 'kaiheila' \ + and tmp_model not in ['text']: + try: + if plugin_event.indeAPI.hasAPI('create_message'): + msg_button_list = [ + { + "type": "action-group", + "elements": [ + { + "type": "button", + "theme": "info", + "value": f'{selection_str[0]}', + "click": "return-val", + "text": { + "type": "plain-text", + "content": f'{selection_str[1]}' + } + } + ] + } for selection_str in selection_str_list + ] + msg_button_list.append( + { + "type": "context", + "elements": [ + { + "type": "plain-text", + "content": "OlivaDice - 青果核心掷骰机器人" + } + ] + } + ) + msg_list = [ + { + "type": "card", + "theme": "primary", + "color": "#009FE9", + "size": "lg", + "modules": msg_button_list + } + ] + if plugin_event.plugin_info['func_type'] == 'group_message': + plugin_event.indeAPI.create_message( + chat_type = 'group', + chat_id = plugin_event.data.group_id, + content_type = 10, + content = json.dumps(msg_list, ensure_ascii=False) + ) + elif plugin_event.plugin_info['func_type'] == 'private_message': + plugin_event.indeAPI.create_message( + chat_type = 'private', + chat_id = plugin_event.data.user_id, + content_type = 10, + content = json.dumps(msg_list, ensure_ascii=False) + ) + except Exception as e: + traceback.print_exc() return res