Exemplo n.º 1
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
Exemplo n.º 2
0
def ignore(context):
    """.ignore nick!user@host"""
    bot.config.setdefault("IGNORE", [])
    if not utils.isadmin(context.line["prefix"], bot):
        return
    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()

        if len(removed) > 0:
            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__
Exemplo n.º 3
0
def ignore(context):
    '''.ignore nick!user@host'''
    bot.config.setdefault('IGNORE', [])
    if not utils.isadmin(context.line['prefix'], bot):
        return
    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()

        if len(removed) > 0:
            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__
Exemplo n.º 4
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
Exemplo n.º 5
0
def invite(context):
    if utils.isadmin(context.line['prefix'], bot):
        bot.irc.send_command('JOIN', context.line['args'][-1])
    else:
        for channel in bot.config['CHANNELS']:
            if channel.lower().split(' ')[0] == context.line['args'][-1].lower():
                bot.irc.send_command('JOIN', channel)
                return
Exemplo n.º 6
0
def invite(context):
    if utils.isadmin(context.line["prefix"], bot):
        bot.irc.send_command("JOIN", context.line["args"][-1])
    else:
        for channel in bot.config["CHANNELS"]:
            if channel.lower().split(" ")[0] == context.line["args"][-1].lower():
                bot.irc.send_command("JOIN", channel)
                return
Exemplo n.º 7
0
def inject(context):
    '''.inject <input_data>'''
    if not utils.isadmin(context.line['prefix'], bot):
        return
    if context.args:
        bot.inject_input(context.args)
    else:
        return inject.__doc__
Exemplo n.º 8
0
def delbadword(context):
    '''.delbadword <word>'''
    global badwords
    if not utils.isadmin(context.line['prefix'], bot):
        return
    old = len(badwords)
    badwords = list(ifilter(lambda word: word != context.args.lower(), badwords))
    save_badwords()
    return 'Removed \x02%d\x02 badwords.' % (old - len(badwords))
Exemplo n.º 9
0
def raw(context):
    '''.raw <command>'''
    if not utils.isadmin(context.line['prefix'], bot):
        return
    if context.args:
        command = context.args.split(' ', 1)[0]
        args = list(context.args.split(' ', 1)[-1])
        bot.irc.send_command(command, args)
    else:
        return raw.__doc__
Exemplo n.º 10
0
def raw(context):
    """.raw <command>"""
    if not utils.isadmin(context.line["prefix"], bot):
        return
    if context.args:
        command = context.args.split(" ", 1)[0]
        args = list(context.args.split(" ", 1)[-1])
        bot.irc.send_command(command, args)
    else:
        return raw.__doc__
Exemplo n.º 11
0
def eval(context):
    '''.eval <command>'''
    if not utils.isadmin(context.line['prefix'], bot):
        return
    if context.args:
        try:
            return str(__builtin__.eval(context.args))
        except:
            return repr(sys.exc_info()[1])
    else:
        return eval.__doc__
Exemplo n.º 12
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:]
Exemplo n.º 13
0
def listbadwords(context):
    '''.listbadwords'''
    global badwords
    if not utils.isadmin(context.line['prefix'], bot):
        return
    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:]
Exemplo n.º 14
0
def raw(context):
    '''.raw <command>'''
    #if not context.line['prefix'] in bot.config.get('ADMINS', []):
    #    return
    if not utils.isadmin(context.line['prefix']):
        return
    if context.args:
        command = context.args.split(' ', 1)[0]
        args = list(context.args.split(' ', 1)[-1])
        bot.irc.send_command(command, args)
    else:
        return raw.__doc__
Exemplo n.º 15
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:]
Exemplo n.º 16
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.'
Exemplo n.º 17
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.'
Exemplo n.º 18
0
def uptime(context):
    """Usage: .uptime"""
    if not utils.isadmin(context.line["prefix"], bot):
        return
    line = ""
    try:
        with open("/proc/uptime") as h:
            uptime_secs = h.read()
    except IOError:
        # OS without /proc/uptime
        pass
    else:
        uptime = timedelta(seconds=int(uptime_secs.split(".")[0]))
        line = "Server uptime: {} ".format(uptime) + line

    uptime = timedelta(seconds=int(time() - bot.config["START_TIME"]))

    return line + "| Bot Uptime: {}".format(uptime)
Exemplo n.º 19
0
def unignore(context):
    '''.unignore nick!user@host'''
    bot.config.setdefault('IGNORE', [])
    if not utils.isadmin(context.line['prefix'], bot):
        return
    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']))

        save_ignores()

        return 'Removed \x02%d\x02 ignores: \x02%s\x02' % (len(subsets), '\x02, \x02'.join(subsets))
    else:
        return eval.__doc__
Exemplo n.º 20
0
def unignore(context):
    """.unignore nick!user@host"""
    bot.config.setdefault("IGNORE", [])
    if not utils.isadmin(context.line["prefix"], bot):
        return
    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"]))

        save_ignores()

        return "Removed \x02%d\x02 ignores: \x02%s\x02" % (len(subsets), "\x02, \x02".join(subsets))
    else:
        return eval.__doc__
Exemplo n.º 21
0
def uptime(context):
    '''Usage: .uptime'''
    if not utils.isadmin(context.line['prefix'], bot):
        return
    line = ''
    try:
        with open('/proc/uptime') as h:
            uptime_secs = h.read()
    except IOError:
        # OS without /proc/uptime
        pass
    else:
        uptime = timedelta(seconds=int(uptime_secs.split('.')[0]))
        line = 'Server uptime: {}'.format(uptime)

    uptime = timedelta(seconds=int(time() - bot.config['START_TIME']))

    if line:
        return line + ' | Bot uptime: {}'.format(uptime)
    else:
        return 'Bot uptime: {}'.format(uptime)
Exemplo n.º 22
0
 def enqueue_plugin(self, plugin, hook, context, regex=False):
     prefix = plugin['context']['prefix']
     if glob.is_valid(prefix) and isignored(prefix, self.bot) and not isadmin(prefix, self.bot):
         return
     super(PluginHandler, self).enqueue_plugin(plugin, hook, context, regex)