Example #1
0
 def __init__(self,client,irccmd,evsys):
     self.irccmd = irccmd
     self.client = client
     self.evsys = evsys
     self.sender = irccmd.prefix.partition(b'!')[0].lower()
     self.senderident = irccmd.prefix.partition(b'!')[2].partition(b'@')[0].lower()
     self.senderhost = irccmd.prefix.partition(b'@')[2].lower()
     self.target = irccmd.args[0].lower()
     self.replyto = irccmd.args[0].lower()
     self.private = False
     with client[0]:
         self.coding = client[1]["coding"]
         self.codings = client[1]["codings"]
         if (self.replyto == client[1]["irc_nickname"].encode("ascii").lower()):
             self.replyto = self.sender
             self.private = True
     for enc in self.codings:
         try:
             self.text = irccmd.args[1].decode(enc)
         except:
             pass
         else:
             break
     #self.text = irccmd.args[1].decode(self.coding)
     try:
         pipe = re.match(r"(.*?)\$\|\s*([#&%a-zA-Z]*)",self.text)
         if pipe and isBotOp(client,self):
             self.replyto = pipe.group(2).lower().encode("ascii")
             self.text = pipe.group(1)
     except UnicodeEncodeError:
         pass
Example #2
0
def handle_irc_privmsg(client,privmsg,*args,e):
    cmd = privmsg.text.strip().partition(" ")
    if cmd[0].startswith("??") and not cmd[0]=="??":
        cmd = ("??"," ",cmd[0][2:])
    if cmd[0].startswith(".?") and not cmd[0]==".?":
        cmd = (".?"," ",cmd[0][2:])
    global db
    if cmd[0] == ".?":
        if not cmd[2]: return False
        foo,nohandle,topic = cmd[2].lower().partition("-")
        if not (not foo and nohandle):
            topic = cmd[2].lower()
        factoid = db.get(topic,None)
        if not factoid: return False
        if nohandle:
            privmsg.reply_imore(factoid)
        else:
            privmsg.reply_imore(handleFact(factoid,db))
    elif cmd[0] == ".!" or cmd[0] == ".learn":
        if not cmd[2]: return False
        foo = re.match('"(.+?)" (.+)',cmd[2])
        bar = re.match("'(.+?)' (.+)",cmd[2])
        if foo:
            key,text = foo.groups()
        else:
            if bar:
                key,text = bar.groups()
            else:
                key = cmd[2].partition(" ")[0]
                text = cmd[2].partition(" ")[2]
        key = key.lower()
        if not text: return False
        db[key] = text
        privmsg.reply("factoid about '%s' saved."%key)
    elif cmd[0].startswith(".factoid"):
        if not cmd[2]: return False
        cmd = cmd[2].partition(" ")
        if cmd[0] == "add":
            if not cmd[2]: return False
            foo = re.match('"(.+?)" (.+)',cmd[2])
            bar = re.match("'(.+?)' (.+)",cmd[2])
            if foo:
                key,text = foo.groups()
            else:
                if bar:
                    key,text = bar.groups()
                else:
                    return False
            key = key.lower()
            if not text: return False
            db[key] = text
            privmsg.reply("factoid about '%s' saved."%key)
        elif cmd[0] == "del":
            try:
                del db[cmd[2].lower()]
            except:
                pass
            else:
                privmsg.reply("GOTSCHA! crocodile hunter *oho*")
        elif cmd[0] == "delmulti":
            if not cmd[2]: return False
            if not isBotOp(client,privmsg): return False
            matches = [x for x in db.keys() if re.match(cmd[2],x)]
            drops = [db.pop(x) for x in matches]
            privmsg.reply("deleted %s matches"%len(drops))
        elif cmd[0] == "get" or cmd[0] == "show":
            if not cmd[2]: return False
            factoid = db.get(cmd[2].lower(),None)
            if not factoid: return False
            privmsg.reply(factoid)
        elif cmd[0] == "cp":
            source,foo,dest = cmd[2].lower().partition(" ")
            if not foo: return False
            content = db.get(source,None)
            if not content: privmsg.reply("no such factoid, bro!")
            db[dest] = content
        elif cmd[0] == "mv":
            source,foo,dest = cmd[2].lower().partition(" ")
            if not foo: return False
            content = db.get(source,None)
            if not content: privmsg.reply("no such factoid, bro!")
            db[dest] = content
            del db[source]
        elif cmd[0] == "list":
            if cmd[2]:
                privmsg.reply_blockmore(sorted(
                    [x for x in db.keys() if re.match(cmd[2],x)]),
                    delim=b", ",topic=b"Factoid list: ")
            else:
                privmsg.reply_blockmore(sorted(
                    db.keys()),delim=b", ",topic=b"Factoid list: ")
    return False
Example #3
0
def handle_irc_privmsg(client,privmsg,*args,e):
    global db
    command = re.match(r"^\.alt( (?P<channel>[^\s]+))? (?P<link>[^\s]+)$",privmsg.text)
    if command:
        link = command.group("link")
        channel = command.group("channel")
        if not channel:
            if privmsg.private:
                privmsg.reply("du könntest mir noch den channel verraten...")
                return False
            channel = privmsg.replyto.decode("ascii")
        if link == "disable" or link.startswith("enable"):
            if isBotOp(client,privmsg):
                if link == "disable":
                    if db.get(channel):
                        del db[channel]
                        privmsg.reply("jop.")
                elif link.startswith("enable"):
                    try:
                        count = int(link[7:])
                    except ValueError:
                        count = 50
                    db.setdefault(channel,[0,[]])[0] = count
                    privmsg.reply("jop. count ist %i"%count)
            else:
                privmsg.reply("*grins*")
        else:
            entry = db.get(channel,[0,[]])
            if entry[0] == 0:
                privmsg.reply("das 'alt'-feature ist in diesem channel abgeschaltet")
            elif entry[0] > 0:
                matches = sorted([x for x in entry[1] if x[1]==link])
                if matches:
                    privmsg.reply("%s wurde insgesamt %i Mal gepostet, das erste Mal vor %s"%(
                        link[-40:], len(matches), outputTime(time.time()-matches[0][0],True)))
                else:
                    privmsg.reply("%s ist ganz frisch!"%link)
    else:
        if not privmsg.private and not privmsg.text.startswith("."):
            links = re.findall(r"[\w\d\-\.+]+:[^\s\?#]+(?:\?[^\s]+)?(?:#[^\s]+)?",privmsg.text)
            links = [x for x in links if x.startswith("http")]
            if links:
                entry = db.get(privmsg.replyto.decode("ascii"),[0,[]])
                global short_period
                toshortago = time.time() - short_period
                for link in links:
                    was_posted = sorted([x for x in entry[1] if x[1]==link])
                    if was_posted and was_posted[-1][0]<toshortago:
                        continue
                    break
                else:
                    global lastalt
                    global trottle
                    if time.time()-lastalt > throttle:
                        global wait_min
                        global wait_max
                        threading.Timer(random.randint(wait_min,wait_max),waitAlt,args=[privmsg,]).start()
                        lastalt = time.time()
                if entry[0] > 0:
                    newlist = entry[1] + [(time.time(),link) for link in links]
                    entry[1] = newlist[-entry[0]:]
    return False