Beispiel #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
Beispiel #2
0
def grab(context):
    '''.grab <start_text> [~~ <end_text>]'''
    if not context.line['sender'].startswith('#'):
        return
    if not context.line['sender'].lower() in scrollback:
        return 'Nothing found.'
    r = []
    if '~~' in context.args:
        str1, str2 = map(unicode.strip, context.args.lower().split('~~', 1))
        matched = False
        s = []
        for line in scrollback[context.line['sender'].lower()]:
            if str1 in line[1].lower():
                matched = True
            if matched:
                s.append(line)
                if str2 in line[1].lower():
                    r.extend(s)
                    s = []
                    break  # make matching non-greedy, unsure if this is good thing
    else:
        str1 = context.args.lower().strip()
        for line in scrollback[context.line['sender'].lower()]:
            if str1 in line[1].lower():
                r[:] = [line]
                break
    if r == []:
        return 'Nothing found.'
    match = map(format_line, r)
    p = paste('\n'.join(match), title='Grabbed from {}'.format(context.line['sender']))
    if p['success']:
        return p['url']
    else:
        return 'Failed to paste'
Beispiel #3
0
def tell_user(context):
    nick = context.line['user']

    if nick.lower() not in bot.data['TELL_USERS']:
        return

    session = Session()
    messages = session.query(tells).filter_by(user_to=nick.lower()).all()

    if not messages:
        Session.remove()
        return

    msgs = [u'{0} <{1}> {2}'.format(make_date_string(message.time),
             message.user_from, message.message) for message in messages]

    if len(msgs) > 2:
        p = paste('\n'.join(msgs), u'Notes for {0}'.format(nick))

        if p['success']:
            map(session.delete, messages)
            session.commit()
            Session.remove()
            get_users()
            return u'{0}: See {1} for your messages'.format(nick, p['url'])
        else:
            Session.remove()
            return
    else:
        map(session.delete, messages)
        session.commit()
        Session.remove()
        get_users()
        return u'{0}: {1}'.format(nick, '\n{0}: '.format(nick).join(msgs))
Beispiel #4
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
Beispiel #5
0
def tellinput(context):
    nick = context.line["user"]

    db = get_db_connection()
    db_init(db)

    tells = get_tells(db, nick)

    if len(tells) == 0:
        return

    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))

    if len(tells) > 2:
        p = paste("\n".join(reply), "Notes for {}".format(nick))
        if p["success"] == True:
            db.execute("delete from tell where user_to=lower(?)", (nick,))
            db.commit()
        else:
            return

        return "{0}: See {1} for your messages.".format(nick, p["url"])
    else:
        db.execute("delete from tell where user_to=lower(?)", (nick,))
        db.commit()
        return "\n".join(imap(lambda x: "{0}: {1}".format(nick, x), reply))
Beispiel #6
0
    def dequeue_plugin(self, plugin, plugin_context):
        for func in plugin['funcs']:
            takes_args = inspect.getargspec(func).args

            action = False
            if plugin.get('action'):
                action = True

            notice = False
            if plugin.get('notice'):
                notice = True

            try:
                if takes_args:
                    message = func(plugin_context)
                else:
                    message = func()
            except:
                etype = sys.exc_info()[0]
                plg = func.__module__
                full = ''.join(traceback.format_exception(*sys.exc_info()))
                baby = ''.join(traceback.format_tb(sys.exc_info()[2], 1)).split('\n')

                sys.stderr.write(full)

                if not self.config['SNOOP_CHANNEL']:
                    return

                try:
                    p = paste(full, title='Internal {0}'.format(etype.__name__), unlisted=1, language='pytb')
                    if p['success']:
                        self.bot.log((plg, 'EXCEPTION'), etype.__name__, p['url'])
                    else:
                        self.bot.log((plg, 'EXCEPTION', 'PASTE_FAILED'), p['error'])
                        raise Exception()
                except:
                    self.bot.log((plg, 'EXCEPTION', 'PASTE_FAILED'), etype.__name__, baby)
                return

            if message:
                self._reply(message, plugin_context.line, action, notice)
Beispiel #7
0
def tellinput(context):
    nick = context.line['user']

    if nick.lower() not in bot.data['TELL_USERS']:
        return

    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

    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))

    if len(tells) > 2:
        p = paste(u'\n'.join(reply), u'Notes for {}'.format(nick))
        if p['success'] == True:
            db.execute('delete from tell where user_to=lower(?)', (nick,))
            db.commit()
            get_users(db)
        else:
            return

        return u'{0}: See {1} for your messages.'.format(nick, p['url'])
    else:
        db.execute('delete from tell where user_to=lower(?)', (nick,))
        db.commit()
        get_users(db)
        return u'\n'.join(imap(lambda x: u'{0}: {1}'.format(nick, x), reply))
Beispiel #8
0
url = 'http://eval.appspot.com/eval'


@bot.command
def python(context):
    '.python <exp>'

    try:
        r = requests.get(url, params={'statement': context.args})
    except Exception, e:
        return 'Failed to get the result from the server: {}.'.format(e)

    if not r.text or r.status_code != 200:
        return 'Failed to get the result from the server.'

    data = r.text.strip()

    if not data:
        return 'Empty result'

    lines = data.splitlines()

    if len(lines) > 1:
        p = paste(data, language='python', title='Executed by {}'.format(context.line['user']))
        if p['success']:
            return '{0}: {1}'.format(context.line['user'], p['url'])
        else:
            return lines[-1]

    return lines[0]