mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-05 13:56:51 +01:00
Some flake8 cleanup
This commit is contained in:
1 parent
506f2f8694
commit
df1745c2a8
5 files changed
+34
-39
No files matched your search
@@ -34,6 +34,6 @@ class Help(commands.Cog):
|
||||
else:
|
||||
paginator = await coghelper(ctx, thing)
|
||||
|
||||
scroller = Scroller(ctx, paginator,
|
||||
ScrollClearSettings.OnTimeout | ScrollClearSettings.OnInteractionExit)
|
||||
scroller = Scroller(ctx, paginator,
|
||||
ScrollClearSettings.OnTimeout | ScrollClearSettings.OnInteractionExit)
|
||||
await scroller.start_scrolling()
|
||||
@@ -184,7 +184,6 @@ class Music(commands.Cog):
|
||||
else:
|
||||
await ctx.send(ctx.localizer.format_str("{seek.missing_amount}"))
|
||||
|
||||
|
||||
@commands.command(name='skip')
|
||||
@require_voice_connection()
|
||||
@require_playing()
|
||||
@@ -200,7 +199,6 @@ class Music(commands.Cog):
|
||||
else:
|
||||
await ctx.send(ctx.localizer.format_str("{skip.skipped}"))
|
||||
|
||||
|
||||
@commands.command(name='skipto')
|
||||
@checks.dj_or(alone=True)
|
||||
@require_playing(require_user_listening=True)
|
||||
@@ -219,7 +217,6 @@ class Music(commands.Cog):
|
||||
msg = ctx.localizer.format_str("{skip_to.skipped_to}", _title=player.current.title, _pos=pos)
|
||||
await ctx.send(msg)
|
||||
|
||||
|
||||
@commands.command(name='stop')
|
||||
@require_voice_connection()
|
||||
@require_playing(require_user_listening=True)
|
||||
@@ -271,8 +268,7 @@ class Music(commands.Cog):
|
||||
await ctx.send(ctx.localizer.format_str("{resume.paused}"))
|
||||
else:
|
||||
await ctx.send(ctx.localizer.format_str("{resume.resumed}"))
|
||||
|
||||
|
||||
|
||||
@commands.command(name='shuffle')
|
||||
@require_voice_connection()
|
||||
@require_queue(require_author_queue=True)
|
||||
@@ -281,8 +277,7 @@ class Music(commands.Cog):
|
||||
player = self.bot.lavalink.player_manager.get(ctx.guild.id)
|
||||
player.shuffle_user_queue(ctx.author.id)
|
||||
await ctx.send(ctx.localizer.format_str("{shuffle}"))
|
||||
|
||||
|
||||
|
||||
@commands.command(name='move')
|
||||
@require_voice_connection()
|
||||
@require_queue(require_author_queue=True)
|
||||
@@ -299,17 +294,17 @@ class Music(commands.Cog):
|
||||
identifiers.append(ctx.localizer.format_str("{queue.usertrack}", _index=index+1,
|
||||
_globalindex=globpos+1, _title=track.title,
|
||||
_uri=track.uri))
|
||||
|
||||
|
||||
def ret_first_arg(*args):
|
||||
return args[0]
|
||||
|
||||
|
||||
functions = [ret_first_arg]*len(user_queue)
|
||||
arguments = [(i,) for i in range(len(user_queue))]
|
||||
|
||||
|
||||
# Set the different titles for the different selections
|
||||
round_titles = ["{moved.choose_song}", "{moved.choose_pos}"]
|
||||
round_titles = [ctx.localizer.format_str(i) for i in round_titles]
|
||||
|
||||
|
||||
selector = Selector(ctx, identifiers, functions, arguments, num_selections=5, round_titles=round_titles,
|
||||
color=ctx.me.color, title=ctx.localizer.format_str("{moved.choose}"))
|
||||
|
||||
@@ -860,7 +855,6 @@ class Music(commands.Cog):
|
||||
player.update_listeners(member, after)
|
||||
await self.check_leave_voice(member.guild)
|
||||
|
||||
|
||||
async def check_leave_voice(self, guild):
|
||||
""" Checks if the bot should leave the voice channel """
|
||||
# TODO, disconnect timer?
|
||||
|
||||
@@ -26,7 +26,8 @@ class BasicVoiceClient(discord.VoiceClient):
|
||||
async def on_voice_state_update(self, data):
|
||||
await self.lavalink.voice_update_handler({'t': 'VOICE_STATE_UPDATE', 'd': data})
|
||||
|
||||
async def connect(self, *, timeout: float, reconnect: bool, self_deaf: bool = False, self_mute: bool = False) -> None:
|
||||
async def connect(self, *, timeout: float, reconnect: bool, self_deaf: bool = False,
|
||||
self_mute: bool = False) -> None:
|
||||
await self.channel.guild.change_voice_state(channel=self.channel, self_mute=self_mute, self_deaf=self_deaf)
|
||||
|
||||
async def disconnect(self, *, force: bool = False) -> None:
|
||||
@@ -78,7 +79,6 @@ def require_voice_connection(should_connect=False):
|
||||
player.store('channel', ctx.channel.id)
|
||||
await ctx.author.voice.channel.connect(cls=BasicVoiceClient)
|
||||
|
||||
|
||||
elif int(player.channel_id) != ctx.author.voice.channel.id:
|
||||
bot_channel = self.bot.get_channel(int(player.channel_id))
|
||||
raise WrongVoiceChannelError(
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
import discord
|
||||
from enum import Flag, auto
|
||||
from typing import Callable, Any, Tuple
|
||||
|
||||
from lavalink.client import asyncio
|
||||
from .paginators import BasePaginator, CantScrollException
|
||||
|
||||
|
||||
class ScrollerButton(discord.ui.Button):
|
||||
def __init__(self, method, label, style=discord.ButtonStyle.gray, **kwargs):
|
||||
super().__init__(label=label, style=style, **kwargs)
|
||||
self.callback = method
|
||||
|
||||
|
||||
class ScrollerNav(discord.ui.Select):
|
||||
def __init__(self, method, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.callback = method
|
||||
|
||||
|
||||
class ScrollClearSettings(Flag):
|
||||
OnTimeout = auto()
|
||||
OnInteractionExit = auto()
|
||||
|
||||
|
||||
class ScrollerButton(discord.ui.Button):
|
||||
def __init__(self, callback, label, style=discord.ButtonStyle.gray, **kwargs):
|
||||
super().__init__(label=label, style=style, **kwargs)
|
||||
self.callback = callback
|
||||
|
||||
|
||||
class ScrollerNav(discord.ui.Select):
|
||||
def __init__(self, callback, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.callback = callback
|
||||
|
||||
|
||||
class Scroller:
|
||||
def __init__(self, ctx, paginator, clear_mode: ScrollClearSettings, timeout=20.0,
|
||||
with_nav_bar: bool = True):
|
||||
with_nav_bar: bool = True):
|
||||
|
||||
if not isinstance(paginator, BasePaginator):
|
||||
raise TypeError('Paginator needs to be a subclass of BasePaginator.')
|
||||
@@ -37,8 +36,8 @@ class Scroller:
|
||||
|
||||
# No embeds to scroll through
|
||||
if not self.paginator.pages:
|
||||
raise Exception("Paginator contained no pages to display") # TODO: proper error
|
||||
|
||||
raise Exception("Paginator contained no pages to display") # TODO: proper error
|
||||
|
||||
self.bot = ctx.bot
|
||||
self.channel = ctx.channel
|
||||
self.message = None
|
||||
@@ -84,7 +83,7 @@ class Scroller:
|
||||
|
||||
def build_view(self):
|
||||
for (reaction, callback) in self.interaction_mapping:
|
||||
self.view.add_item(item=ScrollerButton(method=callback, label=reaction, row=3))
|
||||
self.view.add_item(item=ScrollerButton(callback=callback, label=reaction, row=3))
|
||||
|
||||
if self.use_nav_bar:
|
||||
self.navigator = ScrollerNav(self.navigate, placeholder="Navigate to page", row=4)
|
||||
@@ -97,7 +96,7 @@ class Scroller:
|
||||
self.view.stop()
|
||||
self.view.clear_items()
|
||||
if (user_stopped and self.clear_mode & ScrollClearSettings.OnInteractionExit or
|
||||
not user_stopped and self.clear_mode & ScrollClearSettings.OnTimeout):
|
||||
not user_stopped and self.clear_mode & ScrollClearSettings.OnTimeout):
|
||||
await self.message.delete()
|
||||
self.message = None
|
||||
await self.ctx.message.delete()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# Discord Packages
|
||||
from __future__ import annotations
|
||||
from locale import resetlocale
|
||||
import discord
|
||||
|
||||
import asyncio
|
||||
@@ -10,8 +9,10 @@ from typing import List, Callable, Coroutine
|
||||
from .paginators import TextPaginator
|
||||
from .scroller import ScrollClearSettings, Scroller
|
||||
|
||||
|
||||
class SelectorButton(discord.ui.Button):
|
||||
def __init__(self, label, callback: Callable[[discord.Interaction, SelectorButton], Coroutine], style=discord.ButtonStyle.gray, **kwargs):
|
||||
def __init__(self, label, callback: Callable[[discord.Interaction, SelectorButton], Coroutine],
|
||||
style=discord.ButtonStyle.gray, **kwargs):
|
||||
super().__init__(label=label, style=style, **kwargs)
|
||||
|
||||
# The callback we need to supply to disord.py takes only a discord.Interaction
|
||||
@@ -32,7 +33,8 @@ class SelectorItem:
|
||||
|
||||
|
||||
class Selector2(TextPaginator, Scroller):
|
||||
def __init__(self, ctx, choices: List[SelectorItem], round_titles=None, terminate_on_select: bool = True, max_size=2000, **embed_base):
|
||||
def __init__(self, ctx, choices: List[SelectorItem], round_titles=None,
|
||||
terminate_on_select: bool = True, max_size=2000, **embed_base):
|
||||
self.match = None
|
||||
if round_titles is None:
|
||||
round_titles = []
|
||||
@@ -58,7 +60,7 @@ class Selector2(TextPaginator, Scroller):
|
||||
# The list of currently visible buttons, gets cleared upon scroll.
|
||||
self.visible_buttons = []
|
||||
|
||||
# Depending on the selector we might want the result of callbacks
|
||||
# Depending on the selector we might want the result of callbacks
|
||||
# after we have finished interacting with the scroller
|
||||
self.callback_results = []
|
||||
|
||||
@@ -91,7 +93,7 @@ class Selector2(TextPaginator, Scroller):
|
||||
self.current_page_number
|
||||
start = self.current_page_number * self.max_selections_per_page
|
||||
end = min((self.current_page_number + 1) * self.max_selections_per_page, len(self.selections))
|
||||
|
||||
|
||||
for button in self.buttons[start:end]:
|
||||
self.view.add_item(item=button)
|
||||
self.visible_buttons.append(button)
|
||||
|
||||
Reference in new issue
Block a user