From 82709423f80530ce8305cfa82feb16ea156a587f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=91=E8=B4=A8?= Date: Tue, 17 Oct 2023 15:43:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ekook=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E7=9A=84=E7=8B=AC=E7=AB=8B=E6=8E=A5=E5=8F=A3=EF=BC=9A=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=9C=A8=E7=8E=A9=E6=B8=B8=E6=88=8F/=E5=90=AC?= =?UTF-8?q?=E9=9F=B3=E4=B9=90=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit red协议消息类型修改为`olivos_para` --- OlivOS/API.py | 18 ++++ OlivOS/contentAPI.py | 5 ++ OlivOS/kaiheilaSDK.py | 196 +++++++++++++++++++++++++++++++++++++++++- OlivOS/messageAPI.py | 2 +- 4 files changed, 217 insertions(+), 4 deletions(-) diff --git a/OlivOS/API.py b/OlivOS/API.py index 79496c9d..cafd573e 100644 --- a/OlivOS/API.py +++ b/OlivOS/API.py @@ -111,6 +111,18 @@ def getMenuEvent(target_event): pass +class inde_interface_T(object): + def __init__(self, event, platform:str): + self.platform = platform + self.event = event + + def hasAPI(self, api_name): + res = False + if hasattr(self, api_name): + res = True + return res + + class Event(object): def __init__(self, sdk_event=None, log_func=None, Proc=None): self.bot_info = None @@ -147,10 +159,16 @@ def __init__(self, sdk_event=None, log_func=None, Proc=None): self.plugin_info['control_queue'] = Proc.Proc_info.control_queue if type(self.log_func) is None: self.log_func = Proc.log + self.indeAPI = None self.get_Event_from_SDK() self.get_Event_on_Plugin() + self.__init_inde_interface() self.do_init_log() + def __init_inde_interface(self): + if self.platform['sdk'] == 'kaiheila_link': + self.indeAPI = OlivOS.kaiheilaSDK.inde_interface(self, self.platform['platform']) + def get_Event_from_SDK(self): if self.sdk_event_type is OlivOS.virtualTerminalSDK.event: OlivOS.virtualTerminalSDK.get_Event_from_SDK(self) diff --git a/OlivOS/contentAPI.py b/OlivOS/contentAPI.py index ed363bfb..1b67046f 100644 --- a/OlivOS/contentAPI.py +++ b/OlivOS/contentAPI.py @@ -29,6 +29,11 @@ def __init__(self, arg): class api_result_data_template(object): + class universal_result(dict): + def __init__(self): + self['active'] = False + self['data'] = {} + class get_msg(dict): def __init__(self): self['active'] = False diff --git a/OlivOS/kaiheilaSDK.py b/OlivOS/kaiheilaSDK.py index 62775d11..6dfbe685 100644 --- a/OlivOS/kaiheilaSDK.py +++ b/OlivOS/kaiheilaSDK.py @@ -39,7 +39,8 @@ 'direct-message': '/direct-message', 'user': '/user', 'gateway': '/gateway', - 'asset': '/asset' + 'asset': '/asset', + 'game': '/game' } sdkAPIRouteTemp = {} @@ -308,6 +309,88 @@ def do_api(self, req_type='POST', file_type: str = ['.png', 'image/png']): traceback.print_exc() return None + #在玩游戏相关接口 + class getPlayGameList(api_templet): + def __init__(self, bot_info=None): + api_templet.__init__(self) + self.bot_info = bot_info + self.data = None + self.metadata = None + self.host = sdkAPIHost['default'] + self.route = sdkAPIRoute['game'] + + class setPlayGameCreate(api_templet): + def __init__(self, bot_info=None): + api_templet.__init__(self) + self.bot_info = bot_info + self.data = self.data_T() + self.metadata = None + self.host = sdkAPIHost['default'] + self.route = sdkAPIRoute['game'] + '/create' + + class data_T(object): + def __init__(self): + self.name = "N/A" + self.icon = None + + class setPlayGameUpdate(api_templet): + def __init__(self, bot_info=None): + api_templet.__init__(self) + self.bot_info = bot_info + self.data = self.data_T() + self.metadata = None + self.host = sdkAPIHost['default'] + self.route = sdkAPIRoute['game'] + '/update' + + class data_T(object): + def __init__(self): + self.id = -1 + self.name = None + self.icon = None + + class setPlayGameDelete(api_templet): + def __init__(self, bot_info=None): + api_templet.__init__(self) + self.bot_info = bot_info + self.data = self.data_T() + self.metadata = None + self.host = sdkAPIHost['default'] + self.route = sdkAPIRoute['game'] + '/delete' + + class data_T(object): + def __init__(self): + self.id = -1 + + class setPlayGameActivity(api_templet): + def __init__(self, bot_info=None): + api_templet.__init__(self) + self.bot_info = bot_info + self.data = self.data_T() + self.metadata = None + self.host = sdkAPIHost['default'] + self.route = sdkAPIRoute['game'] + '/activity' + + class data_T(object): + def __init__(self): + self.id = -1 + self.data_type = 1 + self.software = None + self.singer = None + self.music_name = None + + class setPlayGameDeleteActivity(api_templet): + def __init__(self, bot_info=None): + api_templet.__init__(self) + self.bot_info = bot_info + self.data = self.data_T() + self.metadata = None + self.host = sdkAPIHost['default'] + self.route = sdkAPIRoute['game'] + '/delete-activity' + + class data_T(object): + def __init__(self): + self.data_type = 1 + def get_kmarkdown_message_raw(data: dict): res = data['raw_content'] @@ -657,6 +740,115 @@ def setResourceUploadFast(target_event, url: str, type_path: str = 'images'): res = None return res + def set_playgame_delete_activity(target_event, data_type:int): + raw_obj = None + res_data = OlivOS.contentAPI.api_result_data_template.universal_result() + this_msg = API.setPlayGameDeleteActivity(get_SDK_bot_info_from_Event(target_event)) + this_msg.data.data_type = data_type + try: + this_msg.do_api('POST') + if this_msg.res is not None: + raw_obj = init_api_json(this_msg.res) + if raw_obj is not None: + if type(raw_obj) is dict: + res_data['active'] = True + except: + res_data['active'] = False + return res_data + return res_data + + def set_playgame_delete_activity_all(target_event): + res_data = OlivOS.contentAPI.api_result_data_template.universal_result() + res_data['active'] = False + for i in [1, 2]: + res_data = event_action.set_playgame_delete_activity(target_event, i) + if not res_data['active']: + return res_data + return res_data + + def set_playgame_activity_game(target_event, game_id): + raw_obj = None + res_data = OlivOS.contentAPI.api_result_data_template.universal_result() + res_data['active'] = False + res_data = event_action.set_playgame_delete_activity_all(target_event) + if not res_data['active']: + return res_data + res_data = OlivOS.contentAPI.api_result_data_template.universal_result() + this_msg = API.setPlayGameActivity(get_SDK_bot_info_from_Event(target_event)) + this_msg.data.data_type = 1 + this_msg.data.id = game_id + try: + this_msg.do_api('POST') + if this_msg.res is not None: + raw_obj = init_api_json(this_msg.res) + if raw_obj is not None: + if type(raw_obj) is dict: + res_data['active'] = True + except: + res_data['active'] = False + return res_data + return res_data + + def set_playgame_activity_music(target_event, music_name, singer, software): + raw_obj = None + res_data = OlivOS.contentAPI.api_result_data_template.universal_result() + res_data['active'] = False + res_data = event_action.set_playgame_delete_activity_all(target_event) + if not res_data['active']: + return res_data + res_data = OlivOS.contentAPI.api_result_data_template.universal_result() + this_msg = API.setPlayGameActivity(get_SDK_bot_info_from_Event(target_event)) + this_msg.data.data_type = 2 + this_msg.data.id = None + this_msg.data.software = software + this_msg.data.music_name = music_name + this_msg.data.singer = singer + try: + this_msg.do_api('POST') + if this_msg.res is not None: + raw_obj = init_api_json(this_msg.res) + if raw_obj is not None: + if type(raw_obj) is dict: + res_data['active'] = True + except: + res_data['active'] = False + return res_data + +class inde_interface(OlivOS.API.inde_interface_T): + @OlivOS.API.Event.callbackLogger('kaiheila:set_playgame_activity_game') + def __set_playgame_activity_game(target_event, game_id, flag_log=True): + res_data = None + res_data = OlivOS.kaiheilaSDK.event_action.set_playgame_activity_game(target_event, game_id) + return res_data + + def set_playgame_activity_game(self, game_id:int, flag_log: bool = True, remote: bool = False): + res_data = None + if remote: + pass + else: + res_data = inde_interface.__set_playgame_activity_game(self.event, game_id, flag_log=True) + return res_data + + @OlivOS.API.Event.callbackLogger('kaiheila:set_playgame_activity_music') + def __set_playgame_activity_music(target_event, music_name, singer, software, flag_log=True): + res_data = None + res_data = OlivOS.kaiheilaSDK.event_action.set_playgame_activity_music(target_event, music_name, singer, software) + return res_data + + def set_playgame_activity_music( + self, + music_name:str, + singer:str, + software:str = 'cloudmusic', + flag_log: bool = True, + remote: bool = False + ): + res_data = None + if remote: + pass + else: + res_data = inde_interface.__set_playgame_activity_music(self.event, music_name, singer, software, flag_log=True) + return res_data def init_api_json(raw_str): res_data = None @@ -672,8 +864,6 @@ def init_api_json(raw_str): if flag_is_active: if type(tmp_obj) == dict: res_data = tmp_obj.copy() - elif type(tmp_obj) == list: - res_data = tmp_obj.copy() return res_data diff --git a/OlivOS/messageAPI.py b/OlivOS/messageAPI.py index 0e3305a9..007349db 100644 --- a/OlivOS/messageAPI.py +++ b/OlivOS/messageAPI.py @@ -32,7 +32,7 @@ 'onebot': { 'default': 'old_string', 'onebotV12': 'obv12_para', - 'red': 'obv12_para', + 'red': 'olivos_para', 'gocqhttp': 'old_string', 'gocqhttp_hide': 'old_string', 'gocqhttp_show': 'old_string',