refactor: follow more guidelines

This commit is contained in:
2025-04-03 17:32:44 -04:00
parent f360566824
commit ec31250153
20 changed files with 122 additions and 86 deletions

View File

@@ -1,11 +1,11 @@
import arguments
import disnake_paginator
from constants import EMBED_COLOR
from state import players
import arguments
import commands
import sponsorblock
import utils
from constants import EMBED_COLOR
from state import players
from .utils import command_allowed
@@ -13,7 +13,8 @@ from .utils import command_allowed
async def playing(message):
tokens = commands.tokenize(message.content)
parser = arguments.ArgumentParser(
tokens[0], "get information about the currently playing song"
tokens[0],
"get information about the currently playing song",
)
parser.add_argument(
"-d",
@@ -49,7 +50,7 @@ async def playing(message):
await utils.reply(
message,
embed=players[message.guild.id].current.embed(
is_paused=message.guild.voice_client.is_paused()
is_paused=message.guild.voice_client.is_paused(),
),
)
else:
@@ -94,7 +95,7 @@ async def fast_forward(message):
"-s",
"--seconds",
nargs="?",
type=lambda v: arguments.range_type(v, min=0, max=300),
type=lambda v: arguments.range_type(v, lower=0, upper=300),
help="the amount of seconds to fast forward instead",
)
if not (args := await parser.parse_args(message, tokens)):
@@ -110,11 +111,12 @@ async def fast_forward(message):
seconds = args.seconds
if not seconds:
video = await sponsorblock.get_segments(
players[message.guild.id].current.player.id
players[message.guild.id].current.player.id,
)
if not video:
await utils.reply(
message, "no sponsorblock segments were found for this video!"
message,
"no sponsorblock segments were found for this video!",
)
return
@@ -140,7 +142,7 @@ async def volume(message):
parser.add_argument(
"volume",
nargs="?",
type=lambda v: arguments.range_type(v, min=0, max=150),
type=lambda v: arguments.range_type(v, lower=0, upper=150),
help="the volume level (0 - 150)",
)
if not (args := await parser.parse_args(message, tokens)):

View File

@@ -20,14 +20,15 @@ async def queue_or_play(message, edited=False):
tokens = commands.tokenize(message.content)
parser = arguments.ArgumentParser(
tokens[0], "queue a song, list the queue, or resume playback"
tokens[0],
"queue a song, list the queue, or resume playback",
)
parser.add_argument("query", nargs="*", help="yt-dlp URL or query to get song")
parser.add_argument(
"-v",
"--volume",
default=50,
type=lambda v: arguments.range_type(v, min=0, max=150),
type=lambda v: arguments.range_type(v, lower=0, upper=150),
help="the volume level (0 - 150) for the specified song",
)
parser.add_argument(
@@ -140,8 +141,8 @@ async def queue_or_play(message, edited=False):
lambda queued: queued.trigger_message.author.id
== message.author.id,
players[message.guild.id].queue,
)
)
),
),
)
>= 5
and not len(message.guild.voice_client.channel.members) == 2
@@ -155,7 +156,9 @@ async def queue_or_play(message, edited=False):
try:
async with message.channel.typing():
player = await audio.youtubedl.YTDLSource.from_url(
" ".join(query), loop=client.loop, stream=True
" ".join(query),
loop=client.loop,
stream=True,
)
player.volume = float(args.volume) / 100.0
except Exception as e:
@@ -192,7 +195,7 @@ async def queue_or_play(message, edited=False):
[
queued.player.duration if queued.player.duration else 0
for queued in players[message.guild.id].queue
]
],
),
natural=True,
)
@@ -217,13 +220,14 @@ async def queue_or_play(message, edited=False):
[
f"**{i + 1}.** {queued.format(show_queuer=True, hide_preview=True, multiline=True)}"
for i, queued in batch
]
],
)
for batch in itertools.batched(
enumerate(players[message.guild.id].queue), 10
enumerate(players[message.guild.id].queue),
10,
)
],
)
),
),
).start(utils.MessageInteractionWrapper(message))
else:

View File

@@ -21,7 +21,8 @@ async def sponsorblock_command(message):
video = await sponsorblock.get_segments(players[message.guild.id].current.player.id)
if not video:
await utils.reply(
message, "no sponsorblock segments were found for this video!"
message,
"no sponsorblock segments were found for this video!",
)
return
@@ -33,7 +34,7 @@ async def sponsorblock_command(message):
current = "**" if progress >= begin and progress < end else ""
text.append(
f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category}{current}"
f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category}{current}",
)
await utils.reply(

View File

@@ -24,7 +24,8 @@ def play_next(message, once=False, first=False):
if message.guild.id in players and players[message.guild.id].queue:
queued = players[message.guild.id].queue_pop()
message.guild.voice_client.play(
queued.player, after=lambda e: play_after_callback(e, message, once)
queued.player,
after=lambda e: play_after_callback(e, message, once),
)
embed = queued.embed()