Fix examples to better reflect changes in library

This commit is contained in:
cloudwithax 2021-10-17 17:21:24 -04:00
parent fde5f9711a
commit ea6c2baf3c
4 changed files with 68 additions and 7 deletions

View File

@ -91,7 +91,7 @@ class Music(commands.Cog):
player = ctx.voice_client player = ctx.voice_client
results = await player.get_tracks(query=f'ytsearch:{search}') results = await player.get_tracks(query=f'{search}')
if not results: if not results:
raise commands.CommandError('No results were found for that search term.') raise commands.CommandError('No results were found for that search term.')

View File

@ -75,7 +75,7 @@ class Music(commands.Cog):
# i.e: player.get_tracks("query", search_type=SearchType.ytmsearch) # i.e: player.get_tracks("query", search_type=SearchType.ytmsearch)
# will search up any keyword results on Youtube Music # will search up any keyword results on Youtube Music
results = player.get_tracks("query") results = player.get_tracks(f"{search}")
if not results: if not results:
raise commands.CommandError('No results were found for that search term.') raise commands.CommandError('No results were found for that search term.')

View File

@ -1,3 +1,4 @@
import collections
from .exceptions import FilterInvalidArgument from .exceptions import FilterInvalidArgument
@ -6,6 +7,34 @@ class Filter:
self.payload = None self.payload = None
class Equalizer:
"""
Filter which represents a 15 band equalizer.
You can adjust the dynamic of the sound using this filter.
i.e: Applying a bass boost filter to emphasize the bass in a song.
The format for the levels is: List[Tuple[int, float]]
"""
def __init__(self, *, levels: list):
super().__init__()
self.eq = self._factory(self, levels)
self.raw = levels
self.payload = {'equalizer': {'bands': self.eq}}
def _factory(self, levels: list):
_dict = collections.defaultdict(int)
_dict.update(levels)
_dict = [{"band": i, "gain": _dict[i]} for i in range(15)]
return _dict
def __repr__(self) -> str:
return f"<Pomice.EqualizerFilter eq={self.eq} raw={self.raw}>"
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 Do be warned that this filter is bugged as of the lastest Lavalink dev version
@ -78,9 +107,11 @@ class Tremolo(Filter):
super().__init__() super().__init__()
if frequency < 0: if frequency < 0:
raise FilterInvalidArgument("Tremolo frequency must be more than 0.") raise FilterInvalidArgument(
"Tremolo frequency must be more than 0.")
if depth < 0 or depth > 1: if depth < 0 or depth > 1:
raise FilterInvalidArgument("Tremolo depth must be between 0 and 1.") raise FilterInvalidArgument(
"Tremolo depth must be between 0 and 1.")
self.frequency = frequency self.frequency = frequency
self.depth = depth self.depth = depth
@ -101,9 +132,11 @@ class Vibrato(Filter):
super().__init__() super().__init__()
if frequency < 0 or frequency > 14: if frequency < 0 or frequency > 14:
raise FilterInvalidArgument("Vibrato frequency must be between 0 and 14.") raise FilterInvalidArgument(
"Vibrato frequency must be between 0 and 14.")
if depth < 0 or depth > 1: if depth < 0 or depth > 1:
raise FilterInvalidArgument("Vibrato depth must be between 0 and 1.") raise FilterInvalidArgument(
"Vibrato depth must be between 0 and 1.")
self.frequency = frequency self.frequency = frequency
self.depth = depth self.depth = depth

View File

@ -8,6 +8,7 @@ import socket
import time import time
from typing import Dict, Optional, Type, TYPE_CHECKING from typing import Dict, Optional, Type, TYPE_CHECKING
from urllib.parse import quote from urllib.parse import quote
from base64 import b
import aiohttp import aiohttp
import discord import discord
@ -253,6 +254,33 @@ class Node:
self.available = False self.available = False
self._task.cancel() self._task.cancel()
async def build_track(
self,
*,
identifier: str,
ctx: Optional[commands.Context]
):
"""
Builds a track using a valid track identifier
You can also pass in a discord.py Context object to get a
Context object on the track it builds.
"""
async with self.session.get(f'{self._rest_uri}/decodetrack?',
headers={'Authorization': self._password},
params={'track': identifier}) as resp:
data: dict = await resp.json()
if not resp.status == 200:
raise TrackLoadError(f'Failed to build track. Status: {data["status"]}, Error: {data["error"]}.'
f'Check the identifier is correct and try again.')
track = Track(track_id=identifier, ctx=ctx, info=data)
return track
async def get_tracks( async def get_tracks(
self, self,
query: str, query: str,
@ -480,7 +508,7 @@ class NodePool:
"""Fetches a node from the node pool using it's identifier. """Fetches a node from the node pool using it's identifier.
If no identifier is provided, it will choose a node at random. If no identifier is provided, it will choose a node at random.
""" """
available_nodes = {identifier: node for identifier, node in cls._nodes.items()} available_nodes = {identifier: node for identifier, node in cls._nodes.items() if node._available}
if not available_nodes: if not available_nodes:
raise NoNodesAvailable('There are no nodes available.') raise NoNodesAvailable('There are no nodes available.')