Files
payphone/payphone/core/checks.py
T

52 lines
1.2 KiB
Python

from discord.ext import commands
from payphone.db import utils
from payphone.core import exceptions, constants
def is_moderator():
"""Checks whether the user is a moderator or not."""
async def predicate(ctx: commands.Context) -> bool:
if ctx.author.bot:
return False
user, _ = await utils.get_user(ctx.author)
if user.is_moderator:
return True
raise exceptions.NotAModeratorError()
return commands.check(predicate)
def is_unbanned():
"""Checks that the user is not banned."""
async def predicate(ctx: commands.Context) -> bool:
if await ctx.bot.is_banned(ctx.author):
raise exceptions.BannedError()
return True
return commands.check(predicate)
def is_on_call():
"""Checks that a call is ongoing in the channel."""
async def predicate(ctx: commands.Context) -> bool:
channel_id = ctx.channel.id
is_on_call = await ctx.bot.redis.sismember(
constants.CHANNELS_ONCALL_SET, str(channel_id)
)
if not is_on_call:
raise exceptions.NotOnCallError()
return True
return commands.check(predicate)