Skip to content

Commit

Permalink
新增kook平台的独立接口:设置在玩游戏/听音乐状态
Browse files Browse the repository at this point in the history
red协议消息类型修改为`olivos_para`
  • Loading branch information
lunzhiPenxil committed Oct 17, 2023
1 parent 8426933 commit 8270942
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 4 deletions.
18 changes: 18 additions & 0 deletions OlivOS/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions OlivOS/contentAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
196 changes: 193 additions & 3 deletions OlivOS/kaiheilaSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
'direct-message': '/direct-message',
'user': '/user',
'gateway': '/gateway',
'asset': '/asset'
'asset': '/asset',
'game': '/game'
}

sdkAPIRouteTemp = {}
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion OlivOS/messageAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 8270942

Please sign in to comment.