aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-02-09 00:16:26 +0100
committerGravatar Leon Sandøy <[email protected]>2018-02-09 00:16:26 +0100
commitb10fe1e4ece320ad5a1f0cf98234579a791c09a9 (patch)
tree9f3448bca82d98d7263dfccb21586601602577e8
parentTurn down the reqs for deployment, for now (diff)
Monkey patching discord.ext.commands.view methods to allow case insensitivity for all prefixes and commands.
-rw-r--r--bot/__init__.py32
1 files changed, 32 insertions, 0 deletions
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