diff --git a/functions/prefixes.py b/functions/prefixes.py index 4624d3b..e2a984e 100644 --- a/functions/prefixes.py +++ b/functions/prefixes.py @@ -1,28 +1,23 @@ from data.constants import prefixes from discord.ext import commands import os +import re fallback = os.urandom(32).hex() def get_prefix(bot: commands.Bot, message): - content = message.content.lower() mention = "<@!{}>".format(bot.user.id) + regex = r"^({})\s*" - # Used @Didier - if content.startswith(mention): - if content.startswith(mention + " "): - return mention + " " - return mention - - # Used a prefix - for prefix in prefixes: - # Find correct prefix - if content.startswith(prefix): - # Check if a space has to be added to invoke commands - if content.startswith(prefix + " "): - return prefix + " " - return prefix + # Check which prefix was used + for prefix in [*prefixes, mention]: + r = re.compile(regex.format(prefix), flags=re.I) + m = r.match(message.content) + if m: + # match.group() randomly ignores whitespace for some reason + # so use string slicing + return message.content[:m.end()] return fallback