Added secure kwarg to create_node() and fixed some bugs

This commit is contained in:
cloudwithax 2021-11-12 21:07:50 -05:00
parent 3115989f42
commit 2e77a7d7df
7 changed files with 32 additions and 14 deletions

View File

@ -11,7 +11,7 @@ if discord.__version__ != "2.0.0a":
"using 'pip install git+https://github.com/Rapptz/discord.py@master'" "using 'pip install git+https://github.com/Rapptz/discord.py@master'"
) )
__version__ = "1.1.2" __version__ = "1.1.3"
__title__ = "pomice" __title__ = "pomice"
__author__ = "cloudwithax" __author__ = "cloudwithax"

View File

@ -101,7 +101,7 @@ class TrackExceptionEvent(PomiceEvent):
class WebSocketClosedPayload: class WebSocketClosedPayload:
def __init__(self, data: dict): def __init__(self, data: dict):
self.guild = NodePool.get_node().get_player(int(data["guildId"]))._guild self.guild = NodePool.get_node().bot.get_guild(int(data["guildId"]))
self.code: int = data["code"] self.code: int = data["code"]
self.reason: str = data["code"] self.reason: str = data["code"]
self.by_remote: bool = data["byRemote"] self.by_remote: bool = data["byRemote"]
@ -142,3 +142,4 @@ class WebSocketOpenEvent(PomiceEvent):
def __repr__(self) -> str: def __repr__(self) -> str:
return f"<Pomice.WebsocketOpenEvent target={self.target!r} ssrc={self.ssrc!r}>" return f"<Pomice.WebsocketOpenEvent target={self.target!r} ssrc={self.ssrc!r}>"

View File

@ -3,6 +3,12 @@ from .exceptions import FilterInvalidArgument
class Filter: class Filter:
"""
The base class for all filters.
You can use these filters if you have the latest Lavalink version
installed. If you do not have the latest Lavalink version,
these filters will not work.
"""
def __init__(self): def __init__(self):
self.payload = None self.payload = None
@ -37,11 +43,9 @@ class Equalizer(Filter):
class Timescale(Filter): class Timescale(Filter):
"""Filter which changes the speed and pitch of a track. """Filter which changes the speed and pitch of a track.
Do be warned that this filter is bugged as of the lastest Lavalink dev version You can make some very nice effects with this filter,
due to the filter patch not corresponding with the track time. i.e: a vaporwave-esque filter which slows the track down
a certain amount to produce said effect.
In short this means that your track will either end prematurely or end later due to this.
This is not the library's fault.
""" """
def __init__( def __init__(

View File

@ -5,14 +5,18 @@ import json
import random import random
import re import re
import socket import socket
import time
from typing import Dict, Optional, TYPE_CHECKING from typing import Dict, Optional, TYPE_CHECKING
from urllib.parse import quote from urllib.parse import quote
import aiohttp import aiohttp
from discord.ext import commands from discord.ext import commands
from . import __version__, spotify
from . import (
__version__,
spotify,
)
from .enums import SearchType from .enums import SearchType
from .exceptions import ( from .exceptions import (
InvalidSpotifyClientAuthorization, InvalidSpotifyClientAuthorization,
@ -57,6 +61,7 @@ class Node:
port: int, port: int,
password: str, password: str,
identifier: str, identifier: str,
secure: bool = False,
session: Optional[aiohttp.ClientSession], session: Optional[aiohttp.ClientSession],
spotify_client_id: Optional[str], spotify_client_id: Optional[str],
spotify_client_secret: Optional[str], spotify_client_secret: Optional[str],
@ -68,8 +73,10 @@ class Node:
self._pool = pool self._pool = pool
self._password = password self._password = password
self._identifier = identifier self._identifier = identifier
self._secure = secure
self._websocket_uri = f"ws://{self._host}:{self._port}"
self._websocket_uri = f"{'wss' if self._secure else 'ws'}://{self._host}:{self._port}"
self._rest_uri = f"http://{self._host}:{self._port}" self._rest_uri = f"http://{self._host}:{self._port}"
self._session = session or aiohttp.ClientSession() self._session = session or aiohttp.ClientSession()
@ -258,7 +265,7 @@ class Node:
) as resp: ) as resp:
if not resp.status == 200: if not resp.status == 200:
raise TrackLoadError( raise TrackLoadError(
f"Failed to build track. Check the identifier is correct and try again." f"Failed to build track. Check if the identifier is correct and try again."
) )
data: dict = await resp.json() data: dict = await resp.json()
@ -452,6 +459,7 @@ class NodePool:
port: str, port: str,
password: str, password: str,
identifier: str, identifier: str,
secure: bool = False,
spotify_client_id: Optional[str], spotify_client_id: Optional[str],
spotify_client_secret: Optional[str], spotify_client_secret: Optional[str],
session: Optional[aiohttp.ClientSession] = None, session: Optional[aiohttp.ClientSession] = None,
@ -465,7 +473,7 @@ class NodePool:
node = Node( node = Node(
pool=cls, bot=bot, host=host, port=port, password=password, pool=cls, bot=bot, host=host, port=port, password=password,
identifier=identifier, spotify_client_id=spotify_client_id, identifier=identifier, secure=secure, spotify_client_id=spotify_client_id,
session=session, spotify_client_secret=spotify_client_secret session=session, spotify_client_secret=spotify_client_secret
) )

View File

@ -75,10 +75,15 @@ class Client:
elif spotify_type == "album": elif spotify_type == "album":
return Album(data) return Album(data)
else: else:
tracks = [ tracks = [
Track(track["track"]) Track(track["track"])
for track in data["tracks"]["items"] if track["track"] is not None for track in data["tracks"]["items"] if track["track"] is not None
] ]
if not len(tracks):
raise SpotifyRequestException("This playlist is empty and therefore cannot be queued.")
next_page_url = data["tracks"]["next"] next_page_url = data["tracks"]["next"]
while next_page_url is not None: while next_page_url is not None:

View File

@ -11,7 +11,7 @@ class Playlist:
self.owner = data["owner"]["display_name"] self.owner = data["owner"]["display_name"]
self.total_tracks = data["tracks"]["total"] self.total_tracks = data["tracks"]["total"]
self.id = data["id"] self.id = data["id"]
if data.get("images"): if data.get("images") and len(data["images"]):
self.image = data["images"][0]["url"] self.image = data["images"][0]["url"]
else: else:
self.image = None self.image = None

View File

@ -6,7 +6,7 @@ with open("README.md") as f:
setuptools.setup( setuptools.setup(
name="pomice", name="pomice",
author="cloudwithax", author="cloudwithax",
version="1.1.2", version="1.1.3",
url="https://github.com/cloudwithax/pomice", url="https://github.com/cloudwithax/pomice",
packages=setuptools.find_packages(), packages=setuptools.find_packages(),
license="GPL", license="GPL",