Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to lavalink.py v5 #84

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ async def on_ready(self):
self.logger.debug("Bot Ready")

self.session = aiohttp.ClientSession(loop=self.loop)
await self.change_presence(activity=discord.Game(type=0,
name=conf["bot"]["playing status"]),
status=discord.Status.online)

if presence := conf["bot"]["playing status"]:
await self.change_presence(activity=discord.Game(type=0,
name=presence),
status=discord.Status.online)

def run(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ clean:

# Run ruff
lint: venv
{{python}} -m ruff . --fix
{{python}} -m ruff check . --fix

# Run tests
test: venv
Expand Down
2 changes: 1 addition & 1 deletion musicbot/cogs/music/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lavalink
from discord import VoiceChannel
from discord.ext import commands, tasks
from lavalink import AudioTrack
from lavalink.events import (
NodeChangedEvent,
NodeConnectedEvent,
Expand All @@ -17,7 +18,6 @@
TrackStartEvent,
TrackStuckEvent,
)
from lavalink.models import AudioTrack

from bs4 import BeautifulSoup

Expand Down
8 changes: 4 additions & 4 deletions musicbot/utils/localisation/localizer/localizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _load_localization(self, lang):
def _parse_localization_dictionary(d, lookup, prefix=None):
n_dict = {}
for k, v in d.items():
if type(v) is str:
if isinstance(v, str):
n_dict[k] = Localizer._parse_localization_string(v, lookup, prefix)
else:
n_dict[k] = v
Expand Down Expand Up @@ -137,11 +137,11 @@ def format_dict(self, d, lang=None, prefix=None, **kvpairs):
cursorQueue = [nd]
while cursorQueue:
cursor = cursorQueue.pop()
for k, v in (cursor.items() if type(cursor) == dict else enumerate(cursor)):
if type(v) == str:
for k, v in (cursor.items() if isinstance(cursor, dict) else enumerate(cursor)):
if isinstance(v, str):
# insert translations based on lang
cursor[k] = self.format_str(v, lang, prefix, **kvpairs)
elif type(v) == dict or type(v) == list:
elif isinstance(v, dict) or isinstance(v, list):
cursorQueue.append(v)

return nd
Expand Down
2 changes: 1 addition & 1 deletion musicbot/utils/mixplayer/mixqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from random import shuffle
from typing import Generic, Iterable, Iterator, List, Optional, Tuple, TypeVar

from lavalink.models import AudioTrack
from lavalink import AudioTrack

# Would like to ensure the T has a "requester" attribute, but don't know if that is possible
T = TypeVar('T', bound=AudioTrack)
Expand Down
11 changes: 6 additions & 5 deletions musicbot/utils/mixplayer/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def play(self, track: Optional[AudioTrack] = None, start_time: int = 0):
await self.bassboost(False)
await self.nightcoreify(False)
await self.stop()
await self.node._dispatch_event(QueueEndEvent(self))
await self.client._dispatch_event(QueueEndEvent(self))
return
else:
# At this point track will not be None, as the queue is not empty
Expand All @@ -133,9 +133,9 @@ async def play(self, track: Optional[AudioTrack] = None, start_time: int = 0):
if track is None or track.track is None:
# Ignore, if the queue was empty we would have dispatched the event already
return
await self.node._send(op='play', guildId=str(self.guild_id),
track=track.track, startTime=start_time)
await self.node._dispatch_event(TrackStartEvent(self, track))
await self.play_track(track, start_time)

await self.client._dispatch_event(TrackStartEvent(self, track))
self.logger.info(f"Playing track: {track.title}")

async def skip(self, pos: int = 0):
Expand All @@ -149,7 +149,8 @@ async def skip(self, pos: int = 0):

async def stop(self):
"""Stops the player."""
await self.node._send(op='stop', guildId=str(self.guild_id))
# await self.node._send(op='stop', guildId=str(self.guild_id))
await super().stop()
self.current = None
self.queue.enable_looping(False)
self.logger.info("Music player stopped, clearing current track and stopping looping")
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ pythonpath = ["."]

[tool.ruff]
# Allow lines to be as long as 120 characters.
select = ["F", "E", "B", "W", "I001"]
lint.select = ["F", "E", "B", "W", "I001"]
line-length = 120

[tool.ruff.isort]
[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "discord", "third-party", "first-party", "local-folder"]
[tool.ruff.isort.sections]
[tool.ruff.lint.isort.sections]
"discord" = ["discord", "lavalink"]

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
discord.py == 2.3.*
lavalink == 4.0.*
lavalink == 5.3.*
asyncio
pyyaml
BeautifulSoup4
pytest
ruff==0.0.274
ruff
pre-commit
Loading