Exemple #1
0
def ignore(context):
    '''.ignore nick!user@host'''
    bot.config.setdefault('IGNORE', [])

    if context.args:
        to_ignore = glob(context.args)
        supersets = list(ifilter(lambda ignored: to_ignore.issub(glob(ignored)), bot.config['IGNORE']))
        if len(supersets) > 0:
            return 'Not ignoring \x02%s\x02 because it is already matched by \x02%s\x02' % (context.args, supersets[0])

        filter = lambda ignored: to_ignore.issuper(glob(ignored))
        removed = list(ifilter(filter, bot.config['IGNORE']))

        bot.config['IGNORE'] = list(ifilterfalse(filter, bot.config['IGNORE']))
        bot.config['IGNORE'].append(context.args)

        save_ignores()

        bot.log(context, ('IGNORE'), '+{0}{1}'.format(context.args, (' -' + ' -'.join(removed)) if removed else ''))

        if removed:
            return 'Ignored and removed \x02%d\x02 redundant ignores: \x02%s\x02' % (len(removed), '\x02, \x02'.join(removed))
        else:
            return 'Ignored.'
    else:
        return eval.__doc__
Exemple #2
0
def inject(context):
    '''.inject <input_data>'''
    if context.args:
        bot.log(context, ('INJECT'), context.args)
        bot.inject_input(context.args)
    else:
        return inject.__doc__
Exemple #3
0
def raw(context):
    '''.raw <command>'''
    if context.args:
        command = context.args.split(' ', 1)[0]
        args = list(context.args.split(' ', 1)[-1])
        bot.log(context, ('RAW'), context.args)
        bot.irc.send_command(command, args)
    else:
        return raw.__doc__
Exemple #4
0
def delbadword(context):
    '''.delbadword <word>'''
    global badwords

    old = len(badwords)
    badwords = list(ifilter(lambda word: word != context.args.lower(), badwords))
    save_badwords()
    bot.log(context, ('BADWORD', 'DEL'), context.args)
    return 'Removed \x02%d\x02 badwords.' % (old - len(badwords))
Exemple #5
0
def invite(context):
    for channel in bot.config['CHANNELS']:
        if channel.lower().split(' ')[0] == context.line['args'][-1].lower():
            bot.log(context, ('INVITE'), context.line['args'][-1])
            bot.irc.send_command('JOIN', channel)
            return
    if utils.isadmin(context.line['prefix'], bot):
        bot.log(context, ('INVITE', 'OVERRIDE'), context.line['args'][-1])
        bot.irc.send_command('JOIN', context.line['args'][-1])
Exemple #6
0
def eval(context):
    '''.eval <command>'''

    if context.args:
        try:
            bot.log(context, ('EVAL'), context.args)
            return str(__builtin__.eval(context.args))
        except:
            return repr(sys.exc_info()[1])
    else:
        return eval.__doc__
Exemple #7
0
def config(context):
    '''.config (list|view|set|add|remove|revert) <key> [value]'''

    cmd = str(context.args).split(' ', 1)[0].lower()
    if not (cmd in ['list', 'set', 'add', 'remove', 'view', 'revert']):
        return
    if cmd == 'list':
        bot.reply(repr(bot.config.keys()), context.line, False, True, context.line['user'], nofilter=True)
        return
    cmd, key = str(context.args).split(' ', 1)
    if len(key.split(' ', 1)) > 1:
        key, arg = key.split(' ', 1)
    if key.upper() in blacklist:
        return
    if cmd == 'view':
        if key in bot.config and not key.upper().endswith(('_PASSWORD', '_KEY', 'TELL_DB')):
            bot.reply(repr(bot.config[key]), context.line, False, True, context.line['user'], nofilter=True)
        return
    elif cmd == 'revert':
        if key in bot.h_config:
            bot.config[key] = copy.deepcopy(bot.h_config[key])
            bot.save_config()
            bot.log(context, ('CONFIG', 'REVERT'), key)
            bot.reply(repr(bot.config[key]), context.line, False, True, context.line['user'], nofilter=True)
        elif key in bot.config:
            del bot.config[key]
            bot.save_config()
            bot.log(context, ('CONFIG', 'REVERT'), key)
            bot.reply('Key deleted.', context.line, False, True, context.line['user'], nofilter=True)
        else:
            bot.reply('Nothing to do.', context.line, False, True, context.line['user'], nofilter=True)
        return
    if cmd == 'set' and (not key in bot.config or isinstance(bot.config[key], str)):
        bot.config[key] = arg
        bot.save_config()
        c_value = ('*****') if key.upper().endswith(('_PASSWORD', '_KEY', 'TELL_DB')) else arg
        bot.log(context, ('CONFIG', 'SET'), '{0}={1}'.format(key, c_value))
        return 'Set.'
    if key in bot.config and not isinstance(bot.config[key], list):
        return
    if not key in bot.config:
        bot.config[key] = []
    if cmd == 'add' and not arg in bot.config[key]:
        bot.config[key].append(arg)
        bot.save_config()
        bot.log(context, ('CONFIG', 'ADD'), '{1} to {0}'.format(key, arg))
        return 'Added.'
    elif cmd == 'remove' and (not key in bot.h_config or not (arg in bot.h_config[key])):
        bot.config[key].remove(arg)
        if len(bot.config[key]) == 0 and not key in bot.h_config:
            del bot.config[key]
            bot.log(context, ('CONFIG', 'DEL'), '{1} from {0}'.format(key, arg))
        bot.save_config()
        return 'Removed.'
Exemple #8
0
def kick(context):
    if context.line['args'][1] != bot.irc.nick:
        return

    kicked_from = context.line['args'][0]
    bot.log(context, ('KICK'), '{0} ({1})'.format(kicked_from, context.line['args'][-1]))

    if context.line['user'].lower() in [x.lower() for x in bot.config['REJOIN_KICKERS']]:
        # for channel keys
        for channel in bot.config['CHANNELS']:
            if channel.lower().split(' ')[0] == kicked_from.lower():
                delayed_join(channel)
                return
        delayed_join(kicked_from)
Exemple #9
0
def addbadword(context):
    '''.addbadword <word>'''
    global badwords

    if any(imap(lambda word: word in context.args.lower(), badwords)):
        return 'This would be redundant, not adding.'
    removed = list(ifilter(lambda word: context.args.lower() in word, badwords))
    badwords = list(ifilter(lambda word: not (context.args.lower() in word), badwords))
    badwords.append(context.args.lower())
    save_badwords()
    if len(removed) > 0:
        bot.reply('Removed \x02%d\x02 redundant badwords: \x02%s\x02' % (len(removed), '\x02, \x02'.join(removed)),
            context.line, False, True, context.line['user'], nofilter=True)
    bot.log(context, ('BADWORD', 'ADD'), context.args)
    return 'Added.'
Exemple #10
0
def unignore(context):
    '''.unignore nick!user@host'''
    bot.config.setdefault('IGNORE', [])

    if context.args:
        to_unignore = glob(context.args)

        filter = lambda ignored: to_unignore.issuper(glob(ignored))
        subsets = list(ifilter(filter, bot.config['IGNORE']))
        if len(subsets) == 0:
            return 'Nothing to unignore.'

        bot.config['IGNORE'] = list(ifilterfalse(filter, bot.config['IGNORE']))

        bot.log(context, ('IGNORE'), '-{0}'.format(' -'.join(subsets)))

        save_ignores()

        return 'Removed \x02%d\x02 ignores: \x02%s\x02' % (len(subsets), '\x02, \x02'.join(subsets))
    else:
        return eval.__doc__