From 02ce5b34a35f8aba52d65541df1fa05fe4426d6c Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Mon, 19 Jul 2021 13:00:56 -0600 Subject: [PATCH] Various admin bugfixes, closes #56 --- jarvis/cogs/admin.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/jarvis/cogs/admin.py b/jarvis/cogs/admin.py index 44e784a..865ed65 100644 --- a/jarvis/cogs/admin.py +++ b/jarvis/cogs/admin.py @@ -83,6 +83,9 @@ class AdminCog(commands.Cog): "You cannot set a temp ban to < 0 hours.", hidden=True ) return + if len(reason) > 100: + await ctx.send("Reason must be < 100 characters", hidden=True) + return if not reason: reason = ( "Mr. Stark is displeased with your presence. Please leave." @@ -179,7 +182,9 @@ class AdminCog(commands.Cog): user: str, reason: str, ): - await ctx.defer() + if len(reason) > 100: + await ctx.send("Reason must be < 100 characters", hidden=True) + return orig_user = user discrim = None @@ -244,7 +249,7 @@ class AdminCog(commands.Cog): database_ban_info = self.db.jarvis.bans.find_one(search) if not discord_ban_info and not database_ban_info: - await ctx.send(f"Unable to find user {orig_user}") + await ctx.send(f"Unable to find user {orig_user}", hidden=True) elif discord_ban_info: await self.discord_apply_unban(ctx, discord_ban_info.user, reason) @@ -311,7 +316,6 @@ class AdminCog(commands.Cog): self, ctx: SlashContext, type: int = 0, active: int = 1 ): active = bool(active) - await ctx.defer() types = [0, "perm", "temp", "soft"] search = {"guild": ctx.guild.id} if active: @@ -378,6 +382,9 @@ class AdminCog(commands.Cog): if user == self.bot.user: await ctx.send("I'm afraid I can't let you do that", hidden=True) return + if len(reason) > 100: + await ctx.send("Reason must be < 100 characters", hidden=True) + return if not reason: reason = ( "Mr. Stark is displeased with your presence. Please leave." @@ -465,13 +472,15 @@ class AdminCog(commands.Cog): async def _mute( self, ctx: SlashContext, user: Member, reason: str, length: int = 30 ): - await ctx.defer() if user == ctx.author: await ctx.send("You cannot mute yourself.", hidden=True) return if user == self.bot.user: await ctx.send("I'm afraid I can't let you do that", hidden=True) return + if len(reason) > 100: + await ctx.send("Reason must be < 100 characters", hidden=True) + return mute_setting = self.db.jarvis.settings.find_one( {"guild": ctx.guild.id, "setting": "mute"} ) @@ -525,7 +534,6 @@ class AdminCog(commands.Cog): ) @admin_or_permissions(mute_members=True) async def _unmute(self, ctx: SlashContext, user: Member): - await ctx.defer() mute_setting = self.db.jarvis.settings.find_one( {"guild": ctx.guild.id, "setting": "mute"} ) @@ -613,7 +621,10 @@ class AdminCog(commands.Cog): duration: int = 10, channel: Union[TextChannel, VoiceChannel] = None, ): - await ctx.defer() + await ctx.defer(hidden=True) + if len(reason) > 100: + await ctx.send("Reason must be < 100 characters", hidden=True) + return if not channel: channel = ctx.channel for role in ctx.guild.roles: @@ -652,7 +663,6 @@ class AdminCog(commands.Cog): ctx: SlashContext, channel: Union[TextChannel, VoiceChannel] = None, ): - await ctx.defer() if not channel: channel = ctx.channel lock = self.db.jarvis.locks.find_one( @@ -738,7 +748,6 @@ class AdminCog(commands.Cog): self, ctx: SlashContext, ): - await ctx.defer() channels = ctx.guild.channels roles = ctx.guild.roles updates = [] @@ -748,6 +757,7 @@ class AdminCog(commands.Cog): if not locks: await ctx.send("No lockdown detected.", hidden=True) return + await ctx.defer() for channel in channels: for role in roles: try: @@ -796,6 +806,9 @@ class AdminCog(commands.Cog): async def _warn( self, ctx: SlashContext, user: User, reason: str, duration: int = 24 ): + if len(reason) > 100: + await ctx.send("Reason must be < 100 characters", hidden=True) + return await ctx.defer() self.db.jarvis.warns.insert_one( { @@ -1051,7 +1064,7 @@ class AdminCog(commands.Cog): async def _autopurge_update( self, ctx: SlashContext, channel: TextChannel, delay: int ): - autopurge = self.db.jarvis.autopurge.find( + autopurge = self.db.jarvis.autopurge.find_one( {"guild": ctx.guild.id, "channel": channel.id} ) if not autopurge: