Fix examples to better reflect changes in library
This commit is contained in:
parent
fde5f9711a
commit
ea6c2baf3c
|
|
@ -91,7 +91,7 @@ class Music(commands.Cog):
|
|||
|
||||
player = ctx.voice_client
|
||||
|
||||
results = await player.get_tracks(query=f'ytsearch:{search}')
|
||||
results = await player.get_tracks(query=f'{search}')
|
||||
|
||||
if not results:
|
||||
raise commands.CommandError('No results were found for that search term.')
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Music(commands.Cog):
|
|||
# i.e: player.get_tracks("query", search_type=SearchType.ytmsearch)
|
||||
# will search up any keyword results on Youtube Music
|
||||
|
||||
results = player.get_tracks("query")
|
||||
results = player.get_tracks(f"{search}")
|
||||
|
||||
if not results:
|
||||
raise commands.CommandError('No results were found for that search term.')
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import collections
|
||||
from .exceptions import FilterInvalidArgument
|
||||
|
||||
|
||||
|
|
@ -6,6 +7,34 @@ class Filter:
|
|||
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):
|
||||
"""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
|
||||
|
|
@ -78,9 +107,11 @@ class Tremolo(Filter):
|
|||
super().__init__()
|
||||
|
||||
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:
|
||||
raise FilterInvalidArgument("Tremolo depth must be between 0 and 1.")
|
||||
raise FilterInvalidArgument(
|
||||
"Tremolo depth must be between 0 and 1.")
|
||||
|
||||
self.frequency = frequency
|
||||
self.depth = depth
|
||||
|
|
@ -101,9 +132,11 @@ class Vibrato(Filter):
|
|||
|
||||
super().__init__()
|
||||
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:
|
||||
raise FilterInvalidArgument("Vibrato depth must be between 0 and 1.")
|
||||
raise FilterInvalidArgument(
|
||||
"Vibrato depth must be between 0 and 1.")
|
||||
|
||||
self.frequency = frequency
|
||||
self.depth = depth
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import socket
|
|||
import time
|
||||
from typing import Dict, Optional, Type, TYPE_CHECKING
|
||||
from urllib.parse import quote
|
||||
from base64 import b
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
|
|
@ -253,6 +254,33 @@ class Node:
|
|||
self.available = False
|
||||
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(
|
||||
self,
|
||||
query: str,
|
||||
|
|
@ -480,7 +508,7 @@ class NodePool:
|
|||
"""Fetches a node from the node pool using it's identifier.
|
||||
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:
|
||||
raise NoNodesAvailable('There are no nodes available.')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue