Skip to content

Commit

Permalink
soap: convert soap_check into cog_check
Browse files Browse the repository at this point in the history
The commands here are not meant to be used outside of this group of
users. Further decorators such as `is_staff()` may be applied for
individual commands.
  • Loading branch information
lifehackerhansol committed Sep 30, 2024
1 parent 0f6773c commit ab1da9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
13 changes: 9 additions & 4 deletions cogs/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import discord
from discord.ext import commands

from utils.checks import is_staff, soap_check
from utils.checks import is_staff, check_staff, InsufficientStaffRank

if TYPE_CHECKING:
from kurisu import Kurisu
Expand All @@ -26,6 +26,14 @@ def __init__(self, bot: Kurisu):
self.soaps_category: Optional[discord.CategoryChannel] = None
self.bot.loop.create_task(self.setup_soap())

async def cog_check(self, ctx: GuildContext):
author = ctx.author
if not check_staff(self.bot, 'Helper', author.id) and not check_staff(self.bot, 'Staff', author.id) and (
self.bot.roles['crc'] not in author.roles) and (self.bot.roles['Small Help'] not in author.roles):
raise InsufficientStaffRank("You can't use this command.")
return False
return True

async def setup_soap(self):
await self.bot.wait_until_all_ready()
db_channel = await self.bot.configuration.get_channel_by_name('soaps')
Expand All @@ -43,7 +51,6 @@ async def setsoaps(self, ctx: GuildContext, category: discord.CategoryChannel):
self.soaps_category = category
await ctx.send("Soaps category set.")

@soap_check()
@commands.guild_only()
@commands.command(aliases=["soup", "soap"])
async def createsoap(self, ctx: GuildContext, helpee: discord.Member):
Expand Down Expand Up @@ -101,7 +108,6 @@ async def deletesoap(self, ctx: GuildContext, channels: commands.Greedy[discord.
await ctx.send(f"Deleted :soap: {channel.name}.")
await channel.delete()

@soap_check()
@commands.guild_only()
@commands.command()
async def soapnormal(self, ctx: GuildContext):
Expand All @@ -114,7 +120,6 @@ async def soapnormal(self, ctx: GuildContext):
"Please let us know if the eShop functions or not."
)

@soap_check()
@commands.guild_only()
@commands.command()
async def soaplottery(self, ctx: GuildContext):
Expand Down
12 changes: 0 additions & 12 deletions utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ async def predicate(ctx):
return commands.check(predicate)


def soap_check():
async def predicate(ctx):
author = ctx.author
if not check_staff(ctx.bot, 'Helper', author.id) and not check_staff(ctx.bot, 'Staff', author.id) and (
ctx.bot.roles['crc'] not in author.roles) and (ctx.bot.roles['Small Help'] not in author.roles):
raise InsufficientStaffRank("You can't use this command.")
return False
return True

return commands.check(predicate)


def check_if_user_can_ready():
async def predicate(ctx):
channel = ctx.channel
Expand Down

0 comments on commit ab1da9d

Please sign in to comment.