Advertisement
Guest User

basic twitch bot to read gb prompts

a guest
Feb 14th, 2014
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import socket
  2. import sys, getopt
  3.  
  4. server = "irc.twitch.tv"
  5. port = "6667"
  6.  
  7. def ping(): # This is our first function! It will respond to server Pings.
  8. ircsock.send("PONG :pingis\n")
  9. def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel.
  10. ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
  11. def joinchan(chan): # This function is used to join channels.
  12. ircsock.send("JOIN "+ chan +"\n")
  13.  
  14. def main(argv):
  15. user = ''
  16. passw = ''
  17. chan = ''
  18. try:
  19. opts, args = getopt.getopt(argv,"hu:p:c:",["user=","passw=","chan="])
  20. except getopt.GetoptError:
  21. print 'irc.py -u <user> -p <passwd> -c <chan>'
  22. sys.exit(2)
  23. for opt, arg in opts:
  24. if opt == '-h':
  25. print 'irc.py -u <user> -p <passwd> -c <chan>'
  26. sys.exit()
  27. elif opt in ("-u", "--user"):
  28. user = arg
  29. elif opt in ("-p", "--passwd"):
  30. passw = arg
  31. elif opt in ("-c", "--chan"):
  32. chan = arg
  33. print 'user is "', user
  34. print 'pass is "', passw
  35. print 'chan is "', chan
  36.  
  37. ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  38. print("connecting")
  39. ircsock.connect((server, 6667))
  40. ircsock.send("PASS "+passw+"\n") # user authentication
  41. ircsock.send("NICK "+user+"\n") # here we actually assign the nick to the bot
  42. ircsock.send("JOIN "+chan+"\n")
  43. print("connected?")
  44.  
  45. while 1: # Be careful with these! it might send you to an infinite loop
  46. ircmsg = ircsock.recv(2048) # receive data from the server
  47. ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
  48. #print(ircmsg) # Here we print what's coming from the server
  49. if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond!
  50. ping()
  51. if ircmsg.find(":left") != -1:
  52. print("LEFT")
  53. if ircmsg.find(":right") != -1:
  54. print("RIGHT")
  55. if ircmsg.find(":up") != -1:
  56. print("UP")
  57. if ircmsg.find(":down") != -1:
  58. print("DOWN")
  59. if ircmsg.find(":a") != -1:
  60. print("A")
  61. if ircmsg.find(":b") != -1:
  62. print("B")
  63. if ircmsg.find(":start") != -1:
  64. print("START")
  65. if ircmsg.find(":select") != -1:
  66. print("SELECT")
  67.  
  68.  
  69. if __name__ == "__main__":
  70. main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement