From b10fe1e4ece320ad5a1f0cf98234579a791c09a9 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Fri, 9 Feb 2018 00:16:26 +0100 Subject: Monkey patching discord.ext.commands.view methods to allow case insensitivity for all prefixes and commands. --- bot/__init__.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bot/__init__.py b/bot/__init__.py index 9bad5790a..90b474c7c 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1 +1,33 @@ # coding=utf-8 +import discord.ext.commands.view + + +def case_insensitive_skip_string(self, string: str): + """Invokes the skip_string method from + discord.ext.commands.view used to find + the prefix in a message, but allows prefix + to ignore case sensitivity + """ + string = string.lower() + return _skip_string(self, string) + + +def case_insensitive_get_word(self): + """Invokes the get_word method from + discord.ext.commands.view used to find + the bot command part of a message, but + allows the command to ignore case sensitivity + """ + word = _get_word(self) + if isinstance(word, str): + return word.lower() + return word + + +# save the old methods +_skip_string = discord.ext.commands.view.skip_string +_get_word = discord.ext.commands.view.get_word + +# monkey patch them to be case insensitive +discord.ext.commands.view.skip_string = case_insensitive_skip_string +discord.ext.commands.view.get_word = case_insensitive_get_word -- cgit v1.2.3