Ejemplo n.º 1
0
async def on_message(message: discord.Message):
    if message.author.bot or message.author.id in config.get_global(
            "user_blacklist"):
        return

    if (isinstance(message.channel, discord.DMChannel)
            or isinstance(message.channel, discord.GroupChannel) or
            message.channel.permissions_for(message.guild.me).send_messages):
        prefix = config.get_prefix(message.guild)
        if message.content.startswith(prefix):
            if not initialised:
                await message.channel.send(
                    "I've only just woken up, give me a second please!")
                return
            command = message.content[len(prefix):].split(
                " ")[0].lower()  # just command text
            args = message.content[len(prefix) + len(command) + 1:]
            if Hook.exists("public!" +
                           command) and util.check_command_permissions(
                               message, "public"):
                await Hook.get("public!" + command)(message, args)
            elif Hook.exists("admin!" +
                             command) and util.check_command_permissions(
                                 message, "admin"):
                await Hook.get("admin!" + command)(message, args)
            elif Hook.exists("owner!" +
                             command) and util.check_command_permissions(
                                 message, "owner"):
                await Hook.get("owner!" + command)(message, args)
            else:
                await message.channel.send(
                    "I don't know that command, sorry! Use the `help` command for a list of commands."
                )
        else:
            if not initialised:
                return
            await Hook.get("on_message")(message)
            if discord.utils.find(lambda m: m.id == client.user.id,
                                  message.mentions) is not None:
                await Hook.get("on_mention")(message)
            if isinstance(message.channel, discord.abc.PrivateChannel):
                await Hook.get("on_message_private")(message)