From ebe59c937063a30e3fd2e52f90cf69fc810b1082 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 22 Jul 2020 15:25:31 -0400 Subject: [PATCH] Reapply case-insensitivity and get off that command_error train (#101) * Reapply case-insensitivity and get off that command_error train * Can't forget their check, thanks again Cog-Creators This will continue with CCRole being a case-insensitive cog, until the day I change my mind by making this a subclass of CustomCom --- ccrole/ccrole.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/ccrole/ccrole.py b/ccrole/ccrole.py index d2e4fc1..b07897b 100644 --- a/ccrole/ccrole.py +++ b/ccrole/ccrole.py @@ -1,14 +1,11 @@ import asyncio -import json import re -from typing import Any import discord from discord.ext.commands.view import StringView -from redbot.core import Config, checks -from redbot.core import commands +from redbot.core import Config, checks, commands from redbot.core.bot import Red -from redbot.core.utils.chat_formatting import pagify, box +from redbot.core.utils.chat_formatting import box, pagify class CCRole(commands.Cog): @@ -236,10 +233,30 @@ class CCRole(commands.Cog): await ctx.send("Command list DM'd") @commands.Cog.listener() - async def on_command_error(self, ctx: commands.Context, exception): + async def on_message_without_command(self, message: discord.Message): + + """Filtering credit to redbot.cogs.customcom's listener""" + ########### + is_private = isinstance(message.channel, discord.abc.PrivateChannel) + + # user_allowed check, will be replaced with self.bot.user_allowed or + # something similar once it's added + user_allowed = True + + if len(message.content) < 2 or is_private or not user_allowed or message.author.bot: + return + + ctx = await self.bot.get_context(message) + + if ctx.prefix is None: + return + ########### + # Thank you Cog-Creators + cmd = ctx.invoked_with + cmd = cmd.lower() # Continues the proud case_insentivity tradition of ccrole guild = ctx.guild - message = ctx.message + # message = ctx.message # Unneeded since switch to `on_message_without_command` from `on_command_error` cmdlist = self.config.guild(guild).cmdlist # cmd = message.content[len(prefix) :].split()[0].lower()