Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import re
- HOST = "irc.twitch.tv"
- PORT = 6667
- NICK = 'massivly'
- PASS = ""
- CHANNELS = ['#downgrade']
- def send_message(chan, msg):
- global message_counter
- if message_counter % 2 == 0:
- message_counter += 1
- con.send(bytes('PRIVMSG %s :%s\r\n' % (chan, msg), 'UTF-8'))
- else:
- message_counter += 1
- msg = msg + ' '
- con.send(bytes('PRIVMSG %s :%s\r\n' % (chan, msg), 'UTF-8'))
- def send_pong(msg):
- con.send(bytes('PONG %s\r\n' % msg, 'UTF-8'))
- def get_sender(msg):
- result = ""
- for char in msg:
- if char == "!":
- break
- if char != ":":
- result += char
- return result
- def get_message(msg):
- result = ""
- i = 3
- length = len(msg)
- while i < length:
- result += msg[i] + " "
- i += 1
- result = result.replace(':', '', 1)
- return result
- con = socket.socket()
- con.connect((HOST, PORT))
- con.send(bytes('PASS %s\r\n' % PASS, 'UTF-8'))
- con.send(bytes('NICK %s\r\n' % NICK, 'UTF-8'))
- for channel in CHANNELS:
- con.send(bytes('JOIN %s\r\n' % channel, 'UTF-8'))
- data = ''
- while True:
- try:
- data = data+con.recv(1024).decode('UTF-8', 'ignore')
- data_split = re.split(r"[~\r\n]+", data)
- data = data_split.pop()
- for line in data_split:
- line = str.rstrip(line)
- line = str.split(line)
- if len(line) >= 1:
- if line[0] == 'PING':
- send_pong(line[1])
- if line[1] == 'PRIVMSG':
- sender = get_sender(line[0])
- message = get_message(line)
- CHAN = line[2]
- print(sender + ": " + message)
- except IndexError:
- print('loool')
- except socket.error:
- print("Socket died")
- except socket.timeout:
- print("Socket timeout")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement