we do a little cleaning up

This commit is contained in:
vveeps 2021-10-09 23:03:12 +03:00
parent a72afa8031
commit e66440e9b3
3 changed files with 33 additions and 35 deletions

View File

@ -1,20 +1,24 @@
"""Pomice wrapper for Lavalink, made possible by cloudwithax 2021""" """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" __version__ = "1.0.5"
__title__ = "pomice" __title__ = "pomice"
__author__ = "cloudwithax" __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 .enums import SearchType
from .events import * from .events import *
from .exceptions import * from .exceptions import *
from .filters import * from .filters import *
from .pool import *
from .objects import * from .objects import *
from .player import Player from .player import Player
from .pool import *

View File

@ -8,7 +8,7 @@ from discord.ext import commands
from . import events from . import events
from .exceptions import TrackInvalidPosition from .exceptions import TrackInvalidPosition
from .filters import Filter from .filters import Filter
from .node import Node, NodePool from .pool import Node, NodePool
from .objects import Track from .objects import Track
@ -106,7 +106,7 @@ class Player(VoiceProtocol):
return self._filter return self._filter
@property @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""" """Property which returns the bot associated with this player instance"""
return self._bot return self._bot
@ -183,17 +183,11 @@ class Player(VoiceProtocol):
async def play(self, track: Track, start_position: int = 0) -> Track: 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.""" """Plays a track. If a Spotify track is passed in, it will be handled accordingly."""
if track.spotify: if track.spotify:
<< << << < HEAD
search: Track = (await self._node.get_tracks( search: Track = (await self._node.get_tracks(
f"{track._search_type}:{track.author} - {track.title}" f"{track._search_type}:{track.author} - {track.title}"
))[0] ))[0]
track.original = search 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( await self._node.send(
op="play", op="play",
guildId=str(self.guild.id), guildId=str(self.guild.id),

View File

@ -4,7 +4,7 @@ import random
import re import re
import socket import socket
import time import time
from typing import Optional, Type, Union from typing import Dict, Optional, Type
from urllib.parse import quote from urllib.parse import quote
import aiohttp import aiohttp
@ -47,7 +47,7 @@ class Node:
def __init__( def __init__(
self, self,
pool, pool,
bot: Union[discord.Client, commands.Bot, commands.AutoShardedBot], bot: Type[discord.Client],
host: str, host: str,
port: int, port: int,
password: str, password: str,
@ -57,17 +57,17 @@ class Node:
spotify_client_secret: Optional[str], spotify_client_secret: Optional[str],
): ):
self._bot: Union[discord.Client, commands.Bot, commands.AutoShardedBot] = bot self._bot = bot
self._host: str = host self._host = host
self._port: int = port self._port = port
self._pool: NodePool = pool self._pool = pool
self._password: str = password self._password = password
self._identifier: str = identifier self._identifier = identifier
self._websocket_uri: str = f"ws://{self._host}:{self._port}" self._websocket_uri = f"ws://{self._host}:{self._port}"
self._rest_uri: str = f"http://{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._websocket: aiohttp.ClientWebSocketResponse = None
self._task: asyncio.Task = None self._task: asyncio.Task = None
@ -81,10 +81,10 @@ class Node:
"Client-Name": f"Pomice/{__version__}" "Client-Name": f"Pomice/{__version__}"
} }
self._players: dict = {} self._players = {}
self._spotify_client_id: str = spotify_client_id self._spotify_client_id = spotify_client_id
self._spotify_client_secret: str = spotify_client_secret self._spotify_client_secret = spotify_client_secret
if self._spotify_client_id and self._spotify_client_secret: if self._spotify_client_id and self._spotify_client_secret:
self._spotify_client = spotify.Client( self._spotify_client = spotify.Client(
@ -123,12 +123,12 @@ class Node:
return node_stats return node_stats
@property @property
def players(self) -> dict: def players(self) -> Dict[int, Player]:
"""Property which returns a dict containing the guild ID and the player object.""" """Property which returns a dict containing the guild ID and the player object."""
return self._players return self._players
@property @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""" """Property which returns the discord.py client linked to this node"""
return self._bot return self._bot
@ -448,13 +448,13 @@ class NodePool:
This holds all the nodes that are to be used by the bot. This holds all the nodes that are to be used by the bot.
""" """
_nodes: dict = {} _nodes = {}
def __repr__(self): def __repr__(self):
return f"<Pomice.NodePool node_count={self.node_count}>" return f"<Pomice.NodePool node_count={self.node_count}>"
@property @property
def nodes(self) -> dict: def nodes(self) -> Dict[str, Node]:
"""Property which returns a dict with the node identifier and the Node object.""" """Property which returns a dict with the node identifier and the Node object."""
return self._nodes return self._nodes