From 425e74b1324d0c9a79e38ca4cc62f1c1e7332cdb Mon Sep 17 00:00:00 2001 From: Sayan Bhattacharyya Date: Sun, 15 Dec 2024 22:30:00 +0530 Subject: [PATCH] fix(lint): reformat code --- bot.py | 16 ++++++++------- cogs/__error__.py | 7 +++++-- cogs/__eval__.py | 18 +++++++++++------ cogs/__topgg__.py | 6 ++++-- cogs/filters.py | 7 ++++--- cogs/general.py | 7 +++++-- cogs/music.py | 48 +++++++++++++++++++++++++++++++-------------- cogs/utility.py | 5 +++-- launcher.py | 9 +++++---- utils/checks.py | 2 +- utils/db.py | 4 +++- utils/helpers.py | 3 ++- utils/paginators.py | 6 +++--- utils/player.py | 2 +- utils/tools.py | 3 ++- 15 files changed, 92 insertions(+), 51 deletions(-) diff --git a/bot.py b/bot.py index 96a6f89..31126ec 100644 --- a/bot.py +++ b/bot.py @@ -1,27 +1,29 @@ from __future__ import annotations +from typing import Any + import logging from datetime import datetime from itertools import cycle -from typing import Any +import topgg import aiohttp -import aiomysql import discord -import topgg +import aiomysql import wavelink -from discord.app_commands import CommandTree -from discord.ext import commands, tasks +from discord.ext import tasks, commands from discord.ext.ipc import Server +from discord.app_commands import CommandTree -import config from utils.db import ( add_guild, guild_exists, - is_blacklisted_guild, is_blacklisted_user, + is_blacklisted_guild, ) +import config + class FumeTree(CommandTree): async def interaction_check(self, interaction: discord.Interaction) -> bool: diff --git a/cogs/__error__.py b/cogs/__error__.py index fa08da3..39bbc0f 100644 --- a/cogs/__error__.py +++ b/cogs/__error__.py @@ -1,9 +1,10 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import random import string import traceback -from typing import TYPE_CHECKING import discord from discord import app_commands @@ -95,7 +96,9 @@ async def app_command_error( await ctx.edit_original_response(content=message, view=None) except (discord.NotFound, discord.errors.NotFound): - await ctx.followup.send(content=message, ephemeral=True, view=None) + await ctx.followup.send( + content=message, ephemeral=True, view=None + ) else: # noinspection PyUnresolvedReferences await ctx.response.send_message( diff --git a/cogs/__eval__.py b/cogs/__eval__.py index 72a8adb..22ba804 100644 --- a/cogs/__eval__.py +++ b/cogs/__eval__.py @@ -1,21 +1,23 @@ from __future__ import annotations +from typing import TYPE_CHECKING + +import io import asyncio import inspect -import io -import subprocess import textwrap import traceback +import subprocess from contextlib import redirect_stdout -from typing import TYPE_CHECKING import discord from discord import app_commands from discord.ext import commands -from config import COMMUNITY_GUILD_ID from utils.modals import EvalModal, ExecModal +from config import COMMUNITY_GUILD_ID + if TYPE_CHECKING: from bot import FumeTune @@ -130,7 +132,9 @@ def _paginate(text: str): content=f"```py\n{page}\n```" ) else: - await modal.interaction.edit_original_response(content="\U00002705") + await modal.interaction.edit_original_response( + content="\U00002705" + ) else: try: @@ -177,7 +181,9 @@ async def _exec(self, ctx: discord.Interaction): timeout=300, ) - stdout_value = process.stdout.decode("utf-8") + process.stderr.decode("utf-8") + stdout_value = process.stdout.decode("utf-8") + process.stderr.decode( + "utf-8" + ) stdout_value = "\n".join(stdout_value.split("\n")[-25:]) await modal.interaction.edit_original_response( diff --git a/cogs/__topgg__.py b/cogs/__topgg__.py index 89d01ae..51a9048 100644 --- a/cogs/__topgg__.py +++ b/cogs/__topgg__.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING -from discord.ext import commands, tasks +from discord.ext import tasks, commands if TYPE_CHECKING: from bot import FumeTune @@ -18,7 +18,9 @@ async def _update_stats(self): await self.bot.topggpy.post_guild_count( guild_count=len(self.bot.guilds), shard_count=len(self.bot.shards) ) - self.bot.log.info(f"Posted server count ({self.bot.topggpy.guild_count})") + self.bot.log.info( + f"Posted server count ({self.bot.topggpy.guild_count})" + ) except Exception as e: self.bot.log.error(f"Failed to post server count", exc_info=e) diff --git a/cogs/filters.py b/cogs/filters.py index da6c7a9..fe0e35a 100644 --- a/cogs/filters.py +++ b/cogs/filters.py @@ -1,18 +1,19 @@ from __future__ import annotations -import collections from typing import TYPE_CHECKING, cast +import collections + import discord import wavelink -from discord import app_commands, ui +from discord import ui, app_commands from discord.ext import commands from utils.cd import cooldown_level_0 from utils.checks import initial_checks -from utils.helpers import is_privileged from utils.modals import FilterModal from utils.player import Player +from utils.helpers import is_privileged if TYPE_CHECKING: from bot import FumeTune diff --git a/cogs/general.py b/cogs/general.py index 21a6432..6285566 100644 --- a/cogs/general.py +++ b/cogs/general.py @@ -1,8 +1,9 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import math from datetime import datetime -from typing import TYPE_CHECKING import discord from discord import app_commands @@ -129,7 +130,9 @@ async def _review(self, ctx: discord.Interaction): view = discord.ui.View() view.add_item( - discord.ui.Button(label="Review", url="https://fumes.top/fumetune/review") + discord.ui.Button( + label="Review", url="https://fumes.top/fumetune/review" + ) ) await ctx.edit_original_response( diff --git a/cogs/music.py b/cogs/music.py index 171cad6..8c8f3c9 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -1,9 +1,10 @@ from __future__ import annotations +from typing import TYPE_CHECKING, Optional, cast + import json import random import string -from typing import TYPE_CHECKING, Optional, cast import discord import wavelink @@ -12,13 +13,13 @@ from discord.ext.menus.views import ViewMenuPages from utils.cd import cooldown_level_0 +from utils.tools import parse_duration +from utils.views import TrackConfirm, PlaylistConfirm from utils.checks import initial_checks -from utils.helpers import is_privileged, required_votes -from utils.paginators import QueuePaginatorSource from utils.player import Player +from utils.helpers import is_privileged, required_votes from utils.selects import TrackSelect -from utils.tools import parse_duration -from utils.views import PlaylistConfirm, TrackConfirm +from utils.paginators import QueuePaginatorSource if TYPE_CHECKING: from bot import FumeTune @@ -76,7 +77,9 @@ async def on_wavelink_track_exception( await self.bot.webhook.send(embed=embed) @commands.Cog.listener() - async def on_wavelink_track_stuck(self, payload: wavelink.TrackStuckEventPayload): + async def on_wavelink_track_stuck( + self, payload: wavelink.TrackStuckEventPayload + ): player: Player = cast(Player, payload.player) if not player: @@ -311,7 +314,9 @@ async def _search(self, ctx: discord.Interaction, query: str): embed.add_field( name="Name", value=( - f"**[{tracks.name}]({tracks.url})**" if tracks.url else tracks.name + f"**[{tracks.name}]({tracks.url})**" + if tracks.url + else tracks.name ), ) @@ -348,7 +353,9 @@ async def _search(self, ctx: discord.Interaction, query: str): f"({parse_duration(track.length)})\n\n" ) - options.append(discord.SelectOption(label=str(index), value=str(index))) + options.append( + discord.SelectOption(label=str(index), value=str(index)) + ) embed.description += ( "Select the song number within **a minute** to play it, " @@ -494,7 +501,9 @@ async def _resume(self, ctx: discord.Interaction): ) if not player.paused: - return await ctx.edit_original_response(content="The player is not paused.") + return await ctx.edit_original_response( + content="The player is not paused." + ) if is_privileged(ctx): player.resume_votes.clear() @@ -623,7 +632,8 @@ async def _replay(self, ctx: discord.Interaction): if not is_privileged(ctx): return await ctx.edit_original_response( - content="Only the DJ or admins may set the " "loop state of the player." + content="Only the DJ or admins may set the " + "loop state of the player." ) await player.seek() @@ -763,7 +773,9 @@ async def _remove(self, ctx: discord.Interaction, position: int): player.queue.delete(position - 1) - return await ctx.edit_original_response(content=f"That song has been removed!") + return await ctx.edit_original_response( + content=f"That song has been removed!" + ) @app_commands.command(name="flush") @app_commands.check(initial_checks) @@ -789,7 +801,9 @@ async def _flush(self, ctx: discord.Interaction): if is_privileged(ctx): player.queue.clear() - return await ctx.edit_original_response(content="Queue has been flushed!") + return await ctx.edit_original_response( + content="Queue has been flushed!" + ) else: return await ctx.edit_original_response( @@ -821,7 +835,9 @@ async def _shuffle(self, ctx: discord.Interaction): player.shuffle_votes.clear() player.queue.shuffle() - return await ctx.edit_original_response(content="Queue has been shuffled!") + return await ctx.edit_original_response( + content="Queue has been shuffled!" + ) required = required_votes(ctx) player.shuffle_votes.add(ctx.user) @@ -857,7 +873,8 @@ async def _loop(self, ctx: discord.Interaction): if not is_privileged(ctx): return await ctx.edit_original_response( - content="Only the DJ or admins may set the " "loop state of the player." + content="Only the DJ or admins may set the " + "loop state of the player." ) if not player.loop: @@ -886,7 +903,8 @@ async def _loop_queue(self, ctx: discord.Interaction): if not is_privileged(ctx): return await ctx.edit_original_response( - content="Only the DJ or admins may set the " "loop state of the player." + content="Only the DJ or admins may set the " + "loop state of the player." ) if len(player.queue) == 0: diff --git a/cogs/utility.py b/cogs/utility.py index 7000cad..3393c01 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -1,8 +1,9 @@ from __future__ import annotations -import textwrap from typing import TYPE_CHECKING, Optional +import textwrap + import discord from azapi import AZlyrics from discord import app_commands @@ -10,8 +11,8 @@ from discord.ext.menus.views import ViewMenuPages from utils.cd import cooldown_level_0, cooldown_level_1 -from utils.paginators import LyricsPaginatorSource from utils.tools import parse_duration +from utils.paginators import LyricsPaginatorSource if TYPE_CHECKING: from bot import FumeTune diff --git a/launcher.py b/launcher.py index a5a78ae..57f5515 100644 --- a/launcher.py +++ b/launcher.py @@ -1,19 +1,20 @@ from __future__ import annotations +import sys import asyncio -import contextlib import logging -import sys +import contextlib from datetime import datetime -import aiomysql import click import discord import pymysql +import aiomysql -import config from bot import FumeTune +import config + try: # noinspection PyUnresolvedReferences import uvloop diff --git a/utils/checks.py b/utils/checks.py index 3d10cc6..7420dd4 100644 --- a/utils/checks.py +++ b/utils/checks.py @@ -5,8 +5,8 @@ import discord from discord import app_commands -from .helpers import is_privileged from .player import Player +from .helpers import is_privileged def initial_checks(ctx: discord.Interaction) -> bool: diff --git a/utils/db.py b/utils/db.py index 23cc69b..cb2339f 100644 --- a/utils/db.py +++ b/utils/db.py @@ -21,7 +21,9 @@ async def guild_exists(pool: aiomysql.Pool, guild_id: int): async def add_guild(pool: aiomysql.Pool, guild_id: int): async with pool.acquire() as conn: async with conn.cursor() as cur: - await cur.execute("insert into guilds (GUILD_ID) values (%s);", (guild_id,)) + await cur.execute( + "insert into guilds (GUILD_ID) values (%s);", (guild_id,) + ) async def is_premium_user(pool: aiomysql.Pool, user_id: int): diff --git a/utils/helpers.py b/utils/helpers.py index b4b9662..9421a53 100644 --- a/utils/helpers.py +++ b/utils/helpers.py @@ -1,8 +1,9 @@ from __future__ import annotations -import math from typing import cast +import math + import discord from .player import Player diff --git a/utils/paginators.py b/utils/paginators.py index f8906d5..5c17bfa 100644 --- a/utils/paginators.py +++ b/utils/paginators.py @@ -5,10 +5,10 @@ import discord from discord.ext.menus import ListPageSource -import config - -from .player import Player from .tools import parse_duration +from .player import Player + +import config if TYPE_CHECKING: from discord.ext.menus import Menu diff --git a/utils/player.py b/utils/player.py index b4d337d..65c0a4b 100644 --- a/utils/player.py +++ b/utils/player.py @@ -2,9 +2,9 @@ import asyncio -import async_timeout import discord import wavelink +import async_timeout from utils.tools import parse_duration diff --git a/utils/tools.py b/utils/tools.py index 52f3735..d9e9eab 100644 --- a/utils/tools.py +++ b/utils/tools.py @@ -1,8 +1,9 @@ from __future__ import annotations -import datetime from typing import Union +import datetime + def parse_duration(duration: Union[int, float]): duration = round(duration / 1000) * 1000