Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. ### The only import you need!
  2. import socket
  3. import time
  4.  
  5. ### Cooldown variables
  6. min_call_freq = 5
  7. begintime = 0
  8. used = {}
  9.  
  10. ### Options (Don't edit)
  11. SERVER = "irc.twitch.tv" # server
  12. PORT = 6667 # port
  13. ### Options (Edit this)
  14. PASS = "secretkeything" # bot password can be found on https://twitchapps.com/tmi/
  15. BOT = "twerkrobot" # Bot's name [NO CAPITALS]
  16. CHANNEL = "littlesiha" # Channal name [NO CAPITALS]
  17. OWNER = "criogenesis" # Owner's name [NO CAPITALS]
  18.  
  19. ### Functions
  20.  
  21. def sendMessage(s, message):
  22. messageTemp = "PRIVMSG #" + CHANNEL + " :" + message
  23. s.send((messageTemp + "\r\n").encode())
  24.  
  25. def getUser(line):
  26. separate = line.split(":", 2)
  27. user = separate[1].split("!", 1)[0]
  28. return user
  29. def getMessage(line):
  30. global message
  31. #try:
  32. lined = line.encode('utf-8')
  33. #print(lined)
  34. message = (lined.split(":", 2))[2]
  35.  
  36. #except:
  37. #message = ""
  38. return message
  39. def joinchat():
  40. readbuffer_join = "".encode()
  41. Loading = True
  42. while Loading:
  43. readbuffer_join = s.recv(1024)
  44. readbuffer_join = readbuffer_join.decode()
  45. temp = readbuffer_join.split("\n")
  46. readbuffer_join = readbuffer_join.encode()
  47. readbuffer_join = temp.pop()
  48. for line in temp:
  49. Loading = loadingCompleted(line)
  50. #sendMessage(s, "Chat room joined!")
  51. print("Bot has joined " + CHANNEL + " Channel!")
  52.  
  53. def loadingCompleted(line):
  54. if ("End of /NAMES list" in line):
  55. return False
  56. else:
  57. return True
  58.  
  59. def call_command(command):
  60. print('Calling command `%s`.' % command)
  61.  
  62. def cooldown(command):
  63. print('You have used command `%s` in the last %u seconds.' % (command, min_call_freq))
  64.  
  65. def process_command(command):
  66. if command not in used:
  67. used[command] = time.time() - min_call_freq
  68.  
  69. if time.time() - used[command] < min_call_freq:
  70. return False
  71. else:
  72. used[command] = time.time()
  73. return True
  74. ### Code runs
  75. s_prep = socket.socket()
  76. s_prep.connect((SERVER, PORT))
  77. s_prep.send(("PASS " + PASS + "\r\n").encode())
  78. s_prep.send(("NICK " + BOT + "\r\n").encode())
  79. s_prep.send(("JOIN #" + CHANNEL + "\r\n").encode())
  80. s = s_prep
  81. joinchat()
  82. readbuffer = ""
  83.  
  84. def Console(line):
  85. # gets if it is a user or twitch server
  86. if "PRIVMSG" in line:
  87. return False
  88. else:
  89. return True
  90.  
  91.  
  92. while True:
  93. try:
  94. readbuffer = s.recv(1024)
  95. readbuffer = readbuffer.decode()
  96. temp = readbuffer.split("\n")
  97. readbuffer = readbuffer.encode()
  98. readbuffer = temp.pop()
  99. except:
  100. temp = ""
  101. for line in temp:
  102. if line == "":
  103. break
  104. # So twitch doesn't timeout the bot.
  105. if "PING" in line and Console(line):
  106. msgg = "PONG tmi.twitch.tv\r\n".encode()
  107. s.send(msgg)
  108. print(msgg)
  109. break
  110. # get user
  111. user = getUser(line)
  112. # get message send by user'
  113.  
  114. message = getMessage(line)
  115. # for you to see the chat from CMD
  116. print(user + " > " + message)
  117. # sends private msg to the user (start line)
  118. PMSG = "/w " + user + " "
  119.  
  120. ################################# Command ##################################
  121. ############ Here you can add as meny commands as you wish of ! ############
  122. ############################################################################
  123. clubquestion = "club"
  124. dancing = "dance"
  125. twerkrequest = "twerk"
  126. wtfisthis = "wtf is this"
  127. extreme = "extreme"
  128. Nut = " N "
  129. makeitjingle = "make it jingle"
  130. console = "!console"
  131.  
  132. #if user == OWNER and "!command" in message:
  133. #sendMessage(s, "This can only be used by the owner")
  134. #break
  135. print(type(message))
  136. if clubquestion and dancing in message and process_command(clubquestion):
  137. sendMessage(s, "/me If you're asking if Avery goes to clubs, the answer is no")
  138. if twerkrequest in message and process_command(twerkrequest):
  139. sendMessage(s, "/me I shall shake my posterior for you human *twerkles*")
  140. if wtfisthis in message and process_command(wtfisthis):
  141. sendMessage(s, "@" + user + " " + "This is what we would like to call dancing, it's really fun")
  142. if extreme in message and process_command(extreme):
  143. sendMessage(s, "/me Do you want her to die?")
  144. if Nut in message and process_command(Nut):
  145. sendMessage(s, "NUT Kreygasm")
  146. if makeitjingle in message and process_command(makeitjingle):
  147. sendMessage(s, "@" + user + " " + "Avery can't do that song because it includes twerking and that is against TOS. However I am a bot so I can make twerk")
  148. if console in message and process_command(console):
  149. sendMessage(s, "/me If you have a big enough room, Siha recommends using the Xbox with the Kinect (but keep in mind, the Kinect has been discontinued.) If you don't have a lot of space, the Switch version is great and has bonus choreographies and features that other consoles don't have.")
  150. ############################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement