diff --git a/pomice/__init__.py b/pomice/__init__.py index 58b951a..bfcede4 100644 --- a/pomice/__init__.py +++ b/pomice/__init__.py @@ -1,20 +1,24 @@ """Pomice wrapper for Lavalink, made possible by cloudwithax 2021""" +import discord + +if discord.__version__ != '2.0.0a': + class DiscordPyOutdated(Exception): + pass + + raise DiscordPyOutdated( + "You must have discord.py 2.0 to use this library. " + "Uninstall your current version and install discord.py 2.0 " + "using 'pip install git+https://github.com/Rapptz/discord.py@master'" + ) __version__ = "1.0.5" __title__ = "pomice" __author__ = "cloudwithax" -import discord - -if discord.__version__ != '2.0.0a': - raise exit("You must have discord.py 2.0 to use this library. Uninstall your current version and install discord.py 2.0 using 'pip install git+https://github.com/Rapptz/discord.py'") - from .enums import SearchType from .events import * from .exceptions import * from .filters import * -from .pool import * from .objects import * from .player import Player - - +from .pool import * diff --git a/pomice/player.py b/pomice/player.py index 5dbc5dc..cf8c0c7 100644 --- a/pomice/player.py +++ b/pomice/player.py @@ -8,7 +8,7 @@ from discord.ext import commands from . import events from .exceptions import TrackInvalidPosition from .filters import Filter -from .node import Node, NodePool +from .pool import Node, NodePool from .objects import Track @@ -106,7 +106,7 @@ class Player(VoiceProtocol): return self._filter @property - def bot(self) -> Type[Union[discord.Client, commands.Bot, commands.AutoShardedBot]]: + def bot(self) -> Type[discord.Client]: """Property which returns the bot associated with this player instance""" return self._bot @@ -183,17 +183,11 @@ class Player(VoiceProtocol): async def play(self, track: Track, start_position: int = 0) -> Track: """Plays a track. If a Spotify track is passed in, it will be handled accordingly.""" if track.spotify: - - -<< << << < HEAD search: Track = (await self._node.get_tracks( f"{track._search_type}:{track.author} - {track.title}" ))[0] track.original = search -== == == = - spotify_track: objects.Track = (await self._node.get_tracks(f"{track.search_type}"))[0] - track.youtube_result = spotify_track ->>>>>> > f6a375229831e0e68f0ccc8483ebde284247ee9c + await self._node.send( op="play", guildId=str(self.guild.id), diff --git a/pomice/pool.py b/pomice/pool.py index cb95692..233c792 100644 --- a/pomice/pool.py +++ b/pomice/pool.py @@ -4,7 +4,7 @@ import random import re import socket import time -from typing import Optional, Type, Union +from typing import Dict, Optional, Type from urllib.parse import quote import aiohttp @@ -47,7 +47,7 @@ class Node: def __init__( self, pool, - bot: Union[discord.Client, commands.Bot, commands.AutoShardedBot], + bot: Type[discord.Client], host: str, port: int, password: str, @@ -57,17 +57,17 @@ class Node: spotify_client_secret: Optional[str], ): - self._bot: Union[discord.Client, commands.Bot, commands.AutoShardedBot] = bot - self._host: str = host - self._port: int = port - self._pool: NodePool = pool - self._password: str = password - self._identifier: str = identifier + self._bot = bot + self._host = host + self._port = port + self._pool = pool + self._password = password + self._identifier = identifier - self._websocket_uri: str = f"ws://{self._host}:{self._port}" - self._rest_uri: str = f"http://{self._host}:{self._port}" + self._websocket_uri = f"ws://{self._host}:{self._port}" + self._rest_uri = f"http://{self._host}:{self._port}" - self._session: aiohttp.ClientSession = session or aiohttp.ClientSession() + self._session = session or aiohttp.ClientSession() self._websocket: aiohttp.ClientWebSocketResponse = None self._task: asyncio.Task = None @@ -81,10 +81,10 @@ class Node: "Client-Name": f"Pomice/{__version__}" } - self._players: dict = {} + self._players = {} - self._spotify_client_id: str = spotify_client_id - self._spotify_client_secret: str = spotify_client_secret + self._spotify_client_id = spotify_client_id + self._spotify_client_secret = spotify_client_secret if self._spotify_client_id and self._spotify_client_secret: self._spotify_client = spotify.Client( @@ -123,12 +123,12 @@ class Node: return node_stats @property - def players(self) -> dict: + def players(self) -> Dict[int, Player]: """Property which returns a dict containing the guild ID and the player object.""" return self._players @property - def bot(self) -> Union[discord.Client, commands.Bot, commands.AutoShardedBot]: + def bot(self) -> Type[discord.Client]: """Property which returns the discord.py client linked to this node""" return self._bot @@ -448,13 +448,13 @@ class NodePool: This holds all the nodes that are to be used by the bot. """ - _nodes: dict = {} + _nodes = {} def __repr__(self): return f"" @property - def nodes(self) -> dict: + def nodes(self) -> Dict[str, Node]: """Property which returns a dict with the node identifier and the Node object.""" return self._nodes