Skip to content

Commit

Permalink
优化接口支持
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Nov 18, 2021
1 parent 37116d9 commit 4332e41
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
36 changes: 24 additions & 12 deletions OlivOS/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def do_init_log(self):
])
elif self.plugin_info['func_type'] == 'group_message':
tmp_host_id = '-'
if self.data.extend['host_group_id'] != None:
tmp_host_id = str(self.data.extend['host_group_id'])
if self.data.host_id != None:
tmp_host_id = str(self.data.host_id)
tmp_globalMetaTableTemp_patch = OlivOS.metadataAPI.getPairMapping([
['host_id', tmp_host_id],
['group_id', self.data.group_id],
Expand Down Expand Up @@ -291,6 +291,7 @@ def __init__(self, user_id, message, sub_type, flag_lazy = True):
class group_message(object):
def __init__(self, group_id, user_id, message, sub_type, flag_lazy = True):
self.sub_type = sub_type
self.host_id = None
self.group_id = group_id
self.message = message
self.message_sdk = message
Expand Down Expand Up @@ -505,7 +506,7 @@ def __reply(self, message, flag_log = True):
'group_message'
]
):
self.__send('group', self.data.group_id, tmp_message, host_id = self.data.extend['host_group_id'], flag_log = False)
self.__send('group', self.data.group_id, tmp_message, host_id = self.data.host_id, flag_log = False)
flag_type = 'group'
elif checkByListOrEqual(
self.plugin_info['func_type'],
Expand Down Expand Up @@ -555,18 +556,19 @@ def __reply(self, message, flag_log = True):
'group_message'
]
):
if self.data.extend['host_group_id'] != None:
self.log_func(2, 'Host(' + str(self.data.extend['host_group_id']) + ') Group(' + str(self.data.group_id) + '): ' + tmp_message_log, [
if self.data.host_id != None:
self.log_func(2, 'Host(' + str(self.data.host_id) + ') Group(' + str(self.data.group_id) + '): ' + tmp_message_log, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('reply', 'callback')
])
return
self.log_func(2, 'Group(' + str(self.data.group_id) + '): ' + tmp_message_log, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('reply', 'callback')
])
else:
self.log_func(2, 'Group(' + str(self.data.group_id) + '): ' + tmp_message_log, [
(self.platform['platform'], 'default'),
(self.plugin_info['name'], 'default'),
('reply', 'callback')
])

def reply(self, message, flag_log = True, remote = False):
if remote:
Expand All @@ -585,7 +587,14 @@ def __send(self, send_type, target_id, message, host_id = None, flag_log = True)
return
if self.platform['sdk'] == 'onebot':
if flag_type == 'private':
OlivOS.onebotSDK.event_action.send_private_msg(self, target_id, tmp_message)
if 'host_id' in self.data.__dict__:
if self.data.host_id != None:
#此处缺少接口
pass
else:
OlivOS.onebotSDK.event_action.send_private_msg(self, target_id, tmp_message)
else:
OlivOS.onebotSDK.event_action.send_private_msg(self, target_id, tmp_message)
elif flag_type == 'group':
if host_id != None:
OlivOS.onebotSDK.event_action.send_guild_channel_msg(self, host_id, target_id, tmp_message)
Expand All @@ -600,7 +609,10 @@ def __send(self, send_type, target_id, message, host_id = None, flag_log = True)
OlivOS.fanbookSDK.event_action.send_msg(self, target_id, tmp_message)
elif self.platform['sdk'] == 'dodo_poll':
if flag_type == 'private':
OlivOS.dodoSDK.event_action.send_private_msg(self, target_id, tmp_message)
if host_id != None:
OlivOS.dodoSDK.event_action.send_private_msg(self, host_id, target_id, tmp_message)
else:
OlivOS.dodoSDK.event_action.send_private_msg(self, self.data.host_id, target_id, tmp_message)
elif flag_type == 'group':
OlivOS.dodoSDK.event_action.send_msg(self, target_id, tmp_message)
elif self.platform['sdk'] == 'dodobot_ea':
Expand Down
7 changes: 4 additions & 3 deletions OlivOS/dodoSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def get_Event_from_SDK(target_event):
target_event.data.sender['sex'] = 'unknown'
target_event.data.sender['age'] = 0
if target_event.sdk_event.islandId != None:
target_event.data.host_id = target_event.sdk_event.islandId
target_event.data.extend['host_group_id'] = target_event.sdk_event.islandId

#支持OlivOS API调用的方法实现
Expand Down Expand Up @@ -205,10 +206,10 @@ def send_msg(target_event, chat_id, message):
if this_msg.data.resourceJson != '{}':
this_msg.do_api()

def send_private_msg(target_event, chat_id, message):
def send_private_msg(target_event, host_id, chat_id, message):
this_msg = API.sendMessagePrivate(get_SDK_bot_info_from_Event(target_event))
if target_event.data.extend['host_group_id'] != None:
this_msg.data.islandId = target_event.data.extend['host_group_id']
if host_id != None:
this_msg.data.islandId = host_id
this_msg.data.toUid = chat_id
this_msg.data.content = ''
for message_this in message.data:
Expand Down
2 changes: 2 additions & 0 deletions OlivOS/fanbookSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def get_Event_from_SDK(target_event):
target_event.data.sender['nickname'] = target_event.sdk_event.json['channel_post']['from']['first_name']
target_event.data.sender['sex'] = 'unknown'
target_event.data.sender['age'] = 0
target_event.data.host_id = target_event.sdk_event.json['channel_post']['chat']['guild_id']
target_event.data.extend['host_group_id'] = target_event.sdk_event.json['channel_post']['chat']['guild_id']

#支持OlivOS API调用的方法实现
class event_action(object):
Expand Down
7 changes: 6 additions & 1 deletion OlivOS/onebotSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,13 @@ def get_Event_from_SDK(target_event):
target_event.data.raw_message_sdk = OlivOS.messageAPI.Message_templet('old_string', target_event.sdk_event.json['message'])
target_event.data.font = None
target_event.data.sender.update(target_event.sdk_event.json['sender'])
if 'guild_id' in target_event.sdk_event.json != None:
if 'guild_id' in target_event.sdk_event.json:
target_event.data.host_id = target_event.sdk_event.json['guild_id']
target_event.data.extend['host_group_id'] = target_event.sdk_event.json['guild_id']
if 'self_tiny_id' in target_event.sdk_event.json:
target_event.data.extend['sub_self_id'] = target_event.sdk_event.json['self_tiny_id']
if target_event.sdk_event.json['user_id'] == target_event.sdk_event.json['self_tiny_id']:
target_event.active = False
elif target_event.base_info['type'] == 'notice':
if target_event.sdk_event.json['notice_type'] == 'group_upload':
target_event.active = True
Expand Down

0 comments on commit 4332e41

Please sign in to comment.