Exemplo n.º 1
0
def regex_command(bot, context, message, args):
    """ Manage regex matches on bot.

    Valid arguments are: 'add', 'del', 'set', and 'show'.
    'add' usage: re add [pattern] <=> [response];
    'del' usage: re del [pattern];
    'set' usage: re set [pattern] <=> [attribute] [value];
    'show' usage: re show [pattern];
    If pattern is not specified, a list of triggers will be returned.
    """
    try:
        arg = args[1].lower()
    except IndexError:
        raise BotError("Error: No arguments provided.", Eat, Notice(context.nick))
    if arg == 'add':
        response = add_regex(' '.join(args[2:]), context.database)
    elif arg == 'del' or arg == 'rem':
        response = rem_regex(' '.join(args[2:]), context.database)
    elif arg == 'show':
        search = ' '.join(args[2:])
        if search != '':
            response = show_patterns(context.database, search)
        else:
            response = show_triggers(context.database)
    elif arg == 'set':
        response = set_attrib(' '.join(args[2:]), context.database)
    else:
        response = "Error: Unrecognised argument."

    return response, Eat, Notice(context.nick)
Exemplo n.º 2
0
def copy_command(bot, context, message, args):
    try:
        target = args[1]
        message = ' '.join(args[2:])
        if message:
            response = (message, (message, Target(target)))
        else:
            response = ("Error: Message must be supplied.",
                        Notice(context.nick))
    except IndexError:
        response = ("Error: Target must be supplied.", Notice(context.nick))
    return response
Exemplo n.º 3
0
def identify_command(bot, context, message, args):
    try:
        password = bot.admin_pass
    except AttributeError:
        raise BotError("Error: I've not been configured with a password.",
                       Notice(context.nick))

    input_pass = '******'.join(args[1:])
    if input_pass == password:
        recognise(context.session, context.nick)
        response = 'You are now recognised as a bot admin.'
    else:
        response = 'Error: Password incorrect.'
    return response, Notice(context.nick)
Exemplo n.º 4
0
def channel_command(bot, context, message, args):
    """ Override the channel to make a command act as if it were in another channel. """
    try:
        channel = args[1]
        if channel.lower() in get_channels(context.database):
            message = ' '.join(args[2:])
            response = bot.request('HANDLE_MESSAGE', context.nick, channel,
                                   context.host, message)
        else:
            response = "Error: Please provide a channel that I'm currently in.", Notice(
                context.nick)
    except IndexError:
        response = "Error: Please provide a channel.", Notice(context.nick)
    return response
Exemplo n.º 5
0
def top_desu_command(bot, context, message, args):
    """ Return the users with the highest desu score for the given argument.

    Valid arguments are: 'number', 'average', and 'undesus'.
    The default argument is 'number'.
    """
    keys = {
        'number': lambda x: x[1][1],
        'average': lambda x: x[1][1] / x[1][0],
        'undesus': lambda x: x[1][2]
    }
    response = ''

    try:
        stats = context.database.get({})
        arg = args[1].lower() if len(args) > 1 else 'number'
        key = keys[arg]

        response = "Users with the highest score desus ({}): ".format(arg)
        for stats in sorted(stats.items(), reverse=True, key=key)[:10]:
            response += "{}: {}; ".format(stats[0], key(stats))

    except KeyError:
        response = "Invalid argument, valid arguments are: " + \
            ", ".join(keys.keys()) + '.'

    return response, Notice(context.nick)
Exemplo n.º 6
0
def module_command(bot, context, message, args):
    """ Command to enable or disable modules in the bot.

    The 'enable' and 'disable' argument both require a module argument.
    The 'show' argument will show the currently disabled modules in the channel.
    The 'list' argument will return a list of modules in the bot.
    If 'list' is called with an argument, it'll return a list of plugins in that module.
    The 'get' argument will return the module a particular command is located in.
    """
    try:
        arg = args[1].lower()

        if arg == 'enable':
            module = ' '.join(args[2:])
            response = enable_module(context.database, context.channel, module)
        elif arg == 'disable':
            module = ' '.join(args[2:])
            response = disable_module(get_modules(bot), context.database,
                                      context.channel, module)
        elif arg == 'show':
            response = show_disabled_modules(context.database, context.channel)
        elif arg == 'list':
            module = ' '.join(args[2:])
            response = list_module(get_modules(bot), module)
        elif arg == 'get':
            module = ' '.join(args[2:])
            response = get_module(get_modules(bot), module)
        else:
            response = "Error: Invalid argument."
    except IndexError:
        response = "Error: Too few arguments supplied."

    return response, Notice(context.nick)
Exemplo n.º 7
0
def ignore_command(bot, context, message, args):
    """ Ignore a nick or host mask in the current channel. """
    try:
        response = add_ignore(context.database, context.channel, args[1])
    except IndexError:
        response = "Error: Please provide a mask or nick to ignore."
    return response, Notice(context.nick)
Exemplo n.º 8
0
def stopchatwith_command(bot, context, message, args):
    try:
        target = args[1]
    except IndexError:
        return "You must give me someone to chat with.", Notice(context.nick)

    try:
        target_channel = args[2]
    except IndexError:
        target_channel = context.channel

    if end_chat(context.session, target, target_channel):
        return "I'm no longer chatting with {} on {}.".format(
            target, target_channel), Notice(context.nick)
    else:
        return "I wasn't chatting with {} on {}.".format(
            target, target_channel), Notice(context.nick)
Exemplo n.º 9
0
def listchat_command(bot, context, message, args):
    chats = context.session.get({})
    if chats:
        response = split_response(
            "I'm chatting with {} on {}".format(nick, chan)
            for chan, nick in chats.keys())
    else:
        response = "I'm not chatting with anyone anywhere."
    return response, Notice(context.nick)
Exemplo n.º 10
0
def rand_command(bot, context, message, args):
    try:
        max = abs(int(args[1]))
        max = max if max > 0 else 1
    except ValueError:
        return "Argument has to be a valid integer.", Notice(context.nick)
    except IndexError:
        max = 6
    result = randint(1, max)
    return "Result of {max}: {result}".format(**locals())
Exemplo n.º 11
0
def tell_sink(bot, context, message):
    try:
        target = context.nick
        tells = context.database.get({})
        messages = tells.pop(target.lower())
        context.database.set(tells)
        response = (format_messages(messages), Notice(target))
    except KeyError:
        response = None
    return response
Exemplo n.º 12
0
def setblame_command(bot, context, message, args):
    global next_blame
    response = ''
    try:
        target = ' '.join(args[1:])
        next_blame = target
        response = "Next blame set to blame {}.".format(target)
    except IndexError:
        response = "Error: Please supply a user to blame."
    return response, Notice(context.nick)
Exemplo n.º 13
0
def chatwith_command(bot, context, message, args):
    try:
        target = args[1]
    except IndexError:
        return "You must give me someone to chat with.", Notice(context.nick)

    try:
        target_channel = args[2]
    except IndexError:
        target_channel = context.channel

    if begin_chat(context.session, target, target_channel):
        return (("I'm now chatting with {} on {}.".format(
            target,
            target_channel), Notice(context.nick)), ("Hi {}!".format(target),
                                                     Target(target_channel)))
    else:
        return "I'm already chatting with {} on {}.".format(
            target, target_channel), Notice(context.nick)
Exemplo n.º 14
0
def say_command(bot, context, message, args):
    """ Send a message to a given target.

    Usage: say <TARGET> [MESSAGE]
    """
    try:
        target = args[1]
        message = ' '.join(args[2:])
        return say(target, message)
    except IndexError:
        return ("Error: Too few arguments supplied.", Notice(context.nick))
Exemplo n.º 15
0
def forwardpms_command(bot, context, message, args):
    forwarding = context.session.get(set())
    nick = context.nick.lower()
    if nick in forwarding:
        forwarding.remove(nick)
        response = "I will no longer forward PMs to you."
    else:
        forwarding.add(nick)
        response = "I will forward PMs to you."
    context.session.set(forwarding)
    return response, Notice(nick)
Exemplo n.º 16
0
def hash_command(bot, context, message, args):
    """ Hash a message.

    Usage: hash <algorithm> [message];
    Pass 'list' or 'show' for a list of algorithms.
    """
    try:
        if args[1] in ('list', 'show'):
            response = split_response(
                algorithms_available,
                "I support the following hashing algorithms: {}.")
        else:
            hash = new(args[1], bytes(' '.join(args[2:]), encoding))
            response = hash.hexdigest()
    except ValueError:
        response = "Error: Unsupported hashing algorithm.", Notice(
            context.nick)
    except IndexError:
        response = "Error: Please provide a hashing algorithm to use.", Notice(
            context.nick)
    return response
Exemplo n.º 17
0
def commands_command(bot, context, message, args):
    userlevel = bot.request('USERLEVEL', context.channel, context.nick)
    groups = defaultdict(lambda: [])

    for command, func in filter_plugins(
            bot.request('GET_PLUGINS', context.channel), userlevel):
        groups[func].append(command)

    commands = map(format_group, sorted(groups.values()))
    response = split_response(commands, "Bot Commands: {};")

    return response, Notice(context.nick)
Exemplo n.º 18
0
def last_command(bot, context, message, args):
    global lines
    response = None

    try:
        n = int(args[1])
        l = lines[context.channel][-n:]
        response = split_response(format_lines(l), separator=' ')
    except (ValueError, IndexError):
        response = ("Error: Must supply integer argument.",
                    Notice(context.nick))

    return response
Exemplo n.º 19
0
def ctcp_match(bot, context, message, match):
    ctcp_response = {
        'VERSION': 'MotoBot Version ' + __VERSION__,
        'FINGER': 'Oh you dirty man!',
        'TIME': strftime('%a %b %d %H:%M:%S UTC', gmtime()),
        'PING': message.strip('\x01')
    }
    try:
        ctcp_req = match.group(1).split(' ', 1)[0]
        reply = ctcp_response[ctcp_req]
        response = ('\x01{}\x01'.format(reply), Notice(context.nick), Eat)
    except KeyError:
        response = None
    return response
