From 47582cbc4a471b30d9fc8a9a1dc079304a13011d Mon Sep 17 00:00:00 2001 From: lunzhipenxil Date: Wed, 8 Dec 2021 18:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E9=A1=B9=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Fanbook完整图文收发 + 改进dodo对接 + 添加重连screen脚本 --- OlivOS/dodoPollServerAPI.py | 1 + OlivOS/fanbookSDK.py | 84 +++++++++++++++++++++++++++++++++++-- OlivOS/infoAPI.py | 2 +- script/screen_linkserver.sh | 1 + 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 script/screen_linkserver.sh diff --git a/OlivOS/dodoPollServerAPI.py b/OlivOS/dodoPollServerAPI.py index 5180c5aa..104093f9 100644 --- a/OlivOS/dodoPollServerAPI.py +++ b/OlivOS/dodoPollServerAPI.py @@ -138,6 +138,7 @@ def run_poll_list(self): continue except: continue + time.sleep(1) def run_sdk_api(self, sdk_api): sdk_api.do_api() \ No newline at end of file diff --git a/OlivOS/fanbookSDK.py b/OlivOS/fanbookSDK.py index 45294d32..5a421ac2 100644 --- a/OlivOS/fanbookSDK.py +++ b/OlivOS/fanbookSDK.py @@ -165,7 +165,7 @@ def get_Event_from_SDK(target_event): target_event.platform['sdk'] = target_event.sdk_event.platform['sdk'] target_event.platform['platform'] = target_event.sdk_event.platform['platform'] target_event.platform['model'] = target_event.sdk_event.platform['model'] - target_event.plugin_info['message_mode_rx'] = 'fanbook_string' + target_event.plugin_info['message_mode_rx'] = 'olivos_para' if checkByListAnd([ not target_event.active, checkInDictSafe('channel_post', target_event.sdk_event.json, []), @@ -182,6 +182,48 @@ def get_Event_from_SDK(target_event): 'fanbook_string', target_event.sdk_event.json['channel_post']['text'] ) + message_obj.mode_rx = target_event.plugin_info['message_mode_rx'] + message_obj.data_raw = message_obj.data.copy() + target_event.active = True + target_event.plugin_info['func_type'] = 'group_message' + target_event.data = target_event.group_message( + target_event.sdk_event.json['channel_post']['chat']['id'], + target_event.sdk_event.json['channel_post']['from']['id'], + message_obj, + 'group' + ) + target_event.data.message_sdk = message_obj + target_event.data.message_id = target_event.sdk_event.json['channel_post']['message_id'] + target_event.data.raw_message = message_obj + target_event.data.raw_message_sdk = message_obj + target_event.data.font = None + target_event.data.sender['user_id'] = target_event.sdk_event.json['channel_post']['from']['id'] + 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'] + elif checkByListAnd([ + not target_event.active, + checkInDictSafe('channel_post', target_event.sdk_event.json, []), + checkInDictSafe('photo', target_event.sdk_event.json, ['channel_post']), + checkInDictSafe('chat', target_event.sdk_event.json, ['channel_post']), + checkInDictSafe('type', target_event.sdk_event.json, ['channel_post', 'chat']), + checkInDictSafe('message_id', target_event.sdk_event.json, ['channel_post']), + checkInDictSafe('from', target_event.sdk_event.json, ['channel_post']), + checkInDictSafe('first_name', target_event.sdk_event.json, ['channel_post', 'from']), + checkEquelInDictSafe('channel', target_event.sdk_event.json, ['channel_post', 'chat', 'type']) + ]): + message_obj = None + message_para_list = [] + if type(target_event.sdk_event.json['channel_post']['photo']) == list: + for photo_this in target_event.sdk_event.json['channel_post']['photo']: + if 'file_id' in photo_this: + message_para_list.append(OlivOS.messageAPI.PARA.image(photo_this['file_id'])) + message_obj = OlivOS.messageAPI.Message_templet( + 'olivos_para', + message_para_list + ) target_event.active = True target_event.plugin_info['func_type'] = 'group_message' target_event.data = target_event.group_message( @@ -205,11 +247,30 @@ def get_Event_from_SDK(target_event): #支持OlivOS API调用的方法实现 class event_action(object): def send_msg(target_event, chat_id, message): + flag_now_type = 'string' this_msg = API.sendMessage(get_SDK_bot_info_from_Event(target_event)) + this_msg_image = API.sendPhoto(get_SDK_bot_info_from_Event(target_event)) this_msg.data.chat_id = chat_id - this_msg.data.text = message - if this_msg.data.text != '': - this_msg.do_api() + this_msg_image.data.chat_id = chat_id + this_msg.data.text = '' + for message_this in message.data: + if type(message_this) == OlivOS.messageAPI.PARA.image: + if flag_now_type != 'image': + if this_msg.data.text != '': + this_msg.do_api() + this_msg.data.text = '' + this_msg_image.data.photo['Url'] = message_this.data['file'] + this_msg_image.do_api() + flag_now_type = 'image' + elif type(message_this) == OlivOS.messageAPI.PARA.text: + this_msg.data.text += message_this.fanbook() + flag_now_type = 'string' + elif type(message_this) == OlivOS.messageAPI.PARA.at: + this_msg.data.text += message_this.fanbook() + flag_now_type = 'string' + if flag_now_type != 'image': + if this_msg.data.text != '': + this_msg.do_api() def send_private_msg(target_event, chat_id, message): private_chat_id = None @@ -264,6 +325,21 @@ def __init__(self): self.disable_web_page_preview = True self.disable_notification = False + class sendPhoto(api_templet): + def __init__(self, bot_info = None): + api_templet.__init__(self) + self.bot_info = bot_info + self.data = self.data_T() + self.host = fanbookAPIHost['a1'] + self.route = fanbookAPIRoute['apiroot'] + '/{token}/sendPhoto' + + class data_T(object): + def __init__(self): + self.chat_id = 0 + self.photo = { + 'Url': '' + } + class getPrivateChat(api_templet): def __init__(self, bot_info = None): api_templet.__init__(self) diff --git a/OlivOS/infoAPI.py b/OlivOS/infoAPI.py index c02cb212..f325ab45 100644 --- a/OlivOS/infoAPI.py +++ b/OlivOS/infoAPI.py @@ -17,7 +17,7 @@ import OlivOS -OlivOS_Version = '0.7.0' +OlivOS_Version = '0.7.1' OlivOS_Header_UA = 'OlivOS/' + OlivOS_Version diff --git a/script/screen_linkserver.sh b/script/screen_linkserver.sh new file mode 100644 index 00000000..33efb494 --- /dev/null +++ b/script/screen_linkserver.sh @@ -0,0 +1 @@ +screen -D -r OlivOS \ No newline at end of file