diff --git a/cogs/customcom.py b/cogs/customcom.py index 900b549ea..8fa918ae7 100644 --- a/cogs/customcom.py +++ b/cogs/customcom.py @@ -2,6 +2,7 @@ import discord from discord.ext import commands from .utils.dataIO import fileIO from .utils import checks +from __main__ import user_allowed import os class CustomCommands: @@ -86,12 +87,25 @@ class CustomCommands: async def checkCC(self, message): if message.author.id == self.bot.user.id or len(message.content) < 2 or message.channel.is_private: return + + if not user_allowed(message): + return + msg = message.content server = message.server - if msg[0] in self.bot.command_prefix and server.id in self.c_commands.keys(): + prefix = self.get_prefix(msg) + + if prefix and server.id in self.c_commands.keys(): cmdlist = self.c_commands[server.id] - if msg[1:] in cmdlist: - await self.bot.send_message(message.channel, cmdlist[msg[1:]]) + cmd = msg[len(prefix):] + if cmd in cmdlist.keys(): + await self.bot.send_message(message.channel, cmdlist[cmd]) + + def get_prefix(self, msg): + for p in self.bot.command_prefix: + if msg.startswith(p): + return p + return False def check_folders(): if not os.path.exists("data/customcom"): diff --git a/red.py b/red.py index 72ae46126..5b22ce770 100644 --- a/red.py +++ b/red.py @@ -44,36 +44,8 @@ async def on_command(command, ctx): @bot.event async def on_message(message): - mod = bot.get_cog('Mod') - author = message.author - - if mod is not None: - if checks.settings["OWNER"] == author.id: - await bot.process_commands(message) - return - if not message.channel.is_private: - if discord.utils.get(author.roles, name=checks.settings["ADMIN_ROLE"]) is not None: - await bot.process_commands(message) - return - if discord.utils.get(author.roles, name=checks.settings["MOD_ROLE"]) is not None: - await bot.process_commands(message) - return - - if author.id in mod.blacklist_list: - return - - if mod.whitelist_list: - if author.id not in mod.whitelist_list: - return - - if not message.channel.is_private: - if message.server.id in mod.ignore_list["SERVERS"]: - return - - if message.channel.id in mod.ignore_list["CHANNELS"]: - return - - await bot.process_commands(message) + if user_allowed(message): + await bot.process_commands(message) @bot.command() @checks.is_owner() @@ -212,6 +184,38 @@ async def _uptime(): up = str(datetime.timedelta(seconds=up)) await bot.say("`Uptime: {}`".format(up)) +def user_allowed(message): + + author = message.author + + mod = bot.get_cog('Mod') + + if mod is not None: + if checks.settings["OWNER"] == author.id: + return True + if not message.channel.is_private: + if discord.utils.get(author.roles, name=checks.settings["ADMIN_ROLE"]) is not None: + return True + if discord.utils.get(author.roles, name=checks.settings["MOD_ROLE"]) is not None: + return True + + if author.id in mod.blacklist_list: + return False + + if mod.whitelist_list: + if author.id not in mod.whitelist_list: + return False + + if not message.channel.is_private: + if message.server.id in mod.ignore_list["SERVERS"]: + return False + + if message.channel.id in mod.ignore_list["CHANNELS"]: + return False + return True + else: + return True + def wait_for_answer(author): global lock print(author.name + " requested to be set as owner. If this is you, type 'yes'. Otherwise press enter.")