예제 #1
0
파일: remember.py 프로젝트: 030303/skybot
def remember(inp, nick='', chan='', db=None, input=None, notice=None, bot=None):
    ".remember [.] <word> is <data> -- maps word to data in the memory, '.' means here only"
    db_init(db)
    
    local, chan, inp = checkinp(chan, inp, True)
    
        
    try:
        head, tail = inp.split(" ", 1)
    except ValueError:
        return remember.__doc__
    if tail.startswith("is "):
        tail=" ".join(tail.split(" ")[1:])
    
    if tail.startswith("<locked") and not usertracking.query(db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "you may not lock factoids.")
        return

    data = get_memory(db, chan, head)
    
    if data and data.startswith("<locked") and not usertracking.query(db, bot.config, nick, chan, "remember.lock"):
        input.notice(("[local]" if local else "") + "that factoid is locked.")
        return
    if data and not data.startswith("<forgotten>"):
        notice("but '%s' already means something else!" % head.replace("'", "`"))
        return
    elif data and data.startswith("<forgotten>"):
        input.notice(("[local]" if local else "") + "permanently deleting "+repr(data)+" to accomodate this")
    
    db.execute("replace into memory(chan, word, data, nick) values"
               " (?,lower(?),?,?)", (chan, head, tail, nick))
    print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr((chan, head, tail, nick))
    db.commit()
    notice(("[local]" if local else "") + 'done.')
예제 #2
0
def unforget(inp, chan='', db=None, nick='', notice=None):
    ".unforget [.] <word> -- re-remembers the mapping the word had before, '.' means here only "
    db_init(db)

    local, chan, inp = checkinp(chan, inp, True)

    data = get_memory(db, chan, inp)
    if data and data.startswith("<locked") and not usertracking.query(
            db, bot.config, nick, chan, "remember.lock"):
        input.notice(("[local]" if local else "") + "that factoid is locked.")
        return

    if data and data.startswith("<forgotten>"):
        db.execute(
            "replace into memory(chan, word, data, nick) values"
            " (?,lower(?),?,?)",
            (chan, inp, data.replace("<forgotten>", "").strip(), nick))
        print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr(
            (chan, inp, data.replace("<forgotten>", "").strip(), nick))
        db.commit()
        notice(("[local]" if local else "") +
               ('unforgot `%s`' % data.replace('`', "'")))
    elif data:
        notice(("[local]" if local else "") + "I still remember that.")
    else:
        notice(("[local]" if local else "") + "I never knew about that.")
예제 #3
0
def forget(inp, chan='', db=None, nick='', notice=None):
    ".forget [.] <word> -- forgets the mapping that word had, '.' means here only"
    local, chan, inp = checkinp(chan, inp, True)
    db_init(db)

    data = get_memory(db, chan, inp)
    if data and data.startswith("<locked") and not usertracking.query(
            db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "that factoid is locked.")
        return
    if data and not data.startswith("<forgotten>"):
        db.execute(
            "replace into memory(chan, word, data, nick) values"
            " (?,lower(?),?,?)", (chan, inp, "<forgotten>" + data, nick))
        print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr(
            (chan, inp, "<forgotten>" + data, nick))
        #db.execute("delete from memory where chan=? and word=lower(?)",
        #           (chan, inp))
        db.commit()
        notice(("[local]" if local else "") +
               ('forgot `%s`' % data.replace('`', "'")))
    elif data:
        notice(("[local]" if local else "") + "I already archived that.")
    else:
        notice(("[local]" if local else "") + "I don't know about that.")
예제 #4
0
파일: remember.py 프로젝트: 030303/skybot
def no(inp, nick='', chan='', db=None, notice=None, bot=None):
    ".no <word> is <data> -- remaps word to data"
    
    local, chan, inp = checkinp(chan, inp, True)
    
    db_init(db)
    try:
        head, tail = inp.split(" ", 1)
    except ValueError:
        return no.__doc__
    if tail.startswith("is "):
        tail=" ".join(tail.split(" ")[1:])
    
    if tail.startswith("<locked") and not usertracking.query(db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "you may not lock factoids.")
        return

    data = get_memory(db, chan, head)
    
    if not data:
        notice("but '%s' doesn't exist!" % head.replace("'", "`"))
        return
    if data and data.startswith("<locked") and not users.query(db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "that factoid is locked, sorry.")
        return
    
    db.execute("replace into memory(chan, word, data, nick) values"
               " (?,lower(?),?,?)", (chan, head, tail, nick))
    print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr((chan, head, tail, nick))
    db.commit()
    notice('forgetting "%s", remembering this instead.' % \
                data.replace('"', "''"))
예제 #5
0
파일: stfu.py 프로젝트: AxelsDawn/skybot
def stfu(inp, input=None, db=None, bot=None, users=None):
    if inp and inp in input.conn.users.channels.keys():
        input.chan = inp
    if usertracking.query(db, bot.config, input.nick, input.chan, "stfu") or "o" in users[input.chan].usermodes[input.nick]:
        users[input.chan].stfu = "%s %d" % (input.nick, time.time())
        input.notice("I am now muted here.")
    else:
        input.notice("you don't have permission to do that")
예제 #6
0
def remember(inp,
             nick='',
             chan='',
             db=None,
             input=None,
             notice=None,
             bot=None):
    ".remember [.] <word> is <data> -- maps word to data in the memory, '.' means here only"
    db_init(db)

    local, chan, inp = checkinp(chan, inp, True)

    try:
        head, tail = inp.split(" ", 1)
    except ValueError:
        return remember.__doc__
    if tail.startswith("is "):
        tail = " ".join(tail.split(" ")[1:])

    if tail.startswith("<locked") and not usertracking.query(
            db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "you may not lock factoids.")
        return

    data = get_memory(db, chan, head)

    if data and data.startswith("<locked") and not usertracking.query(
            db, bot.config, nick, chan, "remember.lock"):
        input.notice(("[local]" if local else "") + "that factoid is locked.")
        return
    if data and not data.startswith("<forgotten>"):
        notice("but '%s' already means something else!" %
               head.replace("'", "`"))
        return
    elif data and data.startswith("<forgotten>"):
        input.notice(("[local]" if local else "") + "permanently deleting " +
                     repr(data) + " to accomodate this")

    db.execute(
        "replace into memory(chan, word, data, nick) values"
        " (?,lower(?),?,?)", (chan, head, tail, nick))
    print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr(
        (chan, head, tail, nick))
    db.commit()
    notice(("[local]" if local else "") + 'done.')
예제 #7
0
def stfu(inp, input=None, db=None, bot=None, users=None):
    if inp and inp in input.conn.users.channels.keys():
        input.chan = inp
    if usertracking.query(
            db, bot.config, input.nick, input.chan,
            "stfu") or "o" in users[input.chan].usermodes[input.nick]:
        users[input.chan].stfu = "%s %d" % (input.nick, time.time())
        input.notice("I am now muted here.")
    else:
        input.notice("you don't have permission to do that")
예제 #8
0
파일: pyexec.py 프로젝트: lukegb/skybot
def ply(inp, bot=None, input=None, nick=None, db=None, chan=None):
    "execute local python - only admins can use this"
    if not usertracking.query(db, bot.config, nick, chan, "ply"):
        return "nope"
    asdf = inp.split(" ")
    asdfa = asdf[0]
    if asdfa == "eval":
        return eval(" ".join(asdf[1:]))
    elif asdfa == "exec":
        rexec(" ".join(asdf[1:]), bot, input, db)
예제 #9
0
파일: remember.py 프로젝트: 030303/skybot
def mem(inp, chan='', db=None, nick='', notice=None, user='', host='', bot=None):
    "controls memory."
    
    def lock(name):
        db_init(db)
        local = name.startswith("l:")
        if name.startswith("l:"):
            name=name[2:]
        facchan = defaultchan if not local else chan
        data = get_memory(db, facchan, name)
        if data and data.startswith("<locked"):
            notice("already locked")
        elif data:
            data = "<locked:%s!%s@%s %s %d>%s" % (nick, user, host, chan, time.time(), data)
            db.execute("replace into memory(chan, word, data, nick) values"
               " (?,lower(?),?,?)", (facchan, name, data, nick))
            db.commit()
            
    def unlock(name):
        db_init(db)
        local = name.startswith("l:")
        if name.startswith("l:"):
            name=name[2:]
        facchan = defaultchan if not local else chan
        data = get_memory(db, facchan, name)
        if data and not data.startswith("<locked"):
            notice("that's not locked..?")
        elif data:
            filtermatch = filter_re.search(data)
            if filtermatch:
                filtername = filtermatch.group(1).lower()
                data = filtermatch.group(2)
                notice("unlocking: "+filtername)
                db.execute("replace into memory(chan, word, data, nick) values"
                   " (?,lower(?),?,?)", (facchan, name, data, nick))
                db.commit()
            else:
                notice("this should never happen, but that doesn't seem to be a valid locked factoid. I'm just gonna delete it and let you recreate it, k?")
                notice("current value: "+repr(data))
                db.execute("delete from memory where chan=? and word=?", (facchan, name))
                db.commit()
            
            
    commands = {"lock": [1, lock], "unlock": [1, unlock]}
    split = inp.split(" ")
    if len(split):
        if not usertracking.query(db, bot.config, nick, chan, "remember.commands."+split[0]):
            return "you do not have permission to use that command"
        if len(split) == commands[split[0]][0]+1:
            func = commands[split[0]][1]
            func(*split[1:])
        else:
            return "wrong number of args for command"
    else:
        return "arguments reqired"
예제 #10
0
파일: stfu.py 프로젝트: AxelsDawn/skybot
def kthx(inp, input=None, db=None, bot=None, users=None):
    if inp and inp in users.channels.keys():
        input.chan = inp
    if usertracking.query(db, bot.config, input.nick, input.chan, "stfu") or "o" in users[input.chan].usermodes[input.nick]:
        if hasattr(users[input.chan], "stfu"):
            input.notice("I am no longer muted here.")
            del users[input.chan].stfu
        else:
            input.notice("I am not muted here.")
    else:
        input.notice("you don't have permission to do that")
예제 #11
0
def kthx(inp, input=None, db=None, bot=None, users=None):
    if inp and inp in users.channels.keys():
        input.chan = inp
    if usertracking.query(
            db, bot.config, input.nick, input.chan,
            "stfu") or "o" in users[input.chan].usermodes[input.nick]:
        if hasattr(users[input.chan], "stfu"):
            input.notice("I am no longer muted here.")
            del users[input.chan].stfu
        else:
            input.notice("I am not muted here.")
    else:
        input.notice("you don't have permission to do that")
예제 #12
0
파일: pyexec.py 프로젝트: Krenair/skybot
def ply(inp, bot=None, input=None, nick=None, db=None, chan=None):
    "execute local python - only admins can use this"
    if not usertracking.query(db, bot.config, nick, chan, "ply"):
        return "nope"
    try:
        _blah = dict(globals())
        _blah.update(input)
        _blah.update(locals())
        exec inp in _blah
        return _blah["_r"] if "_r" in _blah else None
    except:
        import traceback

        s = traceback.format_exc()
        sp = [x for x in s.split("\n") if x]
        if len(sp) > 2:
            sp = sp[-2:]
        for i in sp:
            input.notice(i)
예제 #13
0
파일: remember.py 프로젝트: 030303/skybot
def unforget(inp, chan='', db=None, nick='', notice=None):
    ".unforget [.] <word> -- re-remembers the mapping the word had before, '.' means here only "
    db_init(db)
    
    local, chan, inp = checkinp(chan, inp, True)
        
    data = get_memory(db, chan, inp)
    if data and data.startswith("<locked") and not usertracking.query(db, bot.config, nick, chan, "remember.lock"):
        input.notice(("[local]" if local else "") + "that factoid is locked.")
        return
    
    if data and data.startswith("<forgotten>"):
        db.execute("replace into memory(chan, word, data, nick) values"
               " (?,lower(?),?,?)", (chan, inp, data.replace("<forgotten>","").strip(), nick))
        print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr((chan, inp, data.replace("<forgotten>","").strip(), nick))
        db.commit()
        notice(("[local]" if local else "") + ('unforgot `%s`' % data.replace('`', "'")))
    elif data:
        notice(("[local]" if local else "") + "I still remember that.")
    else:
        notice(("[local]" if local else "") + "I never knew about that.")
예제 #14
0
파일: remember.py 프로젝트: 030303/skybot
def forget(inp, chan='', db=None, nick='', notice=None):
    ".forget [.] <word> -- forgets the mapping that word had, '.' means here only"
    local, chan, inp = checkinp(chan, inp, True)
    db_init(db)
    
    
    data = get_memory(db, chan, inp)
    if data and data.startswith("<locked") and not usertracking.query(db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "that factoid is locked.")
        return
    if data and not data.startswith("<forgotten>"):
        db.execute("replace into memory(chan, word, data, nick) values"
               " (?,lower(?),?,?)", (chan, inp, "<forgotten>"+data, nick))
        print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr((chan, inp, "<forgotten>"+data, nick))
        #db.execute("delete from memory where chan=? and word=lower(?)",
        #           (chan, inp))
        db.commit()
        notice(("[local]" if local else "") + ('forgot `%s`' % data.replace('`', "'")))
    elif data:
        notice(("[local]" if local else "") + "I already archived that.")
    else:
        notice(("[local]" if local else "") + "I don't know about that.")
예제 #15
0
def no(inp, nick='', chan='', db=None, notice=None, bot=None):
    ".no <word> is <data> -- remaps word to data"

    local, chan, inp = checkinp(chan, inp, True)

    db_init(db)
    try:
        head, tail = inp.split(" ", 1)
    except ValueError:
        return no.__doc__
    if tail.startswith("is "):
        tail = " ".join(tail.split(" ")[1:])

    if tail.startswith("<locked") and not usertracking.query(
            db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "you may not lock factoids.")
        return

    data = get_memory(db, chan, head)

    if not data:
        notice("but '%s' doesn't exist!" % head.replace("'", "`"))
        return
    if data and data.startswith("<locked") and not users.query(
            db, bot.config, nick, chan, "remember.lock"):
        notice(("[local]" if local else "") + "that factoid is locked, sorry.")
        return

    db.execute(
        "replace into memory(chan, word, data, nick) values"
        " (?,lower(?),?,?)", (chan, head, tail, nick))
    print "replace into memory(chan, word, data, nick) values (?,lower(?),?,?)", repr(
        (chan, head, tail, nick))
    db.commit()
    notice('forgetting "%s", remembering this instead.' % \
                data.replace('"', "''"))
예제 #16
0
파일: pyexec.py 프로젝트: NoiSek/classhole
def ply(inp, bot=None, input=None, nick=None, db=None, chan=None):
    "execute local python - only admins can use this"
    if not usertracking.query(db, bot.config, nick, chan, "ply"):
        return "nope"
    arguments = inp.split(" ")
    exec(" ".join(arguments[1:]))
예제 #17
0
def mem(inp,
        chan='',
        db=None,
        nick='',
        notice=None,
        user='',
        host='',
        bot=None):
    "controls memory."

    def lock(name):
        db_init(db)
        local = name.startswith("l:")
        if name.startswith("l:"):
            name = name[2:]
        facchan = defaultchan if not local else chan
        data = get_memory(db, facchan, name)
        if data and data.startswith("<locked"):
            notice("already locked")
        elif data:
            data = "<locked:%s!%s@%s %s %d>%s" % (nick, user, host, chan,
                                                  time.time(), data)
            db.execute(
                "replace into memory(chan, word, data, nick) values"
                " (?,lower(?),?,?)", (facchan, name, data, nick))
            db.commit()

    def unlock(name):
        db_init(db)
        local = name.startswith("l:")
        if name.startswith("l:"):
            name = name[2:]
        facchan = defaultchan if not local else chan
        data = get_memory(db, facchan, name)
        if data and not data.startswith("<locked"):
            notice("that's not locked..?")
        elif data:
            filtermatch = filter_re.search(data)
            if filtermatch:
                filtername = filtermatch.group(1).lower()
                data = filtermatch.group(2)
                notice("unlocking: " + filtername)
                db.execute(
                    "replace into memory(chan, word, data, nick) values"
                    " (?,lower(?),?,?)", (facchan, name, data, nick))
                db.commit()
            else:
                notice(
                    "this should never happen, but that doesn't seem to be a valid locked factoid. I'm just gonna delete it and let you recreate it, k?"
                )
                notice("current value: " + repr(data))
                db.execute("delete from memory where chan=? and word=?",
                           (facchan, name))
                db.commit()

    commands = {"lock": [1, lock], "unlock": [1, unlock]}
    split = inp.split(" ")
    if len(split):
        if not usertracking.query(db, bot.config, nick, chan,
                                  "remember.commands." + split[0]):
            return "you do not have permission to use that command"
        if len(split) == commands[split[0]][0] + 1:
            func = commands[split[0]][1]
            func(*split[1:])
        else:
            return "wrong number of args for command"
    else:
        return "arguments reqired"