Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. import socket
  2. import string
  3. import time
  4. import calendar
  5. import re
  6. import datetime
  7. import os
  8. import urllib2
  9. import json
  10. import threading
  11. import random
  12. from random import randint
  13.  
  14. irc = dict()
  15.  
  16. server = "irc.chat.twitch.tv"
  17. port = 6667
  18. channel = "#headdome"
  19.  
  20. epoch_time = int(time.time())
  21.  
  22. nick = []
  23. password = []
  24.  
  25. #create web socket for each acc
  26. for index in range(len(nick)):
  27. irc[index] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  28.  
  29. spam = open('spam.txt').read().splitlines()
  30.  
  31. def testSpam():
  32. global sleepTime
  33. for index in range(len(nick)):
  34. msgToSend = ''.join(spam.pop(0))
  35. print "SENDING " + msgToSend
  36. irc[index].send('PRIVMSG '+ channel +' :' + " " + msgToSend + " " + ' \r\n')
  37.  
  38. #time.sleep(1.55) #The sleep delay should be 1.5 seconds divided by the amount of accounts you have
  39. time.sleep(0.200)
  40.  
  41. testSpam()
  42.  
  43. def pong():
  44. for index in range(len(nick)):
  45. irc[index].send("PONG :Pong\n")
  46. ircANN.send("PONG :Pong\n")
  47.  
  48. def get_sender(msg):
  49. "Returns the user's nick (string) that sent the message"
  50. return msg.split(":")[1].split('!')[0]
  51.  
  52. def parse_command(command):
  53. '''Returns an IRC command's components
  54. A dictionary will be filled by the data of the command, the command is as
  55. follows:
  56. :sender ACTION action_args :arguments
  57. sender(string) is the user who sent the command (only the user's nick)
  58. action(string) can be one of the following: PING, KICK, PRIVMSG, QUIT, etc.
  59. Check: http://www.irchelp.org/irchelp/rfc/chapter4.html#c4_2
  60. action_args(list of strings) depends on the ACTION, they are usually the
  61. channel or the user whom is the command for(see KICK, PRIVMSG, etc.), this
  62. will be a list and the items in the list will be the words that form the
  63. actual arguments
  64. arguments(string) depends on the ACTION
  65. eg: the command ':foo!foo@domain.tld KICK #chan user :reason' will become:
  66. sender: 'foo'
  67. action: 'KICK'
  68. action_args: ['#chan', 'user']
  69. arguments: 'reason'
  70. '''
  71. components = {
  72. 'sender' : '',
  73. 'action' : '',
  74. 'action_args' : [],
  75. 'arguments' : '',
  76.  
  77. }
  78.  
  79. if ':' == command[0]: # a user sent a command
  80. components['sender'] = get_sender(command)
  81.  
  82. space_pos = command.find(' ') + 1
  83. command = command[space_pos:]
  84. space_pos = command.find(' ')
  85.  
  86. components['action'] = command[:space_pos]
  87.  
  88. command = command[space_pos + 1:]
  89.  
  90. if ':' != command[0]: # action_args are present
  91. colon_pos = command.find(':')
  92.  
  93. if -1 == colon_pos:
  94. colon_pos = len(command)+1
  95.  
  96. components['action_args'] = command[:colon_pos-1].split()
  97. command = command[colon_pos:]
  98.  
  99. if command and ':' == command[0]: # arguments are present
  100. components['arguments'] = command[1:]
  101.  
  102. else: # the server sent a command
  103. space_pos = command.find(' ')
  104. components['action'] = command[:space_pos]
  105. components['arguments'] = command[space_pos+2:]
  106.  
  107. components['arguments'] = components['arguments'].rstrip('\r')
  108.  
  109. return components
  110.  
  111. print "Establishing connection to [%s]" % (server)
  112.  
  113. #connect on all accounts
  114. for index in range(len(nick)):
  115. irc[index].connect((server, port))
  116. irc[index].setblocking(False)
  117. irc[index].send("PASS %s\n" % (password[index]))
  118. irc[index].send("USER "+ nick[index] +" "+ nick[index] +" "+ nick[index] +" :droid\n")
  119. irc[index].send("NICK "+ nick[index] +"\n")
  120. irc[index].send("PRIVMSG nickserv :identify %s %s\r\n" % (nick[index], password[index]))
  121. irc[index].send("JOIN "+ channel +"\n")
  122. #irc[index].send("CAP REQ :twitch.tv/commands")
  123.  
  124.  
  125. readbuffer = ""
  126.  
  127. for index in range(len(nick)):
  128. irc[index].setblocking(1)
  129.  
  130.  
  131. testSpam()
  132. #just start spamming
  133.  
  134. threads = []
  135. while 1:
  136. try:
  137. ircmsg = irc[0].recv(1024).decode("UTF-8") # receive data from the server
  138. ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks
  139. print ircmsg
  140. components = parse_command(ircmsg)
  141. msg = components['sender'] + ": " + components['arguments']
  142.  
  143. #print "action component is " + components['action']
  144.  
  145. if 'PING' == components['action']:
  146. print "found PING in action, sending pong!"
  147. pong()
  148.  
  149.  
  150. except socket.error:
  151. print("Socket died.. RIP")
  152.  
  153. except socket.timeout:
  154. print("Socket timeout")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement