Example #1
0
def tells(context):
    '''.tells <nick>'''
    if not utils.isadmin(context.line['prefix'], bot):
        return
    nick = context.args

    db = get_db_connection()

    try:
        tells = get_tells(db, nick)
    except db.OperationalError:
        db_init(db)
        tells = get_tells(db, nick)

    if len(tells) == 0:
        return

    db.execute('delete from tell where user_to=lower(?)', (nick,))
    db.commit()
    get_users(db)

    reply = []
    for user_from, message, time, chan in tells:
        d_time = datetime.fromtimestamp(time)
        reply.append(u'{0} <{1}> {2}'.format(d_time.strftime('%a %d %b %H:%M'), user_from, message))

    p = paste(u'\n'.join(reply), u'Notes for {}'.format(nick), unlisted=1)
    if p['success'] == False:
        bot.reply(u'Could not paste notes: {}'.format(p['error']), context.line, False, True, context.line['user'])
        return
    else:
        bot.reply(p['url'], context.line, False, True, context.line['user'])
        return
Example #2
0
def tells(context):
    """.tells <nick>"""
    if not utils.isadmin(context.line["prefix"], bot):
        return
    nick = context.args

    db = get_db_connection()
    db_init(db)

    tells = get_tells(db, nick)

    if len(tells) == 0:
        return

    db.execute("delete from tell where user_to=lower(?)", (nick,))
    db.commit()

    reply = []
    for user_from, message, time, chan in tells:
        d_time = datetime.fromtimestamp(time)
        reply.append("{0} <{1}> {2}".format(d_time.strftime("%H:%M"), user_from, message))

    p = paste("\n".join(reply), "Notes for {}".format(nick), unlisted=1)
    if p["success"] == False:
        bot.reply("Could not paste notes: {}".format(p["error"]), context.line, False, True, context.line["user"])
        return
    else:
        bot.reply(p["url"], context.line, False, True, context.line["user"])
        return
Example #3
0
def listignores(context):
    '''.listignores'''

    word_list = bot.config.setdefault('IGNORE', [])
    if len(word_list) == 0:
        bot.reply('Nothing to list.', context.line, False, True, context.line['user'], nofilter=True)
    next, word_list = word_list[:4], word_list[4:]
    while next:
        bot.reply('\x02%s\x02' % '\x02, \x02'.join(next), context.line, False, True, context.line['user'], nofilter=True)
        next, word_list = word_list[:4], word_list[4:]
Example #4
0
def listbadwords(context):
    '''.listbadwords'''
    global badwords

    word_list = list(badwords)
    if len(word_list) == 0:
        bot.reply('Nothing to list.', context.line, False, True, context.line['user'], nofilter=True)
    next, word_list = word_list[:4], word_list[4:]
    while next:
        bot.reply('\x02%s\x02' % '\x02, \x02'.join(next), context.line, False, True, context.line['user'], nofilter=True)
        next, word_list = word_list[:4], word_list[4:]
Example #5
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.'
Example #6
0
def listignores(context):
    """.listignores"""
    if not utils.isadmin(context.line["prefix"], bot):
        return
    word_list = bot.config.setdefault("IGNORE", [])
    if len(word_list) == 0:
        bot.reply("Nothing to list.", context.line, False, True, context.line["user"], nofilter=True)
    next, word_list = word_list[:4], word_list[4:]
    while next:
        bot.reply(
            "\x02%s\x02" % "\x02, \x02".join(next), context.line, False, True, context.line["user"], nofilter=True
        )
        next, word_list = word_list[:4], word_list[4:]
Example #7
0
def config(context):
    '''.config (list|view|set|add|remove|revert) <key> [value]'''
    if not utils.isadmin(context.line['prefix'], bot):
        return
    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') and not key.upper().endswith('_KEY'):
            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.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.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()
        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()
        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.save_config()
        return 'Removed.'
Example #8
0
def addbadword(context):
    '''.addbadword <word>'''
    global badwords
    if not utils.isadmin(context.line['prefix'], bot):
        return
    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)
    return 'Added.'
Example #9
0
def usage(context):
    '''.usage <plugin>'''
    plugin = context.args
    if plugin:
        for p in bot.config['PLUGINS']:
            if plugin == p['hook']:
                bot.reply(p['funcs'][0].__doc__, context=context, recipient=context.line['user'], notice=True)
    else:
        p = [(p['hook'], p['funcs']) for p in bot.config['PLUGINS']]
        p.sort(key=lambda t: t[1])
        result = []
        # group by function
        for k, v in groupby(p, key=lambda t: t[1]):
            grouped = [v[0] for v in v]
            grouped[0] = '\x02' + grouped[0] + '\x02'
            if len(grouped) > 1:
                # shortcuts/secondary
                for i, hook in enumerate(grouped[1:]):
                    grouped[i + 1] = '[' + grouped[i + 1] + ']'
            result.append(' '.join(grouped))
        result.sort()
        p = ', '.join(result)
        bot.reply('Plugins currently loaded: ' + p, context=context, recipient=context.line['user'], notice=True)
Example #10
0
def usage(context):
    """.usage <plugin>"""
    plugin = context.args
    if plugin:
        for p in bot.config["PLUGINS"]:
            if plugin == p["hook"]:
                bot.reply(p["funcs"][0].__doc__, context=context, recipient=context.line["user"])
    else:
        p = [(p["hook"], p["funcs"]) for p in bot.config["PLUGINS"]]
        p.sort(key=lambda t: t[1])
        result = []
        # group by function
        for k, v in groupby(p, key=lambda t: t[1]):
            grouped = [v[0] for v in v]
            grouped[0] = "\x02" + grouped[0] + "\x02"
            if len(grouped) > 1:
                # shortcuts/secondary
                for i, hook in enumerate(grouped[1:]):
                    grouped[i + 1] = "[" + grouped[i + 1] + "]"
            result.append(" ".join(grouped))
        result.sort()
        p = ", ".join(result)
        bot.reply("Plugins currently loaded: " + p, context=context, recipient=context.line["user"])