Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys, getopt
- server = "irc.twitch.tv"
- port = "6667"
- def ping(): # This is our first function! It will respond to server Pings.
- ircsock.send("PONG :pingis\n")
- def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel.
- ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
- def joinchan(chan): # This function is used to join channels.
- ircsock.send("JOIN "+ chan +"\n")
- def main(argv):
- user = ''
- passw = ''
- chan = ''
- try:
- opts, args = getopt.getopt(argv,"hu:p:c:",["user=","passw=","chan="])
- except getopt.GetoptError:
- print 'irc.py -u <user> -p <passwd> -c <chan>'
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-h':
- print 'irc.py -u <user> -p <passwd> -c <chan>'
- sys.exit()
- elif opt in ("-u", "--user"):
- user = arg
- elif opt in ("-p", "--passwd"):
- passw = arg
- elif opt in ("-c", "--chan"):
- chan = arg
- print 'user is "', user
- print 'pass is "', passw
- print 'chan is "', chan
- ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- print("connecting")
- ircsock.connect((server, 6667))
- ircsock.send("PASS "+passw+"\n") # user authentication
- ircsock.send("NICK "+user+"\n") # here we actually assign the nick to the bot
- ircsock.send("JOIN "+chan+"\n")
- print("connected?")
- while 1: # Be careful with these! it might send you to an infinite loop
- ircmsg = ircsock.recv(2048) # receive data from the server
- ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
- #print(ircmsg) # Here we print what's coming from the server
- if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond!
- ping()
- if ircmsg.find(":left") != -1:
- print("LEFT")
- if ircmsg.find(":right") != -1:
- print("RIGHT")
- if ircmsg.find(":up") != -1:
- print("UP")
- if ircmsg.find(":down") != -1:
- print("DOWN")
- if ircmsg.find(":a") != -1:
- print("A")
- if ircmsg.find(":b") != -1:
- print("B")
- if ircmsg.find(":start") != -1:
- print("START")
- if ircmsg.find(":select") != -1:
- print("SELECT")
- if __name__ == "__main__":
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement