update(commands:mute|Mod): add reason as optional

This commit is contained in:
Romain J 2021-05-17 00:20:56 +02:00
parent 7b50af0207
commit f06bfd7e24
2 changed files with 13 additions and 9 deletions

View file

@ -57,6 +57,9 @@ class BotMessageConverter(commands.Converter):
class ReasonConverter(commands.Converter): class ReasonConverter(commands.Converter):
async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613 async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613
if argument is None:
return f"{ctx.author.display_name} (ID: {ctx.author.id})"
if len(argument) > 300: if len(argument) > 300:
raise ReasonTooLongException( raise ReasonTooLongException(
_("Reason length must be 300 characters or lower.") _("Reason length must be 300 characters or lower.")

View file

@ -1,5 +1,6 @@
import logging import logging
from datetime import datetime from datetime import datetime
from typing import Optional
import discord import discord
from discord.ext import commands from discord.ext import commands
@ -281,7 +282,7 @@ class Mod(commands.Cog):
ctx: ContextPlus, ctx: ContextPlus,
members: commands.Greedy[discord.Member], members: commands.Greedy[discord.Member],
*, *,
reason: ReasonConverter, reason: Optional[ReasonConverter],
): ):
if not members: if not members:
return await ctx.send(_("Missing members", ctx, self.bot.config)) return await ctx.send(_("Missing members", ctx, self.bot.config))
@ -355,14 +356,14 @@ class Mod(commands.Cog):
@commands.guild_only() @commands.guild_only()
@checks.is_admin() @checks.is_admin()
async def _tempmute( async def _tempmute(
self, self,
ctx: ContextPlus, ctx: ContextPlus,
time, time,
members: discord.Member, members: discord.Member,
*, *,
reason: ReasonConverter, reason: Optional[ReasonConverter],
): ):
... _, _, _, _ = ctx, time, members, reason
# ========================================================================= # =========================================================================
@ -377,7 +378,7 @@ class Mod(commands.Cog):
ctx: ContextPlus, ctx: ContextPlus,
members: commands.Greedy[discord.Member], members: commands.Greedy[discord.Member],
*, *,
reason: ReasonConverter, reason: Optional[ReasonConverter],
): ):
if not members: if not members:
return await ctx.send(_("Missing members", ctx, self.bot.config)) return await ctx.send(_("Missing members", ctx, self.bot.config))