tuxbot-bot/tuxbot/cogs/Mod/functions/converters.py
Romain J 5afadb0f25 fix(commands:rule>list|Mod): fix order
fix(commands:rule|Mod): fix when <prefix>rule <non digit>
2021-05-14 17:35:50 +02:00

38 lines
974 B
Python

from discord.ext import commands
from discord.ext.commands import Context
from tuxbot.cogs.Mod.functions.exceptions import (
RuleTooLongException,
UnknownRuleException,
)
from tuxbot.cogs.Mod.models import Rule
def _(x):
return x
class RuleIDConverter(commands.Converter):
async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613
if not argument.isdigit():
raise UnknownRuleException(_("Unknown rule"))
arg = int(argument)
rule_row = await Rule.get_or_none(server_id=ctx.guild.id, rule_id=arg)
if not rule_row:
raise UnknownRuleException(_("Unknown rule"))
return arg
class RuleConverter(commands.Converter):
async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613
if len(argument) > 300:
raise RuleTooLongException(
_("Rule length must be 300 characters or lower.")
)
return argument