예제 #1
0
 def pC(self):
     a = self.process()
     if a!=False:
         chan     = a[1:].split(':',1)[0].split(" ")[2]
         sender   = a[1:].split("!")[0]
         message  = a[1:].split(':',1)[1]
         splitted = message.split(" ")
         if splitted[0].find(bu.config.getkey(bu.config(),bu.config(),'settings')['nickname'])!=-1 or splitted[0].find(bu.config.getkey(bu.config(),bu.config(),'settings')['nickname']+':')!=-1 or splitted[0].find(bu.config.getkey(bu.config(),'settings')['nickname']+',')!=-1:
             del splitted[0]
             if chan[0]=='#':
                 if message.lower().find("anonymous message")!=-1:
                     tosend = ''
                     if len(splitted)>3:
                         del splitted[0]
                         del splitted[0]
                         receiver = splitted[0]
                         del splitted[0]
                         message = ' '.join(splitted)
                         tosend += "NOTICE %s :Your message will be sent to %s if they're online.\n"%(sender,receiver)
                         tosend += "PRIVMSG %s :You have an anonymous message as follows:\n"%(receiver)
                         tosend += "PRIVMSG %s :%s\n"%(receiver,message)
                         self.send(tosend)
                     else:
                         tosend += "NOTICE %s :Incorrect usage. Usage: \"%s: Anonymous message User123 text\"\n"%(sender,bu.config.getkey(bu.config(),'settings')['nickname'])
                         self.send(tosend)
                 elif message.lower().find("message")!=-1:
                     tosend = ''
                     if len(splitted)>2:
                         del splitted[0]
                         receiver = splitted[0]
                         del splitted[0]
                         message = ' '.join(splitted)
                         tosend += "NOTICE %s :Your message will be sent to %s if they're online.\n"%(sender,receiver)
                         tosend += "PRIVMSG %s :You have a message from %s as follows:\n"%(receiver,sender)
                         tosend += "PRIVMSG %s :%s\n"%(receiver,message)
                         self.send(tosend)
                     else:
                         tosend += "NOTICE %s :Incorrect usage. Usage: \"%s: Message User123 text\"\n"%(sender,bu.config.getkey(bu.config(),'settings')['nickname'])
                         self.send(tosend)
                 elif message.lower().find('help')!=-1:
                     tosend = ''
                     tosend += "NOTICE %s : \x02***** %s Help *****\n"%(sender,bu.config.getkey(bu.config(),'settings')['nickname'])
                     for a in self.helptext:
                         tosend += "NOTICE %s : \x02%s\n"%(sender,a)
                     tosend += "NOTICE %s : \x02***** End Help *****\n"%(sender)
                     self.send(tosend)
                 elif message.lower().find('weather')!=-1:
                     if message.find('today')!=-1 and 'in' in splitted:
                         r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=%s'%(splitted[-1].replace("?","").replace("!","").replace(".","")))
                         a = r.json()
                         if a['cod']==200:
                             tosend = ''
                             tosend += "PRIVMSG %s :%s: Today is %s in %s with a temperature of %sC.\n"%(chan,sender,a['weather'][0]['main'].lower(),a['name'],str(int(a['main']['temp']) - 273))
                             self.send(tosend.encode('utf-8'))
                         else:
                             tosend = ''
                             tosend += "PRIVMSG %s :%s: Sorry, I could not find that city.\n"%(chan,sender)
                             self.send(tosend)
                     elif message.find('today')!=-1 and not 'in' in splitted:
                         tosend = ''
                         tosend += "PRIVMSG %s :%s: Please specify a city. Usage: \"%s: What's the weather like today in London?\"\n"%(chan,sender,bu.config.getkey(bu.config(),'settings')['nickname'])
                         self.send(tosend)
                     elif message.find('today')==-1 and 'in' in splitted:
                         r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=%s'%(splitted[-1].replace("?","").replace("!","").replace(".","")))
                         a = r.json()
                         if a['cod']==200:
                             tosend = ''
                             tosend += "PRIVMSG %s :%s: Today is %s in %s with a temperature of %sC.\n"%(chan,sender,a['weather'][0]['main'].lower(),a['name'],str(int(a['main']['temp']) - 273))
                             self.send(tosend.encode('utf-8'))
                         else:
                             tosend = ''
                             tosend += "PRIVMSG %s :%s: Sorry, I could not find that city.\n"%(chan,sender)
                             self.send(tosend)
                 elif message.lower().find('umbrella')!=-1:
                     if 'in' in splitted:
                         r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=%s'%(splitted[-1].replace("?","").replace("!","").replace(".","")))
                         a = r.json()
                         if a['cod']==200:
                             if a['weather'][0]['main'].lower() == 'rain':
                                 tosend = ''
                                 tosend += "PRIVMSG %s :%s: You should. It is %sing in %s with a temperature of %sC.\n"%(chan,sender,a['weather'][0]['main'].lower(),a['name'],str(int(a['main']['temp']) - 273))
                                 self.send(tosend.encode('utf-8'))
                             else:
                                 tosend = ''
                                 tosend += "PRIVMSG %s :%s: You shouldn't. It is %s in %s with a temperature of %sC.\n"%(chan,sender,a['weather'][0]['main'].lower(),a['name'],str(int(a['main']['temp']) - 273))
                                 self.send(tosend.encode('utf-8'))
                         else:
                             tosend = ''
                             tosend += "PRIVMSG %s :%s: Sorry, I could not find that city.\n"%(chan,sender)
                             self.send(tosend)
                     elif not 'in' in splitted:
                         tosend = ''
                         tosend += "PRIVMSG %s :%s: Please specify a city. Usage: \"%s: Should I use an umbrella in London?\"\n"%(chan,sender,bu.config.getkey(bu.config(),'settings')['nickname'])
                         self.send(tosend)
                 elif message.lower().find('go away')!=-1:
                     if sender in bu.config.getkey(bu.config(),'settings')['authusers']:
                         if message.lower().find('from')!=-1:
                         	self.part(splitted[splitted.index('from')+1], "I was requested to part.")
                         else:
                             self.part(chan, "Goodbye.")
                     else:
                         tosend = "PRIVMSG %s :%s: Why don't YOU go away?\n"%(chan, sender)
                         self.send(tosend)
                 elif message.lower().find('f**k off')!=-1:
                     if sender in bu.config.getkey(bu.config(),'settings')['authusers']:
                     	self.part(chan, "Goodbye.")
                     else:
                         tosend += "PRIVMSG %s :%s: Why don't YOU f**k off?\n"%(chan, sender)
                         self.send(tosend)
                 elif message.lower().find('join')!=-1:
                     if sender in bu.config.getkey(bu.config(),'settings')['authusers']:
                         t = []
                         for c in splitted:
                             if c[:1]=="#":
                                 t.append(c)
                         self.join(t)
                     else:
                         tosend == "PRIVMSG %s :%s: You can't make me join anywhere!\n"%(chan,sender)
                         self.send(tosend)
                 elif message.lower().find('reload')!=-1:
                     self.part(bu.config.getkey(bu.config(),'settings')['channels'], "I'm restarting.")
                     tosend += "QUIT Done\n"
                     self.send(tosend)
                     python = sys.executable
                     os.execl(python, python, * sys.argv)
                 elif message.lower().find("admins")!=-1:
                     tosend = ''
                     if message.lower().find("add")!=-1 and sender in bu.config.getkey(bu.config(),'settings')['authusers']:
                         bu.config.setkey(bu.config(),"settings", {'authusers': bu.config.getkey(bu.config(),'settings')['authusers'].append(splitted[splitted.index('add')+1]) })
                         tosend += "PRIVMSG %s :%s: %s can now control me.\n"%(chan,sender,splitted[splitted.index('add')+1])
                         self.send(tosend)
                     elif message.lower().find("list")!=-1 and sender in bu.config.getkey(bu.config(),'settings')['authusers']:
                         ops = ''
                         for a in bu.config.getkey(bu.config(),'settings')['authusers']:
                             ops += a+', '
                         tosend += "PRIVMSG %s :%s: My operators are: %s.\n"%(chan,sender,ops[:-2])
                         self.send(tosend)
                     elif message.lower().find("remove")!=-1 and sender in bu.config.getkey(bu.config(),'settings')['authusers']:
                         bu.config.setkey(bu.config(),"settings", { 'authusers': bu.config.getkey(bu.config(),'settings')['authusers'].remove(splitted[splitted.index('remove')+1])} )
                         tosend += "PRIVMSG %s :%s: %s can no longer control me.\n"%(chan,sender,splitted[splitted.index('remove')+1])
                         self.send(tosend)
                     else:
                         self.queue.append(":"+sender+'!aa@aa PRIVMSG '+chan+' :TextSiri: list your admins')
                 elif message.lower().find("answer")!=-1 and message.lower().find("universe")!=-1:
                     tosend = ''
                     tosend += "PRIVMSG %s :%s: The answer for 'the universe' is 42, as far as I know.\n"%(chan,sender)
                     self.send(tosend)
예제 #2
0
 def __init__(self, server='', username='', password='', realname='A bot', ident='bot', port=6667):
     self.join(bu.config.getkey(bu.config(),'channels'))
     timr.Timer(0.1,self.receive).start()
     timr.Timer(0.5,self.pC).start()