Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.63 KB | None | 0 0
  1. # I STOLE MOST PART FROM ELSEWHERE AND MODDED IT TO FIT MY NEEDS
  2. import os
  3. import urllib2
  4. import random
  5. import re
  6. import socket
  7. import thread
  8. import time
  9. from HTMLParser import HTMLParser
  10. from Tkinter import Tk
  11.  
  12.  
  13. #-- IRC Setup --#
  14.  
  15. def sendmsg(msg, channel):
  16.     irc.send ( 'PRIVMSG ' + channel + ' :' + msg + '\r\n' )
  17.  
  18. def sendcmd(cmd, data):
  19.     irc.send ( cmd + ' ' + data + '\r\n' )
  20.  
  21. def pingpong(data):
  22.     if data.find ( 'PING' ) != -1:
  23.         irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
  24.  
  25. def pongping(network, data):
  26.     sendcmd('PING', network)
  27.     if 'PING' in data:
  28.         return True
  29.         print 'Connected to ' + network
  30.     else:
  31.         return False
  32.  
  33. def rcvdata(data):
  34.     global channel
  35.  
  36.     if data.find ( 'PRIVMSG' ) != -1:
  37.         nick = data.split ( '!' ) [ 0 ].replace ( ':', '' )
  38.         message = ':'.join ( data.split ( ':' ) [ 2: ] )
  39.         print nick + ':', message.rstrip("\n\r")
  40.         if message.find ('!start') == 0:
  41.             #sendmsg("Starting senbot at " + message[7:], channel)
  42.             thread.start_new_thread(fgetse, (message[7:],))
  43.         if message.find ('!quit') == 0:
  44.             sendcmd('QUIT', message[5:])
  45.  
  46.  
  47.  
  48. #---------------#
  49.  
  50.  
  51. class getlinks(HTMLParser): #Parses html to find links
  52.     def handle_starttag(self, tag, attrs): #Handles any opening tag
  53.         global nurl
  54.         if tag == 'a': #If the tag is a link
  55.             for atr in attrs:
  56.                 if atr[0] == 'href': #Get it's href sttribute
  57.                     if atr[1][0:7] == 'http://' or atr[1][0:8] == 'https://': #Make sure it's http of https
  58.                         if random.randrange(0, 8) == 1: #There's a one in nine chance
  59.                                 nurl = atr[1] #That this it will go to this link next
  60.  
  61. class striphtml(HTMLParser): #Strips html tags from html data.  Ripped from stackoverflow
  62.     def __init__(self):
  63.         self.reset()
  64.         self.fed = []
  65.     def handle_data(self, d): #if it's data (not a tag)
  66.         self.fed.append(d) #add it to fed[].
  67.     def get_data(self): #return fed[]
  68.         return ''.join(self.fed)
  69.  
  70.  
  71. def striptags(html): #Get html without all that annoying markup!
  72.     s = striphtml() #call the parser
  73.     s.feed(html)
  74.     return s.get_data() #Get the data
  75.  
  76. def getse(text): #Gets a sentence form 'text'
  77.     sens = re.findall(r'[A-Z][A-Za-z ,]+[!.?]', text) #Starts with a capital, has 1 or more letters, commas, or spaces, and ends in a !, . , or ?
  78.     if len(sens) != 0: #If the
  79.         rtn = sens[len(sens)-random.randrange(0, len(sens))]
  80.         if len(rtn) > 20:
  81.             return rtn
  82.  
  83. def fgetse(surl):
  84.     global nurl
  85.     global channel
  86.     nurl = surl
  87.     user_agent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' #Set as googlebot to get access to forums/etc.
  88.     headers = { 'User-Agent' : user_agent }
  89.     while True:
  90.         try:
  91.             response = urllib2.urlopen(nurl) #Open link
  92.             html = response.read()
  93.             linkp = getlinks()
  94.             linkp.feed(html)
  95.             #print nurl
  96.             sen = getse(striptags(html))
  97.             if sen != None:
  98.                 print 'Wrote: ' + sen
  99.                 sendmsg(sen, channel)
  100.         except Exception,e: #Oh noes!
  101.             nurl = surl #Go back to lulzy place
  102.  
  103.  
  104. nurl = ''
  105.  
  106. network = 'irc.darkode.com'#irc.darkode.com'#raw_input('What network do you want to join?\n')
  107. channel = '#lizardsquad'#raw_input('What channel do you want to join?\n')
  108. nurl = raw_input('What website will you start spamming?')
  109. print 'Generating nick\n'
  110. nick = os.urandom(16).encode('hex')[:12] #raw_input('Name?\n')#wololo'
  111. print 'New nick: ' + nick
  112. #r = Tk()
  113. #r.withdraw()
  114. #r.clipboard_clear()
  115. #r.clipboard_append('/msg ' + nick + ' !start ' + nurl)
  116. #r.destroy()
  117. port = 6667
  118. connected = False
  119.  
  120. irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
  121. irc.connect ( ( network, port ) )
  122.  
  123. sendcmd('NICK', nick)
  124. sendcmd( 'USER', nick + ' foo bar ' + nick )
  125.  
  126. conn = False
  127.  
  128. while True:
  129.     data = irc.recv(4096)
  130.     pingpong(data)
  131.  
  132.     if connected:
  133.         if not conn:
  134.             sendcmd('PRIVMSG', 'NickServ IDENTIFY mypassword')
  135.             data = irc.recv ( 4096 )
  136.             while data.find(nick) == -1:
  137.                 time.sleep(1)
  138.             sendcmd('JOIN', channel)
  139.             sendcmd('/mode', nick + ' +B')
  140.             #sendmsg('ready!', channel)
  141.             print 'ready! nick is ' + nick
  142.             thread.start_new_thread(fgetse, (nurl,))
  143.             conn = True
  144.         else:
  145.             thread.start_new_thread(rcvdata, (data,))
  146.     else:
  147.         connected = pongping(network, data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement