Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- network = "irc.twitch.tv"
- port = 6667
- default_join = ["#channel_name"]
- # twitch command functions
- def what_is_game(): # under construction
- pass
- def sellout(raw_message):
- message = ('long joke here')
- send_privmsg(raw_message.split('#')[1].split(" ")[0], message)
- # general commands
- def send_privmsg(location, message):
- irc.sendall("PRIVMSG #{0} :{1}\r\n".format(location, message))
- def echo(raw_message): # format = PRIVMSG target :message
- words_to_echo = raw_message.split(":")[2].split(" ")[1:]
- target = raw_message.split("#")[1].split(" ")[0]
- message = ''
- for word in words_to_echo:
- if word[-4:] != '\r\n':
- message += word + ' '
- else:
- message += word
- irc.send("PRIVMSG #{0} :{1}\r\n".format(target, message))
- if __name__ == "__main__":
- irc.connect((network, port))
- print irc.recv(4096)
- irc.send("PASS {0}\r\n".format("oauth:codehere")) # format() was just to see if I was doing it wrong
- irc.send("USER TwitchName 0 * :Owner - Failfixer\r\n")
- irc.send("NICK TwitchName\r\n")
- for channel in default_join:
- irc.send("JOIN "+channel+"\r\n")
- while True:
- action = ''
- data = irc.recv(4096)
- print data #for debug
- if data.find('PING') != -1:
- irc.send("PONG "+data.split()[1]+"\r\n")
- if data.find("#") != -1:
- action = data.split("#")[0].split(" ")[1]
- if action != '':
- if action == 'PRIVMSG':
- command = ''
- if data.find(":!") != -1:
- command = data.split(":")[2].split(" ")[0].strip("\r\n")
- if command == "!say":
- echo(data)
- if command == "!sellout":
- sellout(data)
Advertisement
Add Comment
Please, Sign In to add comment