Skip to content

Commit

Permalink
switched to using interaction_check as per request
Browse files Browse the repository at this point in the history
  • Loading branch information
FirePlank committed Nov 3, 2023
1 parent c01ba86 commit 456c5de
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions bot/extensions/clashofcode/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def role(self):
return self.bot.guild.get_role(settings.coc.role_id)

@session_commands.command(name="start")
@app_commands.check(lambda interaction: interaction.channel_id == settings.coc.channel_id)
async def session_start(self, interaction: core.InteractionType):
"""Start a new coc session"""

Expand Down Expand Up @@ -96,7 +95,6 @@ async def session_start(self, interaction: core.InteractionType):
break

@session_commands.command(name="join")
@app_commands.check(lambda interaction: interaction.channel_id == settings.coc.channel_id)
async def session_join(self, interaction: core.InteractionType):
"""Join the current active coc session"""

Expand All @@ -117,7 +115,6 @@ async def session_join(self, interaction: core.InteractionType):
return await interaction.response.send_message("You have joined the session. Have fun playing", ephemeral=True)

@session_commands.command(name="leave")
@app_commands.check(lambda interaction: interaction.channel_id == settings.coc.channel_id)
async def session_leave(self, interaction: core.InteractionType):
"""Leave the current active coc session"""

Expand All @@ -140,7 +137,6 @@ async def session_leave(self, interaction: core.InteractionType):
)

@session_commands.command(name="end")
@app_commands.check(lambda interaction: interaction.channel_id == settings.coc.channel_id)
async def session_end(self, interaction: core.InteractionType):
"""Ends the current coc session"""

Expand All @@ -167,11 +163,6 @@ async def session_end(self, interaction: core.InteractionType):
)

@app_commands.command(name="invite")
@app_commands.checks.has_any_role(
settings.moderation.staff_role_id,
settings.coc.role_id,
)
@app_commands.check(lambda interaction: interaction.channel_id == settings.coc.channel_id)
async def coc_invite(self, interaction: core.InteractionType, url: str):
"""Mentions all the users with the `Clash Of Code` role that are in the current session."""

Expand Down Expand Up @@ -272,18 +263,22 @@ async def coc_invite(self, interaction: core.InteractionType, url: str):

await interaction.channel.send(embed=embed)

async def cog_app_command_error(self, interaction: core.InteractionType, error):
if not isinstance(error, app_commands.CheckFailure):
return

if isinstance(error, app_commands.MissingAnyRole):
async def interaction_check(self, interaction: core.InteractionType):
if interaction.channel_id != settings.coc.channel_id:
await interaction.response.send_message(
"You need to have the Clash Of Code role to use this command", ephemeral=True
"You need to be in the Clash Of Code channel to use this command", ephemeral=True
)
else:
return False

if not any(
role.id in (settings.moderation.staff_role_id, settings.coc.role_id) for role in interaction.user.roles
):
await interaction.response.send_message(
"You need to be in the Clash Of Code channel to use this command", ephemeral=True
"You need to have the Clash Of Code role to use this command", ephemeral=True
)
return False

return True


async def setup(bot: core.DiscordBot):
Expand Down

0 comments on commit 456c5de

Please sign in to comment.