Advertisement
Guest User

PreBOT V1.0 use PreDB.Me with Treads and Search

a guest
Mar 28th, 2013
1,418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.39 KB | None | 0 0
  1. #   PreBOT V1.0
  2. #   Built By El3ct71k
  3. #       PreDB.Me
  4.  
  5. import socket, string, urllib2, threading, time
  6. import xml.etree.ElementTree as etree
  7. login = {'server':'irc.efnet.nl','port':'6667','nickname':'PREBOT','idenet':'PREBOT','realname':'Carolina'}
  8. channels = {'#staff':''}
  9. categories = ['Movies-SD','Movies-HD','TV-SD','TV-HD', 'GAMES-PC']
  10. color = {'black':chr(3)+"1",'blue':chr(3)+"12",'gray':chr(3)+"14",'red':chr(3)+"4",'green':chr(3)+"3",'orange':chr(3)+"7"}
  11. lastpre = {}
  12. def LoginIRC():
  13.     irc=socket.socket()
  14.     irc.connect((login['server'], int(login['port'])))
  15.     irc.send("NICK %s\r\n" % login['nickname'])
  16.     irc.send("USER %s %s:%s bla :%s\r\n" % (login['idenet'], login['server'], login['port'], login['realname']))
  17.     for chan,key in channels.iteritems():
  18.         irc.send("JOIN %s %s\r\n" % (chan, key))
  19.     while True:
  20.         readbuffer=""
  21.         readbuffer=readbuffer+irc.recv(1024)
  22.         temp=string.split(readbuffer, "\n")
  23.         readbuffer=temp.pop()
  24.  
  25.         for line in temp:
  26.             line=string.rstrip(line)
  27.             line=string.split(line)
  28.         if(line[0]=="PING"):
  29.             irc.send("PONG %s\r\n" % line[1])
  30.         mynick = line[0].split('!')[0].replace(':', '')
  31.         PreBOT(irc)
  32.         if line[1].startswith('PRIVMSG'):
  33.             if(line[3].lower()==':!pre'):
  34.                 threading.Thread(target=PrebotSEARCH, args=(line, irc)).start()
  35.             if(mynick.lower() == 'cyb3rw0rm'):
  36.                 if(line[3].lower()==":!command"):
  37.                     Management(irc,line)
  38.                 elif(line[3].lower()==":!addpre"):
  39.                     try:
  40.                         try:
  41.                             chan = line[4]+" "+line[5]
  42.                             channels[line[4]] = line[5]
  43.                         except:
  44.                             chan = line[4]
  45.                             channels[line[4]] = ''
  46.                         irc.send("JOIN %s\r\n" % (chan))
  47.                     except:
  48.                         irc.send ("PRIVMSG %s : %s \r\n" % (line[2], color['red']+"Error"+color['gray']+"["+color['blue']+"!"+color['gray']+"]"+color['orange']+" try again.. syntax: !addpre #chan key"))
  49.                        
  50.                 elif(line[3].lower()==":!delpre"):
  51.                     try:
  52.                         del channels[line[4]]
  53.                         irc.send("PART %s\r\n" % line[4])
  54.                     except:
  55.                         irc.send ("PRIVMSG %s : %s \r\n" % (line[2], color['red']+"Error"+color['gray']+"["+color['blue']+"!"+color['gray']+"]"+color['orange']+" try again.. syntax: !delpre #chan"))
  56.                 elif(line[3].lower()==":!listpre"):
  57.                     irc.send ("PRIVMSG %s : %s \r\n" % (line[2], color['blue']+"My Channels:"+color['blue']))
  58.                     for listchan in channels:
  59.                         irc.send ("PRIVMSG %s : %s \r\n" % (line[2], "    "+color['green']+listchan+color['green']))
  60.                
  61.            
  62. def PreBOT(irc):
  63.     for type in categories:
  64.         root = etree.XML(urllib2.urlopen(urllib2.Request('http://predb.me/?cats='+type.lower()+'&rss=1')).read())
  65.         key = type.replace('-', '')
  66.         try:
  67.             lastpre[key]
  68.         except KeyError:
  69.             lastpre[key]= list(list(root.iter("item"))[1])[0].text
  70.         for pre in list(root.iter("item")):
  71.             pre = list(pre)
  72.             if(list(list(root.iter("item"))[0])[0].text != lastpre[key]):
  73.                 for chan in channels:
  74.                     irc.send ("PRIVMSG %s : %s \r\n" % (chan, color['gray']+" [ "+color['orange']+"PREDB"+color['gray']+" ] [ "+color['red']+type+color['gray']+" ] [ "+color['black']+pre[0].text+color['gray']+" ] [ "+color['green']+pre[1].text+color['gray']+" ] "+color['gray']))
  75.                 lastpre[key] = pre[0].text
  76.             else:
  77.                 break
  78.  
  79.  
  80.  
  81. def PrebotSEARCH(line,irc):
  82.  
  83.     id = int(3)
  84.     search = str('')
  85.     mynick = line[0].split('!')
  86.     mynick = mynick[0].replace(':', '')
  87.     while True:
  88.         id +=1
  89.         try:
  90.             search +=line[id]+" "
  91.         except:
  92.             break
  93.     irc.send ("PRIVMSG %s : %s \r\n" % (mynick, color['blue']+"Results of "+color['blue']+color['red']+search+color['red']))
  94.     root = etree.XML(urllib2.urlopen(urllib2.Request('http://predb.me/?search='+str(search[0:-1])+'&rss=1')).read())
  95.     try:
  96.         list(root.iter("item"))[0]
  97.         for pre in reversed(list(root.iter("item"))):
  98.             pre = list(pre)
  99.             irc.send ("PRIVMSG %s : %s \r\n" % (mynick, color['gray']+" [ "+color['orange']+"PREDB"+color['gray']+" ] [ "+color['blue']+"Results of "+color['red']+search[0:-1]+color['gray']+" ] [ "+color['black']+pre[0].text+color['gray']+" ] [ "+color['green']+pre[1].text+color['gray']+" ] "+color['gray']))
  100.     except:
  101.         irc.send ("PRIVMSG %s : Not found :( \r\n" % mynick)
  102.                
  103. def Management(irc,line):
  104.  
  105.     command = ''
  106.     num = int(4)
  107.     while True:
  108.         try:
  109.             command += str(line[num]+" ")
  110.             num += 1
  111.         except:
  112.             break  
  113.     irc.send("%s \r\n" % command[0:-1].replace('msg', 'PRIVMSG'))
  114.    
  115. if __name__ == '__main__':
  116.     try:
  117.         LoginIRC()
  118.     except socket.error:
  119.         threading.Timer(660, LoginIRC).start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement