Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发布0.11.25 Pypi版本 #107

Merged
merged 20 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
pyinstaller ./main_linux.spec
- name: Run artifact
run: |
mkdir OlivOS-PKG
Expand Down Expand Up @@ -374,7 +374,7 @@ jobs:
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
pyinstaller ./main_linux.spec
- name: Run artifact
run: |
mkdir OlivOS-PKG
Expand Down
10 changes: 10 additions & 0 deletions OlivOS/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ def get_Event_from_SDK(self):
OlivOS.contentAPI.get_Event_from_fake_SDK(self)
elif self.sdk_event_type is OlivOS.kaiheilaSDK.event:
OlivOS.kaiheilaSDK.get_Event_from_SDK(self)
elif self.sdk_event_type is OlivOS.mhyVilaSDK.event:
OlivOS.mhyVilaSDK.get_Event_from_SDK(self)
elif self.sdk_event_type is OlivOS.qqRedSDK.event:
OlivOS.qqRedSDK.get_Event_from_SDK(self)
elif self.sdk_event_type is OlivOS.hackChatSDK.event:
Expand Down Expand Up @@ -894,6 +896,14 @@ def __send(self, send_type, target_id, message, host_id=None, flag_log=True):
OlivOS.kaiheilaSDK.event_action.send_msg(self, target_id, tmp_message, flag_direct=False)
elif flag_type == 'private':
OlivOS.kaiheilaSDK.event_action.send_msg(self, target_id, tmp_message, flag_direct=True)
elif self.platform['sdk'] == 'mhyVila_link':
if flag_type == 'group':
if host_id is not None:
OlivOS.mhyVilaSDK.event_action.send_group_msg(self, target_id, tmp_message, host_id=host_id)
elif 'host_id' in self.data.__dict__:
OlivOS.mhyVilaSDK.event_action.send_group_msg(self, target_id, tmp_message, host_id=self.data.host_id)
elif flag_type == 'private':
pass
elif self.platform['sdk'] == 'hackChat_link':
OlivOS.hackChatSDK.event_action.send_msg(self, tmp_message, self.plugin_info['control_queue'])
elif self.platform['sdk'] == 'biliLive_link':
Expand Down
2 changes: 2 additions & 0 deletions OlivOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
from . import fanbookPollServerAPI
from . import kaiheilaSDK
from . import kaiheilaLinkServerAPI
from . import mhyVilaSDK
from . import mhyVilaLinkServerAPI
from . import biliLiveSDK
from . import biliLiveLinkServerAPI
from . import updateAPI
Expand Down
22 changes: 22 additions & 0 deletions OlivOS/bootAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,28 @@ def start(self):
)
Proc_Proc_dict[tmp_Proc_name] = Proc_dict[tmp_Proc_name].start_unity(
tmp_proc_mode)
elif basic_conf_models_this['type'] == 'mhyVila_link':
flag_need_enable = False
for bot_info_key in plugin_bot_info_dict:
if plugin_bot_info_dict[bot_info_key].platform['sdk'] == 'mhyVila_link':
flag_need_enable = True
if not flag_need_enable:
continue
for bot_info_key in plugin_bot_info_dict:
if plugin_bot_info_dict[bot_info_key].platform['sdk'] == 'mhyVila_link':
tmp_Proc_name = basic_conf_models_this['name'] + '=' + bot_info_key
Proc_dict[tmp_Proc_name] = OlivOS.mhyVilaLinkServerAPI.server(
Proc_name=tmp_Proc_name,
scan_interval=basic_conf_models_this['interval'],
dead_interval=basic_conf_models_this['dead_interval'],
rx_queue=None,
tx_queue=multiprocessing_dict[basic_conf_models_this['tx_queue']],
logger_proc=Proc_dict[basic_conf_models_this['logger_proc']],
bot_info_dict=plugin_bot_info_dict[bot_info_key],
debug_mode=False
)
Proc_Proc_dict[tmp_Proc_name] = Proc_dict[tmp_Proc_name].start_unity(
tmp_proc_mode)
elif basic_conf_models_this['type'] == 'biliLive_link':
flag_need_enable = False
for bot_info_key in plugin_bot_info_dict:
Expand Down
13 changes: 13 additions & 0 deletions OlivOS/bootDataAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"OlivOS_telegram_poll",
"OlivOS_fanbook_poll",
"OlivOS_kaiheila_link",
"OlivOS_mhyVila_link",
"OlivOS_dodo_link",
"OlivOS_biliLive_link",
"OlivOS_update_check"
Expand Down Expand Up @@ -86,6 +87,7 @@
"OlivOS_telegram_poll",
"OlivOS_fanbook_poll",
"OlivOS_kaiheila_link",
"OlivOS_mhyVila_link",
"OlivOS_dodo_link",
"OlivOS_biliLive_link",
]
Expand All @@ -107,6 +109,7 @@
"telegram_poll",
"fanbook_poll",
"kaiheila_link",
"mhyVila_link",
"dodo_link",
"biliLive_link",
]
Expand Down Expand Up @@ -359,6 +362,16 @@
"logger_proc": "OlivOS_logger",
"debug": False
},
"OlivOS_mhyVila_link": {
"enable": True,
"name": "OlivOS_mhyVila_link",
"type": "mhyVila_link",
"interval": 0.2,
"dead_interval": 1,
"tx_queue": "OlivOS_rx_queue",
"logger_proc": "OlivOS_logger",
"debug": False
},
"OlivOS_telegram_poll": {
"enable": True,
"name": "OlivOS_telegram_poll",
Expand Down
4 changes: 2 additions & 2 deletions OlivOS/infoAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import OlivOS


OlivOS_Version = '0.11.24'
OlivOS_SVN = 144
OlivOS_Version = '0.11.25'
OlivOS_SVN = 145

# Compatible <= Plugin[compatible_svn] : Compatible
# OldCompatible <= Plugin[compatible_svn] < Compatible : OldCompatible Warn
Expand Down
50 changes: 49 additions & 1 deletion OlivOS/kaiheilaSDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ def send_msg(target_event, chat_id, message, flag_direct=False, message_type_in=
elif message_type == 'card':
res_data = {
"type": "card",
"theme": "secondary",
"theme": "primary",
"color": "#009FE9",
"size": "lg",
"modules": []
}
Expand Down Expand Up @@ -670,6 +671,25 @@ def send_msg(target_event, chat_id, message, flag_direct=False, message_type_in=
this_msg.data.content = json.dumps([res_data], ensure_ascii=False)
this_msg.do_api()

def create_message(target_event, chat_id, content_type:int, content:str, flag_direct=False):
res_data = OlivOS.contentAPI.api_result_data_template.universal_result()
res_data['active'] = True
this_msg = None
if flag_direct:
this_msg = API.creatDirectMessage(get_SDK_bot_info_from_Event(target_event))
else:
this_msg = API.creatMessage(get_SDK_bot_info_from_Event(target_event))
this_msg.data.target_id = str(chat_id)
this_msg.data.type = content_type
this_msg.data.content = content
this_msg.do_api()
res_data['data'] = {}
res_data['data']['chat_type'] = 'private' if flag_direct else 'group'
res_data['data']['chat_id'] = str(chat_id)
res_data['data']['content_type'] = str(content_type)
res_data['data']['content'] = str(json.dumps(content, ensure_ascii = False))
return res_data

def get_login_info(target_event):
res_data = OlivOS.contentAPI.api_result_data_template.get_login_info()
raw_obj = None
Expand Down Expand Up @@ -888,6 +908,34 @@ def set_playgame_activity_game(self, game_id:int, flag_log: bool = True, remote:
res_data = inde_interface.__set_playgame_activity_game(self.event, game_id, flag_log=True)
return res_data

@OlivOS.API.Event.callbackLogger('kaiheila:create_message', ['chat_type', 'chat_id', 'content_type', 'content'])
def __create_message(target_event, chat_type:str, chat_id:str, content_type:int, content:str, flag_log:bool=True):
res_data = None
res_data = OlivOS.kaiheilaSDK.event_action.create_message(
target_event,
chat_id,
content_type,
content,
flag_direct = (False if chat_type == 'group' else True)
)
return res_data

def create_message(
self,
chat_type:str,
chat_id:str,
content_type:int,
content:str,
flag_log: bool = True,
remote: bool = False
):
res_data = None
if remote:
pass
else:
res_data = inde_interface.__create_message(self.event, chat_type, chat_id, content_type, content, flag_log=True)
return res_data

@OlivOS.API.Event.callbackLogger('kaiheila:set_playgame_activity_music', ['music_name', 'singer', 'software'])
def __set_playgame_activity_music(target_event, music_name, singer, software, flag_log=True):
res_data = None
Expand Down
8 changes: 8 additions & 0 deletions OlivOS/messageAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
'text': 'olivos_para'
}
},
'mhyVila': {
'mhyVila_link': {
'default': 'olivos_string',
'public': 'olivos_string',
'private': 'olivos_string',
'sandbox': 'olivos_string'
}
},
'discord': {
'discord_link': {
'default': 'olivos_para'
Expand Down
172 changes: 172 additions & 0 deletions OlivOS/mhyVilaLinkServerAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# -*- encoding: utf-8 -*-
'''
@ _______________________ ________________
@ __ __ \__ /____ _/_ | / /_ __ \_ ___/
@ _ / / /_ / __ / __ | / /_ / / /____ \
@ / /_/ /_ /____/ / __ |/ / / /_/ /____/ /
@ \____/ /_____/___/ _____/ \____/ /____/
@
@File : OlivOS/mhyVilaLinkServerAPI.py
@Author : lunzhiPenxil仑质
@Contact : [email protected]
@License : AGPL3
@Copyright : (C) 2020-2023, OlivOS-Team
@Desc : None
'''

import multiprocessing
import threading
import time
import json
import websocket
import uuid
import requests as req
import traceback

import OlivOS


class server(OlivOS.API.Proc_templet):
def __init__(self, Proc_name, scan_interval=0.001, dead_interval=1, rx_queue=None, tx_queue=None, logger_proc=None,
debug_mode=False, bot_info_dict=None):
OlivOS.API.Proc_templet.__init__(
self,
Proc_name=Proc_name,
Proc_type='mhyVila_link',
scan_interval=scan_interval,
dead_interval=dead_interval,
rx_queue=rx_queue,
tx_queue=tx_queue,
logger_proc=logger_proc
)
self.Proc_config['debug_mode'] = debug_mode
self.Proc_data['bot_info_dict'] = bot_info_dict
self.Proc_data['extend_data'] = {
'websocket_url': None,
'pulse_interval': None,
'last_s': None,
'ws_obj': None,
'ws_item': None,
'ws_PLogin': {
'uid': 0,
'token': '',
'platform': 3,
'app_id': 104,
'device_id': ''
}
}
self.Proc_data['platform_bot_info_dict'] = None

def run(self):
self.log(2, 'OlivOS mhyVila link server [' + self.Proc_name + '] is running')
while True:
sdk_bot_info = OlivOS.mhyVilaSDK.get_SDK_bot_info_from_Plugin_bot_info(
self.Proc_data['bot_info_dict']
)
api_obj = OlivOS.mhyVilaSDK.API.getWebsocketInfo(sdk_bot_info)
try:
api_obj.do_api('GET')
api_obj_json = json.loads(api_obj.res)
if api_obj_json['retcode'] == 0:
self.Proc_data['extend_data']['ws_PLogin']['uid'] = int(api_obj_json['data']['uid'])
self.Proc_data['extend_data']['ws_PLogin']['token'] = '%s.%s.%s' % (
str(sdk_bot_info.vila_id),
OlivOS.mhyVilaSDK.get_bot_secret(sdk_bot_info),
str(sdk_bot_info.bot_id)
)
self.Proc_data['extend_data']['ws_PLogin']['platform'] = int(api_obj_json['data']['platform'])
self.Proc_data['extend_data']['ws_PLogin']['app_id'] = int(api_obj_json['data']['app_id'])
self.Proc_data['extend_data']['ws_PLogin']['device_id'] = str(api_obj_json['data']['device_id'])
self.Proc_data['extend_data']['websocket_url'] = api_obj_json['data']['websocket_url']
else:
self.Proc_data['extend_data']['websocket_url'] = None
except:
self.Proc_data['extend_data']['websocket_url'] = None
if self.Proc_data['extend_data']['websocket_url'] is not None:
self.run_websocket_rx_connect_start()
time.sleep(10)

def on_data(self, ws:websocket.WebSocketApp, data, opcode, FIN):
#print([data, opcode, FIN])
pass

def on_message(self, ws:websocket.WebSocketApp, message):
try:
#print(message)
messageObj = OlivOS.mhyVilaSDK.PAYLOAD.rxPacket(message)
if messageObj.dataHeader.BizType in [
OlivOS.mhyVilaSDK.protoEnum.Model_ROBOTEVENT.value
]:
sdk_event = OlivOS.mhyVilaSDK.event(
messageObj.dataHeader.BizType,
messageObj.dataTable,
self.Proc_data['bot_info_dict']
)
tx_packet_data = OlivOS.pluginAPI.shallow.rx_packet(sdk_event)
self.Proc_info.tx_queue.put(tx_packet_data, block=False)
except Exception as e:
traceback.print_exc()

def on_error(self, ws:websocket.WebSocketApp, error):
self.log(0, 'OlivOS mhyVila link server [' + self.Proc_name + '] websocket link error')

def on_close(self, ws:websocket.WebSocketApp, close_status_code, close_msg):
self.log(0, 'OlivOS mhyVila link server [' + self.Proc_name + '] websocket link close')

def on_open(self, ws:websocket.WebSocketApp):
self.send_PLogin(ws)
threading.Thread(
target=self.run_pulse,
args=()
).start()
self.log(2, 'OlivOS mhyVila link server [' + self.Proc_name + '] websocket link start')

def run_pulse(self):
tmp_ws_item = self.Proc_data['extend_data']['ws_item']
while self.Proc_data['extend_data']['pulse_interval'] is not None:
tmp_pulse_interval = self.Proc_data['extend_data']['pulse_interval']
time.sleep(tmp_pulse_interval)
tmp_data = OlivOS.mhyVilaSDK.PAYLOAD.PHeartBeat().dump()
if tmp_ws_item != self.Proc_data['extend_data']['ws_item'] or self.Proc_data['extend_data']['ws_item'] is None:
self.log(0, 'OlivOS mhyVila link server [' + self.Proc_name + '] websocket pulse giveup')
return
if self.Proc_data['extend_data']['ws_obj'] is not None:
try:
self.Proc_data['extend_data']['ws_obj'].send(tmp_data, opcode=websocket.ABNF.OPCODE_BINARY)
self.log(0, 'OlivOS mhyVila link server [' + self.Proc_name + '] websocket pulse send')
except:
break
else:
break
self.log(0, 'OlivOS mhyVila link server [' + self.Proc_name + '] websocket pulse lost')
return

def send_PLogin(self, ws:websocket.WebSocketApp):
tmp_data = OlivOS.mhyVilaSDK.PAYLOAD.PLogin()
tmp_data.data.uid = self.Proc_data['extend_data']['ws_PLogin']['uid']
tmp_data.data.token = self.Proc_data['extend_data']['ws_PLogin']['token']
tmp_data.data.platform = self.Proc_data['extend_data']['ws_PLogin']['platform']
tmp_data.data.app_id = self.Proc_data['extend_data']['ws_PLogin']['app_id']
tmp_data.data.device_id = self.Proc_data['extend_data']['ws_PLogin']['device_id']
tmp_data.dump()
#print(tmp_data)
ws.send(tmp_data.raw, opcode=websocket.ABNF.OPCODE_BINARY)

def run_websocket_rx_connect_start(self):
websocket.enableTrace(False)
ws = websocket.WebSocketApp(
self.Proc_data['extend_data']['websocket_url'],
on_open=self.on_open,
on_message=self.on_message,
on_data=self.on_data,
on_error=self.on_error,
on_close=self.on_close
)
self.Proc_data['extend_data']['ws_obj'] = ws
self.Proc_data['extend_data']['ws_item'] = uuid.uuid4()
self.Proc_data['extend_data']['pulse_interval'] = 20
ws.run_forever()
self.Proc_data['extend_data']['pulse_interval'] = None
self.Proc_data['extend_data']['ws_obj'] = None
self.Proc_data['extend_data']['ws_item'] = None
self.log(2, 'OlivOS mhyVila link server [' + self.Proc_name + '] websocket link lost')
Loading