Advertisement
Guest User

Untitled

a guest
Dec 6th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 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 = "passIcantshow" # bot password can be found on https://twitchapps.com/tmi/
  15. BOT = "mybotname" # Bot's name [NO CAPITALS]
  16. CHANNEL = "criogenesis" # 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. message = (line.split(":", 2))[2]
  33. except:
  34. message = ""
  35. return message
  36. def joinchat():
  37. readbuffer_join = "".encode()
  38. Loading = True
  39. while Loading:
  40. readbuffer_join = s.recv(1024)
  41. readbuffer_join = readbuffer_join.decode()
  42. temp = readbuffer_join.split("\n")
  43. readbuffer_join = readbuffer_join.encode()
  44. readbuffer_join = temp.pop()
  45. for line in temp:
  46. Loading = loadingCompleted(line)
  47. sendMessage(s, "Chat room joined!")
  48. print("Bot has joined " + CHANNEL + " Channel!")
  49.  
  50. def loadingCompleted(line):
  51. if ("End of /NAMES list" in line):
  52. return False
  53. else:
  54. return True
  55.  
  56. def call_command(command):
  57. print('Calling command `%s`.' % command)
  58.  
  59. def cooldown(command):
  60. print('You have used command `%s` in the last %u seconds.' % (command, min_call_freq))
  61.  
  62. def process_command(command):
  63. if (
  64. command not in used
  65. #time.time() - used[command] > min_call_freq
  66. ):
  67. used[command] = time.time() - min_call_freq
  68. #print(time.time() - used[command])
  69. call_command(command)
  70. print('A')
  71. elif time.time() - used[command] < min_call_freq:
  72. #used[command] = time.time()
  73. print(time.time() - used[command])
  74. print('1')
  75. cooldown(command)
  76.  
  77. else:
  78. print(time.time() - used[command])
  79. used[command] = time.time()
  80. print('2')
  81. call_command(command)
  82.  
  83. ### Code runs
  84. s_prep = socket.socket()
  85. s_prep.connect((SERVER, PORT))
  86. s_prep.send(("PASS " + PASS + "\r\n").encode())
  87. s_prep.send(("NICK " + BOT + "\r\n").encode())
  88. s_prep.send(("JOIN #" + CHANNEL + "\r\n").encode())
  89. s = s_prep
  90. joinchat()
  91. readbuffer = ""
  92.  
  93. def Console(line):
  94. # gets if it is a user or twitch server
  95. if "PRIVMSG" in line:
  96. return False
  97. else:
  98. return True
  99.  
  100.  
  101. while True:
  102. try:
  103. readbuffer = s.recv(1024)
  104. readbuffer = readbuffer.decode()
  105. temp = readbuffer.split("\n")
  106. readbuffer = readbuffer.encode()
  107. readbuffer = temp.pop()
  108. except:
  109. temp = ""
  110. for line in temp:
  111. if line == "":
  112. break
  113. # So twitch doesn't timeout the bot.
  114. if "PING" in line and Console(line):
  115. msgg = "PONG tmi.twitch.tv\r\n".encode()
  116. s.send(msgg)
  117. print(msgg)
  118. break
  119. # get user
  120. user = getUser(line)
  121. # get message send by user
  122. message = getMessage(line)
  123. # for you to see the chat from CMD
  124. print(user + " > " + message)
  125. # sends private msg to the user (start line)
  126. PMSG = "/w " + user + " "
  127.  
  128. ################################# Command ##################################
  129. ############ Here you can add as meny commands as you wish of ! ############
  130. ############################################################################
  131. clubquestion = "club"
  132. twerkrequest = "twerk"
  133. wtfisthis = "wtf is this"
  134. extreme = "extreme"
  135. Nut = " N "
  136. makeitjingle = "make it jingle"
  137.  
  138. if user == OWNER and "!command" in message:
  139. sendMessage(s, "This can only be used by the owner")
  140. break
  141. if "!private" in message:
  142. sendMessage(s, PMSG + "This is a private message send to the user")
  143. break
  144. if "!global" in message:
  145. sendMessage(s, "This is a global message send to the chat")
  146. break
  147. if "!me" in message:
  148. sendMessage(s, "/me this is a test for the slash me")
  149. print(used)
  150. break
  151. if clubquestion in message:
  152. process_command(clubquestion)
  153. print(time.time() - used[clubquestion])
  154. if time.time() - used[clubquestion] < min_call_freq:
  155. break
  156. else:
  157. sendMessage(s, "If you're asking if Avery goes to clubs, the answer is no")
  158. if twerkrequest in message:
  159. process_command(twerkrequest)
  160. if time.time() - used[twerkrequest] == begintime:
  161. sendMessage(s, "I shall shake my posterior for you human *twerkles*")
  162. if time.time() - used[twerkrequest] < min_call_freq and not begintime:
  163. break
  164. else:
  165. sendMessage(s, "I shall shake my posterior for you human *twerkles*")
  166.  
  167.  
  168. if wtfisthis in message:
  169. process_command(wtfisthis)
  170. if time.time() - used[wtfisthis] == begintime:
  171. sendMessage(s, "@" + user + " " + "This is what we would like to call dancing, it's really fun")
  172. if time.time() - used[wtfisthis] < min_call_freq and not begintime:
  173. break
  174. else:
  175. sendMessage(s, "@" + user + " " + "This is what we would like to call dancing, it's really fun")
  176. if extreme in message:
  177. process_command(extreme)
  178. if time.time() - used[extreme] == begintime:
  179. sendMessage(s, "Do you want her to die?")
  180. if time.time() - used[extreme] < min_call_freq and not begintime:
  181. break
  182. else:
  183. sendMessage(s, "Do you want her to die?")
  184.  
  185.  
  186. if Nut in message:
  187. process_command(Nut)
  188. if time.time() - used[Nut] == begintime:
  189. sendMessage(s, "NUT Kreygasm")
  190. if time.time() - used[Nut] < min_call_freq and not begintime:
  191. break
  192. else:
  193. sendMessage(s, "NUT Kreygasm")
  194.  
  195.  
  196. if makeitjingle in message:
  197. process_command(makeitjingle)
  198. if time.time() - used[makeitjingle] == begintime:
  199. 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")
  200. if time.time() - used[makeitjingle] < min_call_freq and not begintime:
  201. break
  202. else:
  203. 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")
  204.  
  205. if "skynet" in message:
  206. sendMessage(s, "yes I am skynet... boooooo")
  207. break
  208. if "bang" in message:
  209. sendMessage(s, "oh fuck, im......my splee-I mean my bolts...im dead")
  210.  
  211.  
  212.  
  213.  
  214. ############################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement