SHARE
TWEET

Untitled

a guest May 22nd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import socket
  3. import re
  4.  
  5.  
  6. HOST = "irc.twitch.tv"
  7. PORT = 6667
  8. NICK = 'Anarjay'
  9. PASS = "oauth:41skqj6kas0oaruojh6lrs9tu9wnci"
  10. CHANNELS = ['#downgrade', '#supervate', '#neobugs']
  11.  
  12.  
  13. def sendReply():
  14.     searchMessage = 'TriHard'
  15.     replyMessage = 'TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard TriHard'
  16.     if searchMessage in message:
  17.         send_message(CHAN, replyMessage)
  18.  
  19.  
  20. message_counter = 2
  21.  
  22.  
  23. def send_message(chan, msg):
  24.     global message_counter
  25.     if message_counter % 2 == 0:
  26.         message_counter += 1
  27.         con.send(bytes('PRIVMSG %s :%s\r\n' % (chan, msg), 'UTF-8'))
  28.     else:
  29.         message_counter += 1
  30.         msg = msg + ' 󠀀 '
  31.         con.send(bytes('PRIVMSG %s :%s\r\n' % (chan, msg), 'UTF-8'))
  32.  
  33.  
  34. def send_pong(msg):
  35.     con.send(bytes('PONG %s\r\n' % msg, 'UTF-8'))
  36.  
  37.  
  38. def get_sender(msg):
  39.     result = ""
  40.     for char in msg:
  41.         if char == "!":
  42.             break
  43.         if char != ":":
  44.             result += char
  45.     return result
  46.  
  47.  
  48. def get_message(msg):
  49.     result = ""
  50.     i = 3
  51.     length = len(msg)
  52.     while i < length:
  53.         result += msg[i] + " "
  54.         i += 1
  55.     result = result.replace(':', '', 1)
  56.     return result
  57.  
  58.  
  59. con = socket.socket()
  60. con.connect((HOST, PORT))
  61. con.send(bytes('PASS %s\r\n' % PASS, 'UTF-8'))
  62. con.send(bytes('NICK %s\r\n' % NICK, 'UTF-8'))
  63. for channel in CHANNELS:
  64.     con.send(bytes('JOIN %s\r\n' % channel, 'UTF-8'))
  65.  
  66.  
  67. data = ''
  68. while True:
  69.     try:
  70.         data = data+con.recv(1024).decode('UTF-8', 'ignore')
  71.         data_split = re.split(r"[~\r\n]+", data)
  72.         data = data_split.pop()
  73.         for line in data_split:
  74.             line = str.rstrip(line)
  75.             line = str.split(line)
  76.             if len(line) >= 1:
  77.                 if line[0] == 'PING':
  78.                     send_pong(line[1])
  79.                 if line[1] == 'PRIVMSG':
  80.                     sender = get_sender(line[0])
  81.                     message = get_message(line)
  82.                     CHAN = line[2]
  83.                     sendReply()
  84.                     print(sender + ": " + message)
  85.     except IndexError:
  86.         print('loool')
  87.     except socket.error:
  88.         print("Socket died")
  89.     except socket.timeout:
  90.         print("Socket timeout")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top