Skip to content

Commit b034b65

Browse files
committed
chore: fix linting issues
1 parent 1fa84ac commit b034b65

12 files changed

Lines changed: 357 additions & 312 deletions

File tree

bot.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2222
DEALINGS IN THE SOFTWARE.
2323
"""
24+
2425
from __future__ import annotations
2526

2627
import datetime
@@ -44,14 +45,14 @@
4445
PREMIUM_SKU_ID: Final[int] = 1256218013930094682
4546
log = logging.getLogger(__name__)
4647

48+
4749
class LegacyBotContext(commands.Context["LegacyBot"]):
48-
__slots__ = (
49-
'_cs_premium',
50-
)
50+
__slots__ = ('_cs_premium',)
5151

5252
guild: discord.Guild
53+
me: discord.Member
5354
author: discord.Member
54-
channel: discord.TextChannel | discord.VoiceChannel | discord.StageChannel | discord.ForumChannel
55+
channel: discord.TextChannel | discord.VoiceChannel | discord.StageChannel | discord.Thread
5556

5657
@property
5758
def reference(self) -> discord.MessageReference | None:
@@ -61,7 +62,9 @@ def reference(self) -> discord.MessageReference | None:
6162
@property
6263
def resolved_reference(self) -> discord.Message | None:
6364
""":class:`discord.Message`: The resolved reference message, or ``None``."""
64-
return self.reference and (self.reference.resolved or self.reference.cached_message) # pyright: ignore[reportReturnType]
65+
return self.reference and (
66+
self.reference.resolved or self.reference.cached_message
67+
) # pyright: ignore[reportReturnType]
6568

6669
@property
6770
def session(self) -> aiohttp.ClientSession:
@@ -103,13 +106,21 @@ async def is_premium(self) -> bool:
103106
return self._cs_premium
104107

105108
if self.interaction:
106-
prem = (
107-
(PREMIUM_SKU_ID in [e.sku_id for e in self.interaction.entitlements])
108-
or
109-
(PREMIUM_SKU_ID in self.interaction.entitlement_sku_ids)
109+
prem = (PREMIUM_SKU_ID in [e.sku_id for e in self.interaction.entitlements]) or (
110+
PREMIUM_SKU_ID in self.interaction.entitlement_sku_ids
110111
)
111112
else:
112-
prem = len([_ async for _ in self.bot.entitlements(user=self.author, guild=self.guild, skus=[discord.Object(PREMIUM_SKU_ID)])]) > 0
113+
prem = (
114+
len(
115+
[
116+
_
117+
async for _ in self.bot.entitlements(
118+
user=self.author, guild=self.guild, skus=[discord.Object(PREMIUM_SKU_ID)]
119+
)
120+
]
121+
)
122+
> 0
123+
)
113124

114125
self._cs_premium = prem
115126
return self._cs_premium
@@ -267,7 +278,8 @@ async def update_disabled_modules(self, guild_id: int, disabled_modules: list[st
267278
async with conn.transaction():
268279
await conn.execute(
269280
'UPDATE guilds SET disabled_modules = $1::text[] WHERE "id" = $2;',
270-
disabled_modules, guild_id,
281+
disabled_modules,
282+
guild_id,
271283
)
272284

273285
self._disabled_modules[guild_id] = disabled_modules
@@ -284,7 +296,8 @@ async def _create_or_cache_guild_config(self, guild_id: int) -> None:
284296
'WITH inserted AS '
285297
'(INSERT INTO guilds ("id", prefixes) VALUES ($1, $2::varchar[]) ON CONFLICT ("id") DO NOTHING RETURNING prefixes) '
286298
'SELECT prefixes FROM inserted UNION ALL SELECT prefixes FROM guilds WHERE "id" = $1 LIMIT 1;',
287-
guild_id, ['?'],
299+
guild_id,
300+
['?'],
288301
)
289302

290303
if data is None:
@@ -409,8 +422,7 @@ async def on_guild_join(self, guild: discord.Guild) -> None:
409422
guild.id,
410423
)
411424
await conn.execute(
412-
'INSERT INTO claimtimes_config (guild_id) VALUES ($1) ON CONFLICT (id) DO NOTHING;',
413-
guild.id
425+
'INSERT INTO claimtimes_config (guild_id) VALUES ($1) ON CONFLICT (id) DO NOTHING;', guild.id
414426
)
415427
# ensure context manager closure
416428
pass
@@ -455,17 +467,13 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
455467
embed.description = f'You need the {r} role to execute this command!'
456468
elif isinstance(error, commands.BotMissingPermissions):
457469
fmt = discord.utils._human_join(
458-
[m.replace('_', ' ').replace('guild', 'server').title()
459-
for m in error.missing_permissions
460-
],
470+
[m.replace('_', ' ').replace('guild', 'server').title() for m in error.missing_permissions],
461471
final='and',
462472
)
463473
embed.description = f'I need {fmt} permissions to execute this command!'
464474
elif isinstance(error, commands.MissingPermissions):
465475
fmt = discord.utils._human_join(
466-
[m.replace('_', ' ').replace('guild', 'server').title()
467-
for m in error.missing_permissions
468-
],
476+
[m.replace('_', ' ').replace('guild', 'server').title() for m in error.missing_permissions],
469477
final='and',
470478
)
471479
embed.description = f'You need {fmt} permissions to execute this command!'
@@ -504,7 +512,9 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
504512
elif isinstance(error, commands.ThreadNotFound):
505513
embed.description = f'Thread with name or ID "{error.argument}" was not found!'
506514
elif isinstance(error, commands.ChannelNotReadable):
507-
embed.description = f'I do not have Read Messages permissions on {error.argument.mention}, and I need it to execute the command!'
515+
embed.description = (
516+
f'I do not have Read Messages permissions on {error.argument.mention}, and I need it to execute the command!'
517+
)
508518
elif isinstance(error, commands.ChannelNotFound):
509519
embed.description = f'Channel with name or ID "{error.argument}" was not found!'
510520
elif isinstance(error, commands.UserNotFound):
@@ -537,7 +547,9 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
537547
elif isinstance(error, commands.PrivateMessageOnly):
538548
embed.description = 'This command can only be used on private messages!'
539549
elif isinstance(error, commands.BadLiteralArgument):
540-
embed.description = f'"{error.argument}" is not a valid choice available in {discord.utils._human_join(error.literals)}'
550+
embed.description = (
551+
f'"{error.argument}" is not a valid choice available in {discord.utils._human_join(error.literals)}'
552+
)
541553
elif isinstance(error, commands.BadUnionArgument):
542554
embed.description = f'"{error.param.name}" value was not valid!'
543555
elif isinstance(error, commands.ExpectedClosingQuoteError):
@@ -550,7 +562,9 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
550562
embed.description = 'You are missing one attachment to execute this command!'
551563
elif isinstance(error, commands.MissingRequiredArgument):
552564
assert context.command
553-
embed.description = f'`{error.param.name}` is missing! Make sure you follow the command syntax: `{context.command.signature}`'
565+
embed.description = (
566+
f'`{error.param.name}` is missing! Make sure you follow the command syntax: `{context.command.signature}`'
567+
)
554568
elif isinstance(error, ModuleDisabled):
555569
embed.description = str(error)
556570
else:
@@ -563,7 +577,7 @@ async def on_command_error(self, context: LegacyBotContext, error: commands.Comm
563577
if send_debug_log:
564578
await self.send_debug_message(
565579
embed=discord.Embed(
566-
title=f'An unknown error occurred on {context.command.name}',
580+
title=f'An unknown error occurred on {context.command.name if context.command else "a non-command context"}',
567581
description=f'Executed by: {context.author} ({context.author.id})\nExecution date: {discord.utils.format_dt(context.created_at)}',
568582
colour=discord.Colour.red(),
569583
).add_field(

0 commit comments

Comments
 (0)