Added secure protocol in ipc client

This commit is contained in:
Choco
2024-06-04 23:15:03 +08:00
parent 90c0c83388
commit f3f7ff75af
2 changed files with 9 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import aiohttp
import asyncio
import logging
import function as func
from discord.ext import commands
from typing import Optional
@@ -14,7 +15,10 @@ class IPCClient:
host: str,
port: int,
password: str,
heartbeat: int = 30
heartbeat: int = 30,
secure: bool = False,
*arg,
**kwargs
) -> None:
self._bot: commands.Bot = bot
@@ -22,11 +26,12 @@ class IPCClient:
self._port: int = port
self._password: str = password
self._heartbeat: int = heartbeat
self._is_secure: bool = secure
self._is_connected: bool = False
self._is_connecting: bool = False
self._logger: logging.Logger = logging.getLogger("ipc_client")
self._websocket_url: str = f"ws://{self._host}:{self._port}/ws_bot"
self._websocket_url: str = f"{'wss' if self._is_secure else 'ws'}://{self._host}:{self._port}/ws_bot"
self._session: Optional[aiohttp.ClientSession] = None
self._websocket: Optional[aiohttp.ClientWebSocketResponse] = None
self._task: Optional[asyncio.Task] = None
@@ -34,6 +39,7 @@ class IPCClient:
self._heanders = {
"Authorization": self._password,
"User-Id": str(bot.user.id),
"Client-Version": func.settings.version
}
async def _listen(self) -> None:

View File

@@ -76,12 +76,7 @@ class Vocard(commands.Bot):
if func.settings.ipc_client.get("enable", False):
try:
self.ipc = IPCClient(
self,
host=func.settings.ipc_client["host"],
port=func.settings.ipc_client["port"],
password=func.settings.ipc_client["password"]
)
self.ipc = IPCClient(self, **func.settings.ipc_client)
await self.ipc.connect()
except Exception as e:
func.logger.error(f"Cannot connected to dashboard! - Reason: {e}")