Advertisement
Guest User

Untitled

a guest
Nov 12th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. # coding=utf-8
  2. import socket
  3. import string
  4. import time
  5.  
  6. print "RUNNING"
  7. commands = ['γεια', '!εντολές']
  8.  
  9. # Set all the variables necessary to connect to Twitch IRC
  10. HOST = "irc.twitch.tv"
  11. NICK = "teknon_my"
  12. PORT = 6667
  13. PASS = "oauth:ivjnfkclnur7cohwm3wghxpq9dvwcq"
  14. readbuffer = ""
  15. MODT = False
  16.  
  17. # Connecting to Twitch IRC by passing credentials and joining a certain channel
  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 #teknon_my \r\n")
  23.  
  24.  
  25. # Method for sending a message
  26. def send_message(old_message):
  27. new_message = "PRIVMSG #teknon_my : ΜΠΟΤ: " + old_message + "\r\n"
  28. s.send(new_message)
  29. print new_message
  30.  
  31. send_message("Μπήκα!")
  32. # send_message("Dryzon = mouni")
  33.  
  34. s.send("CAP REQ :twitch.tv/commands")
  35. time.sleep(1)
  36. s.send(".mods")
  37. time.sleep(1)
  38.  
  39. while True:
  40. readbuffer += s.recv(1024)
  41. print readbuffer
  42. temp = string.split(readbuffer, "\n")
  43. readbuffer = temp.pop()
  44.  
  45. for line in temp:
  46. # Checks whether the message is PING because its a method of Twitch to check if you're afk
  47. if line[0] == "PING":
  48. s.send("PONG %s\r\n" % line[1])
  49. else:
  50. # Splits the given string so we can work with it better
  51. parts = string.split(line, ":")
  52.  
  53. if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
  54. try:
  55. # Sets the message variable to the actual message sent
  56. message = parts[2][:len(parts[2]) - 1]
  57. except:
  58. message = ""
  59. # Sets the username variable to the actual username
  60. usernamesplit = string.split(parts[1], "!")
  61. username = usernamesplit[0]
  62.  
  63. # Only works after twitch is done announcing stuff (MODT = Message of the day)
  64. if MODT:
  65. print username + ": " + message
  66. msg = message.lower()
  67. print msg
  68.  
  69. # You can add all your plain commands here
  70. if msg == "γεια":
  71. send_message("Καλωσήρθες, " + username)
  72. elif msg == "!εντολές":
  73. for cmd in commands:
  74. send_message(cmd)
  75.  
  76. for l in parts:
  77. if "End of /NAMES list" in l:
  78. MODT = True
  79. # print parts
  80. # time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement