Exemple #1
0
 def handler(self,matchlist):
     host = matchlist[0]
     target = matchlist[1] if matchlist[0] != self.head.nickname else nick(host)
     time = matchlist[2]
     text = matchlist[3]
     if (int(time) > 0):
         self.head.sendNotice(nick(host),"Timer started.")
         Timer(int(time),self.head.sendMsg,(target,"timed message by " + nick(host) + ": " + text)).start()
Exemple #2
0
 def handler(self,matchlist):
     host = matchlist[0]
     target = matchlist[1] if (matchlist[1] != self.head.nickname) else nick(host)
     command = matchlist[2]
     text = matchlist[3]
     if (command == "!auth") and (text == self.adminpass):
         if (host not in self.adminhosts):
             if (self.adminhosts != []):
                 for x in self.adminhosts:
                     self.head.sendMsg(nick(x),"Master added: New admin is " + host)
             self.adminhosts.append(host)
         adminNickList = []
         for x in self.adminhosts:
             adminNickList.append(nick(x))
         self.head.sendMsg(target,"Done. Admins: " + str(adminNickList))
     if (host in self.adminhosts):
         if (command == "!do"):
             self.head.sendraw(text)
         elif (command == "!py"):
             try:
                 self.head.sendMsg(target,"eval> " + str(eval(text,globals(),self.storage)))
             except Exception:
                 try:
                     exec text in globals(), self.storage
                     self.head.sendMsg(target,"exec> Done.")
                 except Exception as inst:
                     self.head.sendErr(target,inst)
         elif (command == "!pydo"):
             try:
                 for x in eval(text,globals(),self.storage):
                     exec x in globals(), self.storage
                 self.head.sendMsg(target,"exec> Done.")
             except Exception as inst:
                 self.head.sendErr(target,inst)
         elif (command == "spam?"):
             self.head.sendraw("PRIVMSG " + target + " :" + str(len(self.head.spamqueue.queue)) + " items in spamqueue.")
         elif (command == "!rehash"):
             self.head.sendraw("PRIVMSG " + target + " :Reimporting code...",)
             if (not text):
                 #rehash the head
                 if ("pyhkal" in sys.modules):
                     sys.modules.pop("pyhkal")
                 instance = self.head
                 import pyhkal
                 instance.__class__ = pyhkal.IRCBot
                 pyhkal.main(instance)
                 # # # dont rehash mods, just rehash core # # # 
             else:
                 self.rehashModule(self.head.MODLIST[text])
Exemple #3
0
    def handler(self,text):
        elementstodelete =  []
        for x in self.triggerlist:
            if (re.match(x[2],text)):
                if (type(x[1]) == type("str")):
                    self.head.sendMsg(x[0],x[1] + re.findall(x[2],text)[0])
                else:
                    self.head.sendMsg(x[0],x[1](*re.findall(x[2],text)))
                elementstodelete.append(x)
        #two loops, to not disturb the first one <.<
        for x in elementstodelete:
            self.triggerlist.remove(x)


        if (re.match(r':(.+) (PRIVMSG|\d+) ([\S]+)(?:$| (.+))',text)):
            matchlist = re.findall(r':(.+) (PRIVMSG|\d+) ([\S]+)(?:$| (.+))',text)
            matchlist = matchlist[0]
            host = matchlist[0]
            target = matchlist[2] if matchlist[2] != self.head.nickname else nick(host)
            text = matchlist[3][1:]
            w = text.split(" ")
            if (len(w) > 1) and (matchlist[1] == "PRIVMSG"):
                if (w[0] == "whois"):
                    self.head.sendraw("whois " + w[1] + " " + w[1])
                    self.addtrigger([target,self.identhost,r'.+ 311 (?:[\S]+) (?:[\S]+) ([\S]+) ([\S]+).+'])
                    self.addtrigger([target,"Real Name: ",r'.+ 311 (?:[\S]+) .+:(.+)'])
                    self.addtrigger([target,"Authnick: ",r'.+ 330 (?:[\S]+) (?:[\S]+) ([\S]+).+'])
                    self.addtrigger([target,self.raw317reply,r'.+ 317 (?:[\S]+) (?:[\S]+) (\d+ \d+)'])
                elif (w[1] == "alive?"):
                    self.head.sendraw("whois " + w[0] + " " + w[0])
                    self.addtrigger([target,self.raw317reply,r'.+ 317 (?:[\S]+) (?:[\S]+) (\d+ \d+)'])
                elif (w[1] == "lag?"):
                    self.head.sendMsg(w[0],chr(1) + "PING " + str(time.time()) + chr(1))
                    self.addtrigger([target,self.pingreply,r':({0}[\S]+) NOTICE (?:[\S]+) :.PING ([\d\.]+).'.format(w[0])])
                #removed - bot crashes if the calculation is too difficult (eg .calc 5**(5**(5**5))) - anyone knows a fix for this?    
                #http://try-python.mired.org/ has a timeout solution for this... feel free to implement it if you need .calc
                #elif (w[0] == ".calc") and (re.match(r'[0-9\s\\\+\*\-\(\)\j]',matchlist[3][6:])):
                #    self.head.sendMsg(target,matchlist[3][6:] + " = " + str(eval(matchlist[3][6:])))
            elif (matchlist[1] == "PRIVMSG"):
                if (w[0] == "lag?"):
                    self.head.sendMsg(nick(host),chr(1) + "PING " + str(time.time()) + chr(1))
                    self.addtrigger([target,self.pingreply,r':({0}[\S]+) NOTICE (?:[\S]+) :.PING ([\d\.]+).'.format(nick(host))])
Exemple #4
0
    def handler(self,text):
        elementstodelete =  []
        for x in self.triggerlist:
            if (re.match(x[2],text)):
                if (type(x[1]) == type("str")):
                    self.head.sendMsg(x[0],x[1] + re.findall(x[2],text)[0])
                else:
                    self.head.sendMsg(x[0],x[1](*re.findall(x[2],text)))
                elementstodelete.append(x)
        #two loops, to not disturb the first one <.<
        for x in elementstodelete:
            self.triggerlist.remove(x)


        if (re.match(r':(.+) (PRIVMSG|\d+) ([\S]+)(?:$| (.+))',text)):
            matchlist = re.findall(r':(.+) (PRIVMSG|\d+) ([\S]+)(?:$| (.+))',text)
            matchlist = matchlist[0]
            host = matchlist[0]
            target = matchlist[2] if matchlist[2] != self.head.nickname else nick(host)
            text = matchlist[3][1:]
            w = text.split(" ")
            if (len(w) > 1) and (matchlist[1] == "PRIVMSG"):
                if (w[0] == "whois"):
                    self.head.sendraw("whois " + w[1] + " " + w[1])
                    self.addtrigger([target,self.identhost,r'.+ 311 (?:[\S]+) (?:[\S]+) ([\S]+) ([\S]+).+'])
                    self.addtrigger([target,"Real Name: ",r'.+ 311 (?:[\S]+) .+:(.+)'])
                    self.addtrigger([target,"Authnick: ",r'.+ 330 (?:[\S]+) (?:[\S]+) ([\S]+).+'])
                    self.addtrigger([target,self.raw317reply,r'.+ 317 (?:[\S]+) (?:[\S]+) (\d+ \d+)'])
                elif (w[1] == "alive?"):
                    self.head.sendraw("whois " + w[0] + " " + w[0])
                    self.addtrigger([target,self.raw317reply,r'.+ 317 (?:[\S]+) (?:[\S]+) (\d+ \d+)'])
                elif (w[1] == "lag?"):
                    self.head.sendMsg(w[0],chr(1) + "PING " + str(time.time()) + chr(1))
                    self.addtrigger([target,self.pingreply,r':({0}[\S]+) NOTICE (?:[\S]+) :.PING ([\d\.]+).'.format(w[0])])
            elif (matchlist[1] == "PRIVMSG"):
                if (w[0] == "lag?"):
                    self.head.sendMsg(nick(host),chr(1) + "PING " + str(time.time()) + chr(1))
                    self.addtrigger([target,self.pingreply,r':({0}[\S]+) NOTICE (?:[\S]+) :.PING ([\d\.]+).'.format(nick(host))])
Exemple #5
0
 def handler(self,matchlist):
     host = matchlist[0]
     target = matchlist[1] if matchlist[1] != self.head.nickname else nick(host)
     text = matchlist[2]
     t = matchlist[2].split(" ")
     if (t[0] == "tikkle"):
         if (len(t) > 2):
             if (t[1] == "hi"):
                 try:
                     r = re.match(list2string(t[2:]),"")
                 except Exception as inst:
                     self.head.sendErr(target,inst)
                 else:
                     if nick(host) in self.tikklers:
                         x = self.tikklers[nick(host)]
                         x.regex = list2string(t[2:])
                         self.head.sendNotice(nick(host),"Ok "+ x.name + ", regex updated.")
                     else:
                         self.tikklers[nick(host)] = tikkleuser(nick(host),list2string(t[2:]))
                         self.head.sendNotice(nick(host),"Welcome to tikkle.")
             if (t[1] == "friend"):
                 try:
                     if (self.tikklers[t[2]] not in self.tikklers[nick(host)].friendlist):
                         self.tikklers[nick(host)].friendlist.append(self.tikklers[t[2]])
                         self.head.sendNotice(nick(host),"Friend added.")
                     else:
                         self.tikklers[nick(host)].friendlist.remove(self.tikklers[t[2]])
                         self.head.sendNotice(nick(host),"Friend deleted.")
                 except KeyError:
                     self.head.sendNotice(nick(host),"Couldn't befriend you. Either you or " + t[2] + " isn't registered.")
             if (t[1] == "tikkle"):
                 try:
                     self.tikklers[t[2]].mailbox.append([datetime.datetime.now(),"<" + nick(host) + "> " + list2string(t[3:]) if len(t) > 2 else "*tikkle*"])
                     self.head.sendNotice(nick(host),"Message sent.")
                 except Exception:
                     self.head.sendNotice(nick(host),"Couldnt send message. Either you or the target isnt registered.")
     if nick(host) in self.tikklers:
         x = self.tikklers[nick(host)]
         if re.match(x.regex,text) and (x.name in nick(host)):
             target = nick(host)
             self.head.sendNotice(nick(host),"Hi.")
             x.greet(text)
             for y in x.friendlist:
                 self.head.sendNotice(nick(host),y.greettime.strftime("%A@%H:%M") + " <" + y.name + "> " + y.greeting)
             for y in x.mailbox:
                 self.head.sendNotice(target,y[0].strftime("%d %b@%H:%M") + " " + y[1])
             x.mailbox = []
     self.exportconf()
Exemple #6
0
 def pingreply(self,match):
     n = nick(match[0])
     t = time.time() - float(match[1])
     return n + " ping reply: " + str(int(t * 1000)) + "ms"
Exemple #7
0
 def handler(self,matchlist):
     if ((matchlist[1] == self.head.mainchannel.name) and (not self.head.mainchannel.isReg(nick(matchlist[0])))):
         karmalist = re.findall(r'(\S\S+\+\+)(?:\s|$)|([\S]\S+--)(?:\s|$)|(\S\S+==)(?:\s|$)',matchlist[2])
         for x in karmalist:
             if x[0]:
                 if not x[0][:-2] in self.karmadict:
                     e = KarmaEntry(x[0][:-2])
                     self.karmadict[x[0][:-2]] = e
                 if not self.karmadict[x[0][:-2]].add(1):
                     self.head.sendMsg(matchlist[1],"Karmaspam - " + x[0][:-2] + " ist noch " + self.karmadict[x[0][:-2]].resttime() + " blockiert.")
                 else:
                     self.head.sendMsg(matchlist[1],x[0][:-2] + " hat nun einen karmawert von " + str(self.karmadict[x[0][:-2]].value))
             if x[1]:
                 if not x[1][:-2] in self.karmadict:
                     e = KarmaEntry(x[1][:-2])
                     self.karmadict[x[1][:-2]] = e
                 if not self.karmadict[x[1][:-2]].add(-1):
                     self.head.sendMsg(matchlist[1],"Karmaspam - " + x[1][:-2] + " ist noch " + self.karmadict[x[1][:-2]].resttime() + " blockiert.")
                 else:
                     self.head.sendMsg(matchlist[1],x[1][:-2] + " hat nun einen karmawert von " + str(self.karmadict[x[1][:-2]].value))
             if x[2]:
                 if not x[2][:-2] in self.karmadict:
                     e = KarmaEntry(x[2][:-2])
                     self.karmadict[x[2][:-2]] = e
                 self.head.sendMsg(matchlist[1],x[2][:-2] + " hat einen karmawert von " + str(self.karmadict[x[2][:-2]].value))
         if (karmalist != []):
             self.exportconf()
Exemple #8
0
    def handler(self,matchlist):
        host = matchlist[0]
        target = matchlist[1] if matchlist[1] != self.head.nickname else nick(host)
        text = matchlist[2]
        t = matchlist[2].split(" ")
        matches = [] # factoid-matching :s
        if (t[0] == "factoid"):
            if (len(t) > 2):
                if ((t[1] == "set") and (t[1] == "add")):
                    try:
                        r = re.match(list2string(t[2]),"")
                    except Exception as inst:
                        self.head.sendErr(target,inst)
                    else: # add factoid
                        try:
                            mm = re.match("factoid set \/(.+)\/ (.+)",list2string(t[0:]))
                            regex = mm.group(1)
                            reaction = mm.group(2)
                            cre = re.compile(regex)
                            
                            self.factoids.append( (cre, reaction ) )
                            if (self.head.mainchannel.isOp(nick(host))):
                                self.head.sendMsg(target,"Okay, "+ nick(host)+".")
                            else:
                                self.head.sendMsg(self.head.mainchannel.name, "Added [%s] %s »%s« via non-op" % ((len(self.factoids)-1), t[2], list2string(t[3:])) )

                        except:
                            self.head.sendMsg(target,"Invalid Regex, "+ nick(host)+" :<")
                            
                elif (t[1] == "get"):
                    gets = [ "[%s] %s -> %s" % (i, cre.pattern, subst) for i, (cre, subst) in enumerate(self.factoids) if t[2] in cre.pattern ]
                    if len(gets):
                        answer = list2string(gets,', ')
                        if (len(answer) > 300):
                            answerlist = textwrap.wrap(answer,300)
                            for ans in answerlist:
                                self.head.sendMsg(target, ans)
                        else:
                            self.head.sendMsg(target, answer )
                    else:
                        self.head.sendMsg(target, "No match..")

                elif (t[1] == "find"):

                    gets = [ "[%s] %s -> %s" % (i, cre.pattern, subst) for i, (cre, subst) in enumerate(self.factoids) if t[2] in subst ]
                    if len(gets):
                        answer = list2string(gets,', ')
                        if (len(answer) > 300):
                            answerlist = textwrap.wrap(answer,300)
                            for ans in answerlist:
                                self.head.sendMsg(target, ans)
                        else:
                            self.head.sendMsg(target, answer )
                    else:
                        self.head.sendMsg(target, "No match..")

                elif (t[1] == "num"):
                    if (int(t[2]) <= len(self.factoids)):
                        f = self.factoids[int(t[2])]
                        gets = "[%s] %s -> %s" % (t[2], f[0].pattern, f[1])
                        self.head.sendMsg(target, gets)
                    else:
                        self.head.sendMsg(target, "No match..")

                elif (t[1] == "list"): # 400 max., so we should split here :<

                    self.head.sendMsg(target, "I know %s factoids:" % (len(self.factoids)) )
                    gets = list2string ( [ "[%s] %s -> %s" % (i, cre.pattern, subst) for i, (cre, subst) in enumerate(self.factoids) ] )
                    self.head.sendMsg(target, gets)
                    
                elif ((t[1] == "del") or (t[1] == "rem")) and (self.head.mainchannel.isOp(nick(host))) and (int(t[2]) <= len(self.factoids)) :
                    del(self.factoids[int(t[2])])
                    self.head.sendMsg(target, "Done.")

        elif (randint(0,100) < self.factoidprobability): # give factoid
            for cre, subst in self.factoids:
                m = cre.search(text)
                if m:
                    tmp = cre.sub(subst, m.group(0))
                    matches.append( tmp )
    

            if (len(matches) > 0): # and (len(t[1:]) > 15) and (len(t) > 3):
                rply = matches[randint(0,len(matches)-1)].replace("$who", nick(host)) # choose random factoid, regard replacement of $who
                rply = rply.replace("$someone",random.choice(bot.mainchannel.nicklist.keys())) # replace $someone with ..someone ;)
                rply = rply.replace("\n","\\n") # output validation :)
                if rply.startswith("A:"): # reactions starting with "A:" will be send as /me
                     self.head.sendAction(target, rply[2:]) # strip first two chars
                else:
                     self.head.sendMsg(target, rply)
 #               except ValueError:
 #                   pass
            #print(list2string(matches,","))
            matches = []

        self.exportconf()