Advertisement
Guest User

Untitled

a guest
Aug 21st, 2016
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None
  1. # imports
  2. import socket
  3. import string
  4. import random
  5.  
  6. # Config for PokeBot
  7. HOST = "irc.chat.twitch.tv"
  8. PORT = 6667
  9. NICK = "Prick"
  10. PASS = "yag:This is none of your business."
  11. CHAN = "GitGud"
  12.  
  13.  
  14. # Functions
  15.  
  16. def openSocket():
  17. # Opens the connection to Twitch IRC, and connects chosen channel with nick and password given.
  18. s = socket.socket()
  19. s.connect((HOST, PORT))
  20. s.send("PASS " + PASS + "\r\n")
  21. s.send("NICK " + NICK + "\r\n")
  22. s.send("JOIN #" + CHAN + "\r\n")
  23. return s
  24.  
  25. def sendMessage(s, message):
  26. messageTemp = "PRIVMSG #" + CHAN + " :" + message
  27. s.send(messageTemp + "\r\n")
  28. print("Erin: " + message)
  29.  
  30. def getUser(line):
  31. separate = line.split(":", 2)
  32. user = separate[1].split("!", 1)[0]
  33. return user
  34. def getMessage(line):
  35. if "PING :tmi.twitch.tv" in line:
  36. separate = line.split(":", 1)
  37. message = separate[1]
  38. return message
  39. separate = line.split(":", 2)
  40. message = separate[2]
  41. return message
  42.  
  43. def joinRoom(s):
  44. readbuffer = ""
  45. Loading = True
  46. while Loading:
  47. readbuffer = readbuffer + s.recv(1024)
  48. temp = string.split(readbuffer, "\n")
  49. readbuffer = temp.pop()
  50.  
  51. for line in temp:
  52. Loading = loadingComplete(line)
  53. sendMessage(s, "Hello!\r\n")
  54.  
  55. def loadingComplete(line):
  56. if("End of /NAMES list" in line):
  57. return False
  58. else:
  59. return True
  60.  
  61. # Initialization
  62. s = openSocket()
  63. joinRoom(s)
  64. readbuffer = ""
  65.  
  66. while True:
  67. readbuffer = readbuffer + s.recv(1024)
  68. temp = string.split(readbuffer, "\n")
  69. readbuffer = temp.pop()
  70.  
  71. for line in temp:
  72. user = getUser(line)
  73. message = getMessage(line)
  74. print user + " typed :" + message
  75. if "tmi.twitch.tv" in message:
  76. s.send("PONG :tmi.twitch.tv\r\n")
  77. if "!point @" in message:
  78. separate = line.split("@", 2)
  79. seconduser = separate[2]
  80. if "MademoiselleErin" in seconduser:
  81. sendMessage(s, "Why, @" + user + " ?" + " I didn't do anything.")
  82. sendMessage(s, "@" + user + " is pointing at " + "@" + seconduser)
  83. if "!punch" in message:
  84. sendMessage(s, "MonsieurErin punches " + "@" + user)
  85. if "!kill" in message:
  86. sendMessage(s, "I KEEL YOU " + "@" + user)
  87. if "!greet @" in message:
  88. separate = line.split("@", 2)
  89. seconduser = separate[2]
  90. sendMessage(s, "Welcome, " + "@" + seconduser + " !")
  91. if "!cheer @" in message:
  92. separate = line.split("@" , 2)
  93. seconduser = separate[2]
  94. sendMessage(s, "@" + user + " is cheering for you," + " @" + seconduser)
Advertisement
RAW Paste Data Copied
Advertisement