Example #1
0
async def help_command(args, message):
    if not args:
        command_list = [command.handle for command in commands.values()]
        return 'These are the available commands:\n{}'.format(
            '\n'.join(command_list))

    command = commands[args[0].lower()]
    if not command:
        return await get_command_not_found_message(
            command, persistence.get_prefix(message.guild))
    else:
        return command.help_message
Example #2
0
async def get_prefix_command(args, message):
    if not message.guild:
        return "I can only retrieve the prefix for a server"

    prefix = persistence.get_prefix(message.guild)

    response = "I am currently responding to the following prefix: {}".format(
        prefix)

    if message.content.startswith(prefix):
        response += "\nBut you already knew that, it seems..."
    return response
Example #3
0
async def set_prefix_command(args, message):
    if not message.guild:
        return "I can only set the prefix for a server"

    if not args or args[0].isalnum() or len(args[0]) != 1:
        return "Please specify a single non-alphanumeric character such as ! or $"

    success = persistence.set_prefix(message.guild, args[0])

    if success:
        return 'The command prefix is now {}'.format(args[0])
    else:
        return 'Something went wrong while setting the command prefix.' + \
               'It remains "{}". Try again later.'.format(persistence.get_prefix(message.guild))
Example #4
0
async def on_message(message):
    if message.author == client.user:
        return

    # The command prefix for the guild that the message was sent in
    prefix = persistence.get_prefix(message.guild)

    # The string indicating that the bot is being mentioned. e.g. '@Omni' in the
    # discord client.
    mention = "<@!{}>".format(client.user.id)

    content = message.content

    # The string representing the command, and the arguments following it are
    # extracted differently depending on how the bot is addressed
    if content.startswith(mention):
        # If the bot is addressed by starting the message with mentioning it,
        # the command string is interpreted to be the first word in the message
        # after the mention
        after_mention = content[len(mention):].lstrip()
        command_string = after_mention.split()[0]
        arguments = after_mention.split()[1:]
    elif content.startswith(prefix):
        # If the bot is addressed by the guild's prefix, the command string is
        # interpreted to be the first word in the message, minus the prefix.
        command_string = content.split()[0][len(prefix):]
        arguments = content.split()[1:]
    else:
        return

    command = commands.get(command_string.lower(), None)

    if command:
        response = await command.function(arguments, message)
    else:
        response = get_command_not_found_message(command_string, prefix)

    if response:
        await message.channel.send(response)
Example #5
0
 def get_prefix(self, guild):
     return persistence.get_prefix(guild)