misc(suggestions): improved code structure
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
Seaswimmer 2023-09-22 12:07:06 -04:00
parent 480ff5915f
commit b74569e4eb
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -47,7 +47,7 @@ class Suggestions(commands.Cog):
else: else:
return f"{user.name}#{user.discriminator}" return f"{user.name}#{user.discriminator}"
async def red_delete_data_for_user(self, *, requester, user_id): async def red_delete_data_for_user(self, *, requester, user_id: discord.User.id):
# per guild suggestions # per guild suggestions
for guild in self.bot.guilds: for guild in self.bot.guilds:
for suggestion_id in range(1, await self.config.guild(guild).next_id()): for suggestion_id in range(1, await self.config.guild(guild).next_id()):
@ -136,7 +136,7 @@ class Suggestions(commands.Cog):
reason: typing.Optional[str], reason: typing.Optional[str],
): ):
"""Approve a suggestion.""" """Approve a suggestion."""
await self._finish_suggestion(ctx, suggestion_id, True, reason, ctx.author) await self._finish_suggestion(ctx, suggestion_id, True, reason)
@checks.admin() @checks.admin()
@commands.command() @commands.command()
@ -150,7 +150,7 @@ class Suggestions(commands.Cog):
reason: typing.Optional[str], reason: typing.Optional[str],
): ):
"""Deny a suggestion. Reason is optional.""" """Deny a suggestion. Reason is optional."""
await self._finish_suggestion(ctx, suggestion_id, False, reason, ctx.author) await self._finish_suggestion(ctx, suggestion_id, False, reason)
@checks.admin() @checks.admin()
@commands.command() @commands.command()
@ -394,7 +394,7 @@ class Suggestions(commands.Cog):
await ctx.send(embed=embed) await ctx.send(embed=embed)
@commands.Cog.listener() @commands.Cog.listener()
async def on_reaction_add(self, reaction, user): async def on_reaction_add(self, reaction: discord.Reaction, user: discord.Message):
message = reaction.message message = reaction.message
if user.id == self.bot.user.id: if user.id == self.bot.user.id:
return return
@ -409,7 +409,7 @@ class Suggestions(commands.Cog):
): ):
await message_reaction.remove(user) await message_reaction.remove(user)
async def _get_results(self, ctx, message): async def _get_results(self, ctx: commands.Context, message: discord.Message):
up_emoji, down_emoji = await self._get_emojis(ctx) up_emoji, down_emoji = await self._get_emojis(ctx)
up_count = 0 up_count = 0
down_count = 0 down_count = 0
@ -422,7 +422,7 @@ class Suggestions(commands.Cog):
return f"{up_count}x {up_emoji}\n{down_count}x {down_emoji}" return f"{up_count}x {up_emoji}\n{down_count}x {down_emoji}"
async def _get_emojis(self, ctx): async def _get_emojis(self, ctx: typing.Union[commands.Context, discord.Interaction]):
up_emoji = self.bot.get_emoji(await self.config.guild(ctx.guild).up_emoji()) up_emoji = self.bot.get_emoji(await self.config.guild(ctx.guild).up_emoji())
if not up_emoji: if not up_emoji:
up_emoji = "✅" up_emoji = "✅"
@ -431,8 +431,9 @@ class Suggestions(commands.Cog):
down_emoji = "❎" down_emoji = "❎"
return up_emoji, down_emoji return up_emoji, down_emoji
async def _finish_suggestion(self, ctx, suggestion_id, approve, reason, author): async def _finish_suggestion(self, ctx: commands.Context, suggestion_id: int, approve: bool, reason: str):
server = ctx.guild.id server = ctx.guild.id
author = ctx.author
old_channel = ctx.guild.get_channel( old_channel = ctx.guild.get_channel(
await self.config.guild(ctx.guild).suggest_id() await self.config.guild(ctx.guild).suggest_id()
) )
@ -510,7 +511,7 @@ class Suggestions(commands.Cog):
) )
await ctx.tick() await ctx.tick()
async def _interaction_get_results(self, interaction: discord.Interaction, message): async def _interaction_get_results(self, interaction: discord.Interaction, message: discord.Message):
up_emoji, down_emoji = await self._get_emojis(interaction) up_emoji, down_emoji = await self._get_emojis(interaction)
up_count = 0 up_count = 0
down_count = 0 down_count = 0
@ -523,15 +524,6 @@ class Suggestions(commands.Cog):
return f"{up_count}x {up_emoji}\n{down_count}x {down_emoji}" return f"{up_count}x {up_emoji}\n{down_count}x {down_emoji}"
async def _interaction_get_emojis(self, interaction: discord.Interaction):
up_emoji = self.bot.get_emoji(await self.config.guild(interaction.guild).up_emoji())
if not up_emoji:
up_emoji = "✅"
down_emoji = self.bot.get_emoji(await self.config.guild(interaction.guild).down_emoji())
if not down_emoji:
down_emoji = "❎"
return up_emoji, down_emoji
async def _interaction_finish_suggestion(self, interaction: discord.Interaction, message: discord.Message, approve: bool, reason: str = None): async def _interaction_finish_suggestion(self, interaction: discord.Interaction, message: discord.Message, approve: bool, reason: str = None):
embed = message.embeds embed = message.embeds
title = embed[0].title title = embed[0].title