Moved ipc_client into voicelink
This commit is contained in:
@@ -176,8 +176,8 @@ class Listeners(commands.Cog):
|
||||
if player.is_paused and len([m for m in player.channel.members if not m.bot]) == 1:
|
||||
await player.set_pause(False, member)
|
||||
|
||||
if self.bot.ipc._is_connected:
|
||||
await self.bot.ipc.send({
|
||||
if player.is_ipc_connected:
|
||||
await player._ipc_client.send({
|
||||
"op": "updateGuild",
|
||||
"user": {
|
||||
"userId": str(member.id),
|
||||
|
||||
9
main.py
9
main.py
@@ -30,9 +30,8 @@ import logging
|
||||
import function as func
|
||||
|
||||
from discord.ext import commands
|
||||
from ipc import IPCClient
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
from voicelink import Config, LangHandler, MongoDBHandler, VoicelinkException
|
||||
from voicelink import Config, LangHandler, MongoDBHandler, IPCClient, VoicelinkException
|
||||
from voicelink.utils import dispatch_message
|
||||
|
||||
class Translator(discord.app_commands.Translator):
|
||||
@@ -69,7 +68,7 @@ class Vocard(commands.Bot):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.ipc: IPCClient
|
||||
self.ipc_client: IPCClient
|
||||
|
||||
async def on_message(self, message: discord.Message, /) -> None:
|
||||
# Ignore messages from bots or DMs
|
||||
@@ -121,10 +120,10 @@ class Vocard(commands.Bot):
|
||||
except Exception as e:
|
||||
func.logger.error(f"Something went wrong while loading {module[:-3]} cog.", exc_info=e)
|
||||
|
||||
self.ipc = IPCClient(self, **bot_config.ipc_client)
|
||||
self.ipc_client: IPCClient = IPCClient(self, **bot_config.ipc_client)
|
||||
if bot_config.ipc_client.get("enable", False):
|
||||
try:
|
||||
await self.ipc.connect()
|
||||
await self.ipc_client.connect()
|
||||
except Exception as e:
|
||||
func.logger.error(f"Cannot connected to dashboard! - Reason: {e}")
|
||||
|
||||
|
||||
@@ -39,3 +39,4 @@ from .placeholders import PlayerPlaceholder, BotPlaceholder
|
||||
from .mongodb import MongoDBHandler
|
||||
from .language import LangHandler
|
||||
from .lyrics import LYRICS_PLATFORMS
|
||||
from .ipc import IPCClient
|
||||
|
||||
@@ -29,7 +29,7 @@ class IPCClient:
|
||||
self._is_secure: bool = secure
|
||||
self._is_connected: bool = False
|
||||
self._is_connecting: bool = False
|
||||
self._logger: logging.Logger = logging.getLogger("ipc_client")
|
||||
self._logger: logging.Logger = logging.getLogger("vocard.ipc_client")
|
||||
|
||||
self._websocket_url: str = f"{'wss' if self._is_secure else 'ws'}://{self._host}:{self._port}/ws_bot"
|
||||
self._session: Optional[aiohttp.ClientSession] = None
|
||||
@@ -1,12 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import time, re
|
||||
|
||||
from typing import List, Dict, Union, Optional
|
||||
from typing import List, Dict, Union, Optional, TYPE_CHECKING
|
||||
|
||||
from discord import User, Member
|
||||
from discord.ext import commands
|
||||
from voicelink import Player, Track, Playlist, NodePool, LoopType, Filters, Config, MongoDBHandler, LangHandler, LYRICS_PLATFORMS
|
||||
from voicelink.utils import TempCtx
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .client import IPCClient
|
||||
|
||||
RATELIMIT_COUNTER: Dict[int, Dict[str, float]] = {}
|
||||
SCOPES = {
|
||||
"prefix": str,
|
||||
@@ -727,7 +732,7 @@ METHODS: Dict[str, Union[SystemMethod, PlayerMethod]] = {
|
||||
"searchAndPlay": PlayerMethod(searchAndPlay, credit=5, auto_connect=True)
|
||||
}
|
||||
|
||||
async def process_methods(ipc_client, bot: commands.Bot, data: Dict) -> None:
|
||||
async def process_methods(ipc_client: IPCClient, bot: commands.Bot, data: Dict) -> None:
|
||||
op: str = data.get("op", "")
|
||||
method = METHODS.get(op)
|
||||
if not method or not (user_id := data.get("userId")):
|
||||
@@ -21,12 +21,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time, logging
|
||||
|
||||
from math import ceil
|
||||
from asyncio import sleep
|
||||
from random import shuffle, choice
|
||||
from typing import Any, Dict, List, Optional, Union, Tuple
|
||||
from typing import Any, Dict, List, Optional, Union, Tuple, TYPE_CHECKING
|
||||
|
||||
from discord import (
|
||||
Client,
|
||||
@@ -58,6 +60,9 @@ from .language import LangHandler
|
||||
from .views import InteractiveController
|
||||
from .utils import format_ms, dispatch_message
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .ipc import IPCClient
|
||||
|
||||
async def connect_channel(ctx: Union[commands.Context, Interaction], channel: VoiceChannel = None):
|
||||
texts = await LangHandler.get_lang(ctx.guild.id, "noChannel", "noPermission")
|
||||
try:
|
||||
@@ -79,7 +84,7 @@ async def connect_channel(ctx: Union[commands.Context, Interaction], channel: Vo
|
||||
if player.volume != 100:
|
||||
await player.set_volume(player.volume)
|
||||
|
||||
if ctx.bot.ipc.is_connected:
|
||||
if player.is_ipc_connected:
|
||||
await player.send_ws({"op": "createPlayer", "memberIds": [str(member.id) for member in channel.members]})
|
||||
|
||||
return player
|
||||
@@ -107,8 +112,8 @@ class Player(VoiceProtocol):
|
||||
):
|
||||
self.client: Client = client
|
||||
self._bot: Client = client
|
||||
self._ipc = self._bot.ipc
|
||||
self._ipc_connection = False
|
||||
self._ipc_client: IPCClient = self._bot.ipc_client
|
||||
self._ipc_connection: bool = False
|
||||
|
||||
self.context = ctx
|
||||
self.dj: Member = ctx.user if isinstance(ctx, Interaction) else ctx.author
|
||||
@@ -255,7 +260,7 @@ class Player(VoiceProtocol):
|
||||
@property
|
||||
def is_ipc_connected(self) -> bool:
|
||||
"""Indicates whether the Inter-Process Communication (IPC) connection is active."""
|
||||
return self._ipc._is_connected and self._ipc_connection
|
||||
return self._ipc_client._is_connected and self._ipc_connection
|
||||
|
||||
def get_msg(self, *keys) -> Union[list[str], str]:
|
||||
"""Retrieves a localized message or list of messages based on the given keys
|
||||
@@ -891,4 +896,4 @@ class Player(VoiceProtocol):
|
||||
payload['guildId'] = str(self.guild.id)
|
||||
if requester:
|
||||
payload['requesterId'] = str(requester.id)
|
||||
await self.bot.ipc.send(payload)
|
||||
await self._ipc_client.send(payload)
|
||||
Reference in New Issue
Block a user