2020-11-03 16:06:08 +01:00
|
|
|
from data.constants import prefixes
|
|
|
|
from discord.ext import commands
|
|
|
|
import os
|
2020-11-04 10:40:02 +01:00
|
|
|
import re
|
2020-11-03 16:06:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
fallback = os.urandom(32).hex()
|
|
|
|
|
|
|
|
|
|
|
|
def get_prefix(bot: commands.Bot, message):
|
|
|
|
mention = "<@!{}>".format(bot.user.id)
|
2020-11-04 10:40:02 +01:00
|
|
|
regex = r"^({})\s*"
|
2020-11-03 16:06:08 +01:00
|
|
|
|
2020-11-04 10:40:02 +01:00
|
|
|
# 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()]
|
2020-11-03 16:06:08 +01:00
|
|
|
|
|
|
|
return fallback
|