Skip to content

Commit

Permalink
测试性内容
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Nov 30, 2023
1 parent 18fa422 commit 90ac836
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 9 deletions.
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
105 changes: 105 additions & 0 deletions OlivOS/mhyVilaLinkServerAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# -*- 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
}
self.Proc_data['platform_bot_info_dict'] = None

def run(self):
self.log(2, 'OlivOS kaiheila link server [' + self.Proc_name + '] is running')
while True:
api_obj = OlivOS.mhyVilaSDK.API.getWebsocketInfo(
OlivOS.mhyVilaSDK.get_SDK_bot_info_from_Plugin_bot_info(
self.Proc_data['bot_info_dict']
)
)
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']['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
print(self.Proc_data['extend_data']['websocket_url'])
#if self.Proc_data['extend_data']['websocket_url'] is not None:
# self.run_websocket_rx_connect_start()
time.sleep(10)

def on_message(self, ws, message):
try:
print(message)
except:
pass

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

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

def on_open(self, ws):
self.log(2, 'OlivOS kaiheila link server [' + self.Proc_name + '] websocket link start')

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_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()
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 kaiheila link server [' + self.Proc_name + '] websocket link lost')
Loading

0 comments on commit 90ac836

Please sign in to comment.