Skip to content

Commit bb92c9c

Browse files
committed
format all files using ruff instead
1 parent f3e397c commit bb92c9c

27 files changed

+435
-207
lines changed

.pre-commit-config.yaml

-47
This file was deleted.

bot/cogs/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ def __str__(self) -> str:
1212
return f"{self.major}.{self.minor}.{self.micro}-{self.releaselevel}"
1313

1414

15-
EXTENSIONS = [module.name for module in iter_modules(__path__, f"{__package__}.")]
16-
VERSION: VersionInfo = VersionInfo(major=0, minor=3, micro=1, releaselevel="final")
15+
EXTENSIONS = [
16+
module.name for module in iter_modules(__path__, f"{__package__}.")
17+
]
18+
VERSION: VersionInfo = VersionInfo(
19+
major=0, minor=3, micro=1, releaselevel="final"
20+
)

bot/cogs/admin.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def tick(self, opt: Optional[bool], label: Optional[str] = None) -> str:
7474

7575
def format_results(self, statuses: list) -> str:
7676
desc = "\U00002705 - Successful reload | \U0000274c - Failed reload | \U000023e9 - Skipped\n\n"
77-
status = "\n".join(f"- {status}: `{module}`" for status, module in statuses)
77+
status = "\n".join(
78+
f"- {status}: `{module}`" for status, module in statuses
79+
)
7880
desc += status
7981
return desc
8082

@@ -159,11 +161,10 @@ async def reload(self, ctx: RoboContext) -> None:
159161
modules = self.find_modules_from_git(stdout)
160162

161163
mods_text = "\n".join(
162-
f"{index}. `{module}`" for index, (_, module) in enumerate(modules, start=1)
163-
)
164-
prompt_text = (
165-
f"This will update the following modules, are you sure?\n{mods_text}"
164+
f"{index}. `{module}`"
165+
for index, (_, module) in enumerate(modules, start=1)
166166
)
167+
prompt_text = f"This will update the following modules, are you sure?\n{mods_text}"
167168

168169
confirm = await ctx.prompt(prompt_text)
169170
if not confirm:

bot/cogs/config.py

