Skip to content

Commit

Permalink
Merge pull request #127 from OlivOS-Team/main
Browse files Browse the repository at this point in the history
发布0.11.48 Pypi版本
  • Loading branch information
MetaLe0 authored Aug 11, 2024
2 parents 5943a7f + 9a15fc2 commit 3945308
Show file tree
Hide file tree
Showing 75 changed files with 5,573 additions and 1,030 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# These are supported funding model platforms

custom: ['https://afdian.net/@OlivOS'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: ['https://afdian.com/a/OlivOS'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
118 changes: 62 additions & 56 deletions OlivOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,69 @@

import platform

from . import infoAPI
from . import L10NAPI
from . import L10NDataAPI
from . import bootAPI
from . import bootDataAPI
from . import data
from .core.info import infoAPI
from .core.L10N import L10NAPI
from .core.L10N import L10NDataAPI
from .core.boot import bootAPI
from .core.boot import bootDataAPI
from .core.inlineData import data
from . import hook
from . import contentAPI
from . import messageAPI
from . import metadataAPI
from . import API
from .core.core import contentAPI
from .core.core import messageAPI
from .core.core import metadataAPI
from .core.core import API
from . import thirdPartyModule
from . import accountAPI
from . import diagnoseAPI
from . import flaskServerAPI
from . import onebotV12SDK
from . import onebotV12LinkServerAPI
from . import pluginAPI
from . import onebotSDK
from . import virtualTerminalSDK
from . import virtualTerminalLinkServerAPI
from . import qqGuildSDK
from . import qqGuildLinkServerAPI
from . import qqGuildv2SDK
from . import qqGuildv2LinkServerAPI
from . import qqRedSDK
from . import qqRedLinkServerAPI
from . import telegramSDK
from . import telegramPollServerAPI
from . import discordSDK
from . import discordLinkServerAPI
from . import hackChatSDK
from . import hackChatLinkServerAPI
from . import dodobotEAServerAPI
from . import dodobotEATXAPI
from . import dodobotEASDK
from . import dodoSDK
from . import dodoPollServerAPI
from . import dodoLinkSDK
from . import dodoLinkServerAPI
from . import dingtalkSDK
from . import dingtalkLinkServerAPI
from . import fanbookSDK
from . import fanbookPollServerAPI
from . import kaiheilaSDK
from . import kaiheilaLinkServerAPI
from . import mhyVilaSDK
from . import mhyVilaLinkServerAPI
from . import biliLiveSDK
from . import biliLiveLinkServerAPI
from . import updateAPI
from . import webTool
from .core.core import accountAPI
from .core.core import accountMetadataAPI
from .core.core import diagnoseAPI
from .adapter.onebotV11 import flaskServerAPI
from .adapter.onebotV12 import onebotV12SDK
from .adapter.onebotV12 import onebotV12LinkServerAPI
from .core.core import pluginAPI
from .adapter.onebotV11 import onebotSDK
from .adapter.virtualTerminal import virtualTerminalSDK
from .adapter.virtualTerminal import virtualTerminalLinkServerAPI
from .adapter.qqGuild import qqGuildSDK
from .adapter.qqGuild import qqGuildLinkServerAPI
from .adapter.qqGuild import qqGuildv2SDK
from .adapter.qqGuild import qqGuildv2LinkServerAPI
from .adapter.red import qqRedSDK
from .adapter.red import qqRedLinkServerAPI
from .adapter.OPQBot import OPQBotSDK
from .adapter.OPQBot import OPQBotLinkServerAPI
from .adapter.telegram import telegramSDK
from .adapter.telegram import telegramPollServerAPI
from .adapter.discord import discordSDK
from .adapter.discord import discordLinkServerAPI
from .adapter.hackChat import hackChatSDK
from .adapter.hackChat import hackChatLinkServerAPI
from .adapter.dodo import dodobotEAServerAPI
from .adapter.dodo import dodobotEATXAPI
from .adapter.dodo import dodobotEASDK
from .adapter.dodo import dodoSDK
from .adapter.dodo import dodoPollServerAPI
from .adapter.dodo import dodoLinkSDK
from .adapter.dodo import dodoLinkServerAPI
from .adapter.dingtalk import dingtalkSDK
from .adapter.dingtalk import dingtalkLinkServerAPI
from .adapter.fanbook import fanbookSDK
from .adapter.fanbook import fanbookPollServerAPI
from .adapter.kaiheila import kaiheilaSDK
from .adapter.kaiheila import kaiheilaLinkServerAPI
from .adapter.mhyVila import mhyVilaSDK
from .adapter.mhyVila import mhyVilaLinkServerAPI
from .adapter.biliLive import biliLiveSDK
from .adapter.biliLive import biliLiveLinkServerAPI
from .core.web import updateAPI
from .core.web import webTool
if platform.system() == 'Windows':
from . import multiLoginUIAPI
from . import libEXEModelAPI
from . import libWQEXEModelAPI
from . import libCWCBEXEModelAPI
from . import nativeWinUIAPI
from . import webviewUIAPI
from .nativeGUI import multiLoginUIAPI
from .libBooter import libEXEModelAPI
from .libBooter import libWQEXEModelAPI
from .libBooter import libCWCBEXEModelAPI
from .libBooter import libOPQBotEXEModelAPI
from .libBooter import libNapCatEXEModelAPI
from .libBooter import libAstralQsignEXEModelAPI
from .nativeGUI import nativeWinUIAPI
from .nativeGUI import webviewUIAPI
from . import userModule
140 changes: 140 additions & 0 deletions OlivOS/adapter/OPQBot/OPQBotLinkServerAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# -*- encoding: utf-8 -*-
'''
_______________________ ________________
__ __ \__ /____ _/_ | / /_ __ \_ ___/
_ / / /_ / __ / __ | / /_ / / /____ \
/ /_/ /_ /____/ / __ |/ / / /_/ /____/ /
\____/ /_____/___/ _____/ \____/ /____/
@File : OlivOS/OPQBotLinkServerAPI.py
@Author : lunzhiPenxil仑质
@Contact : [email protected]
@License : AGPL
@Copyright : (C) 2020-2023, OlivOS-Team
@Desc : None
'''

import time
import json
import websocket
import uuid
import threading

import OlivOS

gCheckList = [
'opqbot_default',
'opqbot_auto',
'opqbot_port',
'opqbot_port_old',
]

modelName = 'OPQBotLinkServerAPI'

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='OPQBot_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,
'ws_obj': None,
'ws_item': None
}
self.Proc_data['platform_bot_info_dict'] = None

def run(self):
wsPath = f"ws://{self.Proc_data['bot_info_dict'].post_info.host}:{self.Proc_data['bot_info_dict'].post_info.port}/ws"
self.log(2, OlivOS.L10NAPI.getTrans('OlivOS OPQBot link server [{0}] is running on [{1}]', [self.Proc_name, wsPath], modelName))
threading.Thread(
target=self.message_router,
args=()
).start()
while True:
try:
self.Proc_data['extend_data']['websocket_url'] = wsPath
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(self.Proc_info.scan_interval)

def on_message(self, ws, message):
try:
#print(message)
rx_data = json.loads(message)
rx_obj = OlivOS.OPQBotSDK.PAYLOAD.rxPacket(data=rx_data)
if rx_obj.active:
sdk_event = OlivOS.OPQBotSDK.event(rx_obj, 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:
pass

def on_error(self, ws, error):
self.log(0, OlivOS.L10NAPI.getTrans(
'OlivOS OPQBot link server [{0}] websocket link error',
[self.Proc_name],
modelName
))

def on_close(self, ws, close_status_code, close_msg):
self.log(0, OlivOS.L10NAPI.getTrans(
'OlivOS OPQBot link server [{0}] websocket link close',
[self.Proc_name],
modelName
))

def on_open(self, ws: websocket.WebSocketApp):
self.log(2, OlivOS.L10NAPI.getTrans(
'OlivOS OPQBot link server [{0}] websocket link start',
[self.Proc_name],
modelName
))

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()
proxy_set = OlivOS.webTool.get_system_proxy_tuple('http')
ws.run_forever(http_proxy_host=proxy_set[0], http_proxy_port=proxy_set[1], proxy_type=proxy_set[2])
self.Proc_data['extend_data']['ws_obj'] = None
self.Proc_data['extend_data']['ws_item'] = None
self.log(2, OlivOS.L10NAPI.getTrans(
'OlivOS OPQBot link server [{0}] websocket link lost',
[self.Proc_name],
modelName
))

def message_router(self):
while True:
if self.Proc_data['extend_data']['ws_obj'] is None or self.Proc_info.rx_queue.empty():
time.sleep(self.Proc_info.scan_interval)
else:
try:
rx_packet_data = self.Proc_info.rx_queue.get(block=False)
except:
rx_packet_data = None
if rx_packet_data is not None:
if 'data' in rx_packet_data.key and 'action' in rx_packet_data.key['data']:
if 'send' == rx_packet_data.key['data']['action']:
if 'data' in rx_packet_data.key['data']:
#print(rx_packet_data.key['data']['data'])
self.Proc_data['extend_data']['ws_obj'].send(rx_packet_data.key['data']['data'])
Loading

0 comments on commit 3945308

Please sign in to comment.