Exemplo n.º 20
0
def adminmask_command(bot, context, message, args):
    try:
        arg = args[1].lower()
        if arg == 'add':
            response = add_mask(context.database, args[2])
        elif arg in ('del', 'rem'):
            response = del_mask(context.database, args[2])
        elif arg in ('show', 'list'):
            response = show_masks(context.database)
        else:
            response = 'Error: Invalid argument;'
    except IndexError:
        response = "Not enough arguments provided."
    return response, Notice(context.nick)
Exemplo n.º 21
0
def help_command(bot, context, message, args):
    """ Print help messages for the user.

    Takes a single argument for a command name.
    No arguments gives a generic help message.
    """

    try:
        response = get_command_help(bot, args[1])
    except IndexError:
        default_help = "For a list of commands use '{0}commands'. " \
                       "For help on a specific command use '{0}help command'.".format(
                            bot.command_prefix)
        response = default_help

    return response, Notice(context.nick)
Exemplo n.º 22
0
def user_module_command(bot, context, message, args):
    try:
        arg = args[1].lower()

        if arg == ('enable', 'disable', 'show'):
            response = "Error: You do not have the privileges to use this argument."
        elif arg == 'list':
            module = ' '.join(args[2:])
            response = list_module(get_modules(bot), module)
        elif arg == 'get':
            module = ' '.join(args[2:])
            response = get_module(get_modules(bot), module)
        else:
            response = "Error: Invalid argument."
    except IndexError:
        response = "Error: Too few arguments supplied."

    return response, Notice(context.nick)
Exemplo n.º 23
0
def globalignore_command(bot, context, message, args):
    """ Manage global ignores.

    Valid arguments are: 'add', 'del', 'all, and 'show'.
    'add' and 'del' require a nick argument.
    'show' will show the currently ignored nicks in the channel.
    """
    response = ''
    try:
        arg = args[1].lower()
        if arg == 'add':
            response = add_ignore(context.database, context.channel, args[2])
        elif arg == 'del' or arg == 'rem':
            response = del_ignore(context.database, context.channel, args[2])
        elif arg == 'show':
            response = show_ignores(context.database, context.channel)
        else:
            response = 'Error: Invalid argument;'
    except IndexError:
        response = "Not enough arguments provided."
    return response, Notice(context.nick)
Exemplo n.º 24
0
def tell_command(bot, context, message, args):
    """ Send a message to a user the next time they're active.

    Usage: tell <nick> <message>
    """
    try:
        nick = args[1]
        message = ' '.join(args[2:])
        if message:
            tells = context.database.get({})
            messages = tells.get(nick.lower(), [])
            messages.append((context.nick, message))
            tells[nick.lower()] = messages
            context.database.set(tells)
            response = "I will tell {} \"{}\" next time I see them.".format(
                nick, message)
        else:
            response = "Error: Please provide a message to tell."
    except IndexError:
        response = "Error: Please provide a nick to tell to."
    return response, Notice(context.nick)
Exemplo n.º 25
0
def command_command(bot, context, message, args):
    """ Command to manage the basic functions of the bot.

    Valid arguments are: 'join', 'part', 'quit', 'show', 'reconnect' and 'reload'.
    The 'join' and 'part' argument both require a channel argument.
    The 'join' command has an optional channel password argument.
    The 'quit', 'part', and 'reconnect' argument have an optional quit/part message.
    The 'show' argument will return a list of currently joined channels.
    The 'reload' command will reload the plugins in the loaded packages.
    """
    try:
        arg = args[1].lower()

        if arg == 'join':
            channel = ' '.join(args[2:])
            response = join_channel(context.database, channel)
        elif arg == 'part':
            channel = args[2]
            message = ' '.join(args[3:])
            response = part_channel(context.database, channel, message)
        elif arg == 'quit':
            bot.running = False
            message = ' '.join(args[2:])
            response = quit(message)
        elif arg == 'reconnect':
            message = ' '.join(args[2:])
            response = quit(message)
        elif arg == 'show':
            response = show_channels(context.database)
        elif arg == 'reload':
            error = bot.reload_plugins()
            response = "Plugins have been reloaded." + \
                (" There were some errors." if error else "")
        else:
            response = "Error: Invalid argument."
    except IndexError:
        response = "Error: Too few arguments supplied."

    return response, Notice(context.nick)
Exemplo n.º 26
0
def chat_command(bot, context, message, args):
    if begin_chat(context.session, context.nick, context.channel):
        return "Hi {}!".format(context.nick)
    else:
        return "I'm already chatting with you.", Notice(context.nick)
Exemplo n.º 27
0
def stopchat_command(bot, context, message, args):
    if end_chat(context.session, context.nick, context.channel):
        return "Nice chatting with you {}!".format(context.nick)
    else:
        return "I wasn't chatting with you.", Notice(context.nick)
Exemplo n.º 28
0
def ignorelist_command(bot, context, message, args):
    """ List the ignored host masks in the current channel. """
    return show_ignores(context.database,
                        context.channel), Notice(context.nick)