+80-34
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ async def _load(self, connection: Union[asyncpg.Connection, asyncpg.Pool]):
8282
"""
8383
rows = await connection.fetch(query)
8484
return {
85-
row["entity_id"]: BlocklistEntity(bot=self.bot, **dict(row)) for row in rows
85+
row["entity_id"]: BlocklistEntity(bot=self.bot, **dict(row))
86+
for row in rows
8687
}
8788

8889
async def load(self, connection: Optional[asyncpg.Connection] = None):
@@ -246,7 +247,9 @@ def __init__(self, entry: ConfigHelpEntry, **kwargs):
246247
self.title = entry.key
247248
self.description = entry.description
248249
self.add_field(name="Default", value=entry.default, inline=False)
249-
self.add_field(name="Example(s)", value="\n".join(entry.examples), inline=False)
250+
self.add_field(
251+
name="Example(s)", value="\n".join(entry.examples), inline=False
252+
)
250253
self.add_field(
251254
name="Notes",
252255
value="\n".join(f"- {note}" for note in entry.notes) or None,
@@ -275,7 +278,9 @@ def __init__(self, entries: dict[str, Any], active: Optional[bool] = None):
275278
super().__init__(self.config_iterator(entries), per_page=20)
276279
self.active = active
277280

278-
async def config_iterator(self, entries: dict[str, Any]) -> AsyncIterator[str]:
281+
async def config_iterator(
282+
self, entries: dict[str, Any]
283+
) -> AsyncIterator[str]:
279284
for key, entry in entries.items():
280285
result = f"**{key}:** {entry}"
281286
# Wtf is wrong with me - Noelle
@@ -288,7 +293,9 @@ async def config_iterator(self, entries: dict[str, Any]) -> AsyncIterator[str]:
288293

289294
async def format_page(self, menu: ConfigPages, entries: list[str]):
290295
pages = []
291-
for _, entry in enumerate(entries, start=menu.current_page * self.per_page):
296+
for _, entry in enumerate(
297+
entries, start=menu.current_page * self.per_page
298+
):
292299
pages.append(f"{entry}")
293300

294301
menu.embed.description = "\n".join(pages)
@@ -304,7 +311,9 @@ def __init__(
304311
active: Optional[bool] = None,
305312
):
306313
super().__init__(ConfigPageSource(entries, active), ctx=ctx)
307-
self.embed = discord.Embed(colour=discord.Colour.from_rgb(200, 168, 255))
314+
self.embed = discord.Embed(
315+
colour=discord.Colour.from_rgb(200, 168, 255)
316+
)
308317

309318

310319
class ConfigOptionFlags(commands.FlagConverter):
@@ -345,7 +354,9 @@ async def convert(self, ctx: GuildContext, argument: str) -> str:
345354
raise RuntimeError("Unable to get Config cog")
346355

347356
if lowered not in cog.config_keys:
348-
raise commands.BadArgument(self.disambiguate(lowered, cog.config_keys))
357+
raise commands.BadArgument(
358+
self.disambiguate(lowered, cog.config_keys)
359+
)
349360

350361
return lowered
351362

@@ -369,7 +380,9 @@ class PrefixConverter(commands.Converter):
369380
async def convert(self, ctx: GuildContext, argument: str):
370381
user_id = ctx.bot.user.id # type: ignore # Already logged in by this time
371382
if argument.startswith((f"<@{user_id}>", f"<@!{user_id}>", "r>")):
372-
raise commands.BadArgument("That is a reserved prefix already in use.")
383+
raise commands.BadArgument(
384+
"That is a reserved prefix already in use."
385+
)
373386
if len(argument) > 100:
374387
raise commands.BadArgument("That prefix is too long.")
375388
return argument
@@ -412,10 +425,10 @@ async def get_guild_config(self, guild_id: int) -> Optional[GuildConfig]:
412425
return config
413426

414427
@alru_cache()
415-
async def get_guild_settings(self, guild_id: int) -> Optional[GuildSettings]:
416-
query = (
417-
"SELECT account_age, guild_age, settings FROM guild_config WHERE id = $1;"
418-
)
428+
async def get_guild_settings(
429+
self, guild_id: int
430+
) -> Optional[GuildSettings]:
431+
query = "SELECT account_age, guild_age, settings FROM guild_config WHERE id = $1;"
419432
rows = await self.pool.fetchrow(query, guild_id)
420433
if rows is None:
421434
self.get_guild_settings.cache_invalidate(guild_id)
@@ -447,7 +460,9 @@ async def set_guild_settings(
447460
config_type: ConfigType,
448461
ctx: GuildContext,
449462
):
450-
current_guild_settings = await self.get_partial_guild_settings(ctx.guild.id)
463+
current_guild_settings = await self.get_partial_guild_settings(
464+
ctx.guild.id
465+
)
451466

452467
# If there are no guild configurations, then we have an issue here
453468
# we will denote this with an error
@@ -473,12 +488,20 @@ async def set_guild_settings(
473488
self.get_partial_guild_settings.cache_invalidate(ctx.guild.id)
474489

475490
command_type = "Toggled" if config_type == ConfigType.TOGGLE else "Set"
476-
await ctx.send(f"{command_type} `{key}` from `{original_value}` to `{value}`")
491+
await ctx.send(
492+
f"{command_type} `{key}` from `{original_value}` to `{value}`"
493+
)
477494

478495
### Blocklist utilities
479496

480-
async def can_be_blocked(self, ctx: GuildContext, entity: discord.Member) -> bool:
481-
if entity.id == ctx.author.id or await self.bot.is_owner(entity) or entity.bot:
497+
async def can_be_blocked(
498+
self, ctx: GuildContext, entity: discord.Member
499+
) -> bool:
500+
if (
501+
entity.id == ctx.author.id
502+
or await self.bot.is_owner(entity)
503+
or entity.bot
504+
):
482505
return False
483506

484507
# Hierarchy check
@@ -579,9 +602,7 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
579602
manage_threads=True,
580603
),
581604
}
582-
lgc_reason = (
583-
f"{ctx.author} (ID: {ctx.author.id}) has created the Rodhaj logs channel"
584-
)
605+
lgc_reason = f"{ctx.author} (ID: {ctx.author.id}) has created the Rodhaj logs channel"
585606

586607
# The rationale behind the restriction of posts is to make sure that
587608
# people don't create posts of their own, thus messing up the code for the bot
@@ -605,7 +626,9 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
605626
),
606627
discord.ForumTag(
607628
name="Serious",
608-
emoji=discord.PartialEmoji(name="\U0001f610"), # U+1F610 Neutral Face
629+
emoji=discord.PartialEmoji(
630+
name="\U0001f610"
631+
), # U+1F610 Neutral Face
609632
),
610633
discord.ForumTag(
611634
name="Private",
@@ -635,7 +658,9 @@ async def setup(self, ctx: GuildContext, *, flags: SetupFlags) -> None:
635658
name="rodhaj", overwrites=rodhaj_overwrites, position=0
636659
)
637660
logging_channel = await rodhaj_category.create_text_channel(
638-
name=flags.log_name or "rodhaj-logs", reason=lgc_reason, position=0
661+
name=flags.log_name or "rodhaj-logs",
662+
reason=lgc_reason,
663+
position=0,
639664
)
640665
lgc_webhook = await logging_channel.create_webhook(
641666
name="Rodhaj Ticket Logs", avatar=avatar_bytes
@@ -707,9 +732,7 @@ async def delete(self, ctx: GuildContext) -> None:
707732
confirm = await ctx.prompt(msg, timeout=300.0, delete_after=True)
708733
if confirm:
709734
if guild_config is None:
710-
msg = (
711-
"Could not find the guild config. Perhaps Rodhaj is not set up yet?"
712-
)
735+
msg = "Could not find the guild config. Perhaps Rodhaj is not set up yet?"
713736
await ctx.send(msg)
714737
return
715738

@@ -786,7 +809,9 @@ async def config_options(
786809
await ctx.send(msg)
787810
return
788811

789-
pages = ConfigPages(guild_settings.to_dict(), ctx=ctx, active=flags.active)
812+
pages = ConfigPages(
813+
guild_settings.to_dict(), ctx=ctx, active=flags.active
814+
)
790815
await pages.start()
791816

792817
@is_manager()
@@ -798,7 +823,9 @@ async def config_help(
798823
) -> None:
799824
"""Shows help information for different configuration options"""
800825
# Because we are using the converter, all options are guaranteed to be correct
801-
embed = ConfigEntryEmbed(ConfigHelpEntry(key=key, **self.options_help[key]))
826+
embed = ConfigEntryEmbed(
827+
ConfigHelpEntry(key=key, **self.options_help[key])
828+
)
802829
await ctx.send(embed=embed)
803830

804831
@is_manager()
@@ -829,7 +856,8 @@ async def config_set_age(
829856
type: Literal["guild", "account"],
830857
*,
831858
duration: Annotated[
832-
FriendlyTimeResult, UserFriendlyTime(commands.clean_content, default="…")
859+
FriendlyTimeResult,
860+
UserFriendlyTime(commands.clean_content, default="…"),
833861
],
834862
) -> None:
835863
"""Sets an minimum duration for age-related options
@@ -880,7 +908,9 @@ async def config_set(
880908
)
881909
return
882910

883-
await self.set_guild_settings(key, value, config_type=ConfigType.SET, ctx=ctx)
911+
await self.set_guild_settings(
912+
key, value, config_type=ConfigType.SET, ctx=ctx
913+
)
884914

885915
@is_manager()
886916
@commands.guild_only()
@@ -890,7 +920,11 @@ async def config_set(
890920
value="Boolean option to set the configuration",
891921
)
892922
async def config_toggle(
893-
self, ctx: GuildContext, key: Annotated[str, ConfigKeyConverter], *, value: bool
923+
self,
924+
ctx: GuildContext,
925+
key: Annotated[str, ConfigKeyConverter],
926+
*,
927+
value: bool,
894928
) -> None:
895929
"""Toggles an boolean option for configuration
896930
@@ -1010,7 +1044,9 @@ async def prefix_edit(
10101044
get_prefix.cache_invalidate(self.bot, ctx.message)
10111045
await ctx.send(f"Prefix updated to from `{old}` to `{new}`")
10121046
else:
1013-
await ctx.send("The prefix is not in the list of prefixes for your server")
1047+
await ctx.send(
1048+
"The prefix is not in the list of prefixes for your server"
1049+
)
10141050

10151051
@is_manager()
10161052
@commands.guild_only()
@@ -1030,7 +1066,9 @@ async def prefix_delete(
10301066
if confirm:
10311067
await self.pool.execute(query, prefix, ctx.guild.id)
10321068
get_prefix.cache_invalidate(self.bot, ctx.message)
1033-
await ctx.send(f"The prefix `{prefix}` has been successfully deleted")
1069+
await ctx.send(
1070+
f"The prefix `{prefix}` has been successfully deleted"
1071+
)
10341072
elif confirm is None:
10351073
await ctx.send("Confirmation timed out. Cancelled deletion...")
10361074
else:
@@ -1043,7 +1081,9 @@ async def prefix_delete(
10431081
# 4. Is the author themselves trying to get blocklisted?
10441082
# This system must be addressed with care as it is extremely dangerous
10451083
# TODO: Add an history command to view past history of entity
1046-
@check_permissions(manage_messages=True, manage_roles=True, moderate_members=True)
1084+
@check_permissions(
1085+
manage_messages=True, manage_roles=True, moderate_members=True
1086+
)
10471087
@commands.guild_only()
10481088
@commands.hybrid_group(name="blocklist", fallback="info")
10491089
async def blocklist(self, ctx: GuildContext) -> None:
@@ -1052,7 +1092,9 @@ async def blocklist(self, ctx: GuildContext) -> None:
10521092
pages = BlocklistPages([entry for entry in blocklist.values()], ctx=ctx)
10531093
await pages.start()
10541094

1055-
@check_permissions(manage_messages=True, manage_roles=True, moderate_members=True)
1095+
@check_permissions(
1096+
manage_messages=True, manage_roles=True, moderate_members=True
1097+
)
10561098
@commands.guild_only()
10571099
@blocklist.command(name="add")
10581100
@app_commands.describe(
@@ -1113,11 +1155,15 @@ async def blocklist_add(
11131155
)
11141156
await ctx.send(f"{entity.mention} has been blocked")
11151157

1116-
@check_permissions(manage_messages=True, manage_roles=True, moderate_members=True)
1158+
@check_permissions(
1159+
manage_messages=True, manage_roles=True, moderate_members=True
1160+
)
11171161
@commands.guild_only()
11181162
@blocklist.command(name="remove")
11191163
@app_commands.describe(entity="The member to remove from the blocklist")
1120-
async def blocklist_remove(self, ctx: GuildContext, entity: discord.Member) -> None:
1164+
async def blocklist_remove(
1165+
self, ctx: GuildContext, entity: discord.Member
1166+
) -> None:
11211167
"""Removes an member from the blocklist"""
11221168
if not await self.can_be_blocked(ctx, entity):
11231169
await ctx.send("Failed to unblock entity")

0 commit comments

Comments
 (0)