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'"
)
__version__ = "1.1.2"
__version__ = "1.1.3"
__title__ = "pomice"
__author__ = "cloudwithax"

View File

@ -101,7 +101,7 @@ class TrackExceptionEvent(PomiceEvent):
class WebSocketClosedPayload:
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.reason: str = data["code"]
self.by_remote: bool = data["byRemote"]
@ -142,3 +142,4 @@ class WebSocketOpenEvent(PomiceEvent):
def __repr__(self) -> str:
return f"<Pomice.WebsocketOpenEvent target={self.target!r} ssrc={self.ssrc!r}>"

View File

@ -3,6 +3,12 @@ from .exceptions import FilterInvalidArgument
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):
self.payload = None
@ -37,11 +43,9 @@ class Equalizer(Filter):
class Timescale(Filter):
"""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
due to the filter patch not corresponding with the track time.
In short this means that your track will either end prematurely or end later due to this.
This is not the library's fault.
You can make some very nice effects with this filter,
i.e: a vaporwave-esque filter which slows the track down
a certain amount to produce said effect.
"""
def __init__(

View File

@ -5,14 +5,18 @@ import json
import random
import re
import socket
import time
from typing import Dict, Optional, TYPE_CHECKING
from urllib.parse import quote
import aiohttp
from discord.ext import commands
from . import __version__, spotify
from . import (
__version__,
spotify,
)
from .enums import SearchType
from .exceptions import (
InvalidSpotifyClientAuthorization,
@ -57,6 +61,7 @@ class Node:
port: int,
password: str,
identifier: str,
secure: bool = False,
session: Optional[aiohttp.ClientSession],
spotify_client_id: Optional[str],
spotify_client_secret: Optional[str],
@ -68,8 +73,10 @@ class Node:
self._pool = pool
self._password = password
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._session = session or aiohttp.ClientSession()
@ -258,7 +265,7 @@ class Node:
) as resp:
if not resp.status == 200:
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()
@ -452,6 +459,7 @@ class NodePool:
port: str,
password: str,
identifier: str,
secure: bool = False,
spotify_client_id: Optional[str],
spotify_client_secret: Optional[str],
session: Optional[aiohttp.ClientSession] = None,
@ -465,7 +473,7 @@ class NodePool:
node = Node(
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
)

View File

@ -75,10 +75,15 @@ class Client:
elif spotify_type == "album":
return Album(data)
else:
tracks = [
Track(track["track"])
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"]
while next_page_url is not None:

View File

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

View File

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