Skip to content

Commit

Permalink
重载接口
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Oct 14, 2021
1 parent b5a35a3 commit 9cda75d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 11 additions & 3 deletions OlivOS/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def __init__(self, sdk_event = None, log_func = None):
self.base_info['type'] = None
self.plugin_info = {}
self.plugin_info['func_type'] = None
self.plugin_info['name'] = 'unity'
self.plugin_info['namespace'] = 'unity'
self.sdk_event = sdk_event
self.sdk_event_type = type(self.sdk_event)
self.get_Event_from_SDK()
Expand Down Expand Up @@ -170,6 +172,7 @@ def do_init_log(self):
tmp_log_message = 'Interval(' + str(self.data.interval) + ')'
self.log_func(tmp_log_level, tmp_log_message, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
(self.plugin_info['func_type'], 'default')
])

Expand Down Expand Up @@ -325,6 +328,7 @@ def funcWarpped(*args, **kwargs):
callback_msg = 'done'
event_obj.log_func(2, callback_msg , [
(event_obj.platform['platform'], 'default'),
(event_obj.plugin_info['name'], 'default'),
(func_name, 'callback')
])
return warppedRes
Expand All @@ -339,6 +343,7 @@ def __set_block(self, enable, flag_log = True):
if flag_log:
self.log_func(2, str(enable) , [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('set_block', 'callback')
])

Expand Down Expand Up @@ -397,11 +402,13 @@ def __reply(self, message, flag_log = True):
if flag_type == 'private':
self.log_func(2, 'User(' + str(self.data.user_id) + '): ' + message, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('reply', 'callback')
])
elif flag_type == 'group':
self.log_func(2, 'Group(' + str(self.data.group_id) + '): ' + message, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('reply', 'callback')
])

Expand All @@ -426,11 +433,13 @@ def __send(self, send_type, target_id, message, flag_log = True):
if flag_type == 'private':
self.log_func(2, 'User(' + str(target_id) + '): ' + message, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('send', 'callback')
])
elif flag_type == 'group':
self.log_func(2, 'Group(' + str(target_id) + '): ' + message, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('send', 'callback')
])

Expand Down Expand Up @@ -674,11 +683,13 @@ def __get_login_info(self, flag_log = True):
if res_data['active'] == True:
self.log_func(2, 'name(' + res_data['data']['name'] + ') id(' + str(res_data['data']['id']) + ')' , [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('get_login_info', 'callback')
])
else:
self.log_func(2, 'failed' , [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('get_login_info', 'callback')
])
return res_data
Expand All @@ -699,9 +710,6 @@ def __get_stranger_info(self, user_id, no_cache, flag_log = True):
res_data = OlivOS.onebotSDK.event_action.get_stranger_info(self, user_id, no_cache)
elif self.platform['sdk'] == 'telegram_poll':
pass

if res_data == None:
return None
return res_data

def get_stranger_info(self, user_id, no_cache = False, flag_log = True, remote = False):
Expand Down
2 changes: 1 addition & 1 deletion OlivOS/diagnoseAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def log_output(self, log_packet_this):
if log_packet_this['log_level'] in self.Proc_config['logger_vis_level']:
if self.Proc_config['logger_mode'] == 'console':
log_output_str = ''
log_output_str += '[' + str(datetime.datetime.fromtimestamp(log_packet_this['log_time'])) + '] - '
log_output_str += '[' + str(datetime.datetime.fromtimestamp(int(log_packet_this['log_time']))) + '] - '
log_output_str += '[' + self.Proc_config['level_dict'][log_packet_this['log_level']] + ']' + ' - '
for segment_this in log_packet_this['log_segment']:
(segment_this_mark, segment_this_type) = segment_this
Expand Down
9 changes: 7 additions & 2 deletions OlivOS/pluginAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def run(self):
if self.Proc_config['enable_auto_restart']:
rx_count += 1
if rx_count == self.Proc_config['step_to_restart']:
self.log(2, 'OlivOS plugin shallow [' + self.Proc_name + '] call restart')
self.Proc_info.rx_queue.put(OlivOS.API.Control.packet('restart_do', self.Proc_name), block=False)
self.set_restart()

def set_restart(self):
self.log(2, 'OlivOS plugin shallow [' + self.Proc_name + '] call restart')
self.Proc_info.rx_queue.put(OlivOS.API.Control.packet('restart_do', self.Proc_name), block=False)

def run_plugin(self, sdk_event):
log_str_tmp = str(sdk_event.json)
Expand Down Expand Up @@ -127,9 +129,12 @@ def run_plugin(self, sdk_event):
if flag_support_found_dict['sdk'] and flag_support_found_dict['platform'] and flag_support_found_dict['model']:
flag_support_found_dict['flag'] = True
if flag_support_found_dict['flag']:
plugin_event.plugin_info['name'] = self.plugin_models_dict[plugin_models_index_this]['name']
plugin_event.plugin_info['namespace'] = self.plugin_models_dict[plugin_models_index_this]['namespace']
self.plugin_event_router(plugin_event, self.plugin_models_dict[plugin_models_index_this]['model'])
self.log(0, 'event [' + str(plugin_event.plugin_info['func_type']) + '] call plugin [' + self.plugin_models_dict[plugin_models_index_this]['name'] + '] done')
if plugin_event.blocked:
self.log(2, 'event [' + str(plugin_event.plugin_info['func_type']) + '] call blocked by plugin [' + self.plugin_models_dict[plugin_models_index_this]['name'] + ']')
break
return

Expand Down

0 comments on commit 9cda75d

Please sign in to comment.