Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 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 = "oauth:rsxogjf9zuvtqm6q5o7ujxowesw4cn" # 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.decode('utf-8')
  33. #print(lined)
  34. #message = (line.split(":", 2))[2]
  35. print('test1')
  36.  
  37. #except:
  38. lined = line.decode('utf-8)')
  39. message = (lined.split(":", 2))[2]
  40. print('test2')
  41. return message
  42. def joinchat():
  43. readbuffer_join = "".encode()
  44. Loading = True
  45. while Loading:
  46. readbuffer_join = s.recv(1024)
  47. readbuffer_join = readbuffer_join.decode()
  48. temp = readbuffer_join.split("\n")
  49. readbuffer_join = readbuffer_join.encode()
  50. readbuffer_join = temp.pop()
  51. for line in temp:
  52. Loading = loadingCompleted(line)
  53. #sendMessage(s, "Chat room joined!")
  54. print("Bot has joined " + CHANNEL + " Channel!")
  55.  
  56. def loadingCompleted(line):
  57. if ("End of /NAMES list" in line):
  58. return False
  59. else:
  60. return True
  61.  
  62. def call_command(command):
  63. print('Calling command `%s`.' % command)
  64.  
  65. def cooldown(command):
  66. print('You have used command `%s` in the last %u seconds.' % (command, min_call_freq))
  67.  
  68. def process_command(command):
  69. if command not in used:
  70. used[command] = time.time() - min_call_freq
  71.  
  72. if time.time() - used[command] < min_call_freq:
  73. return False
  74. else:
  75. used[command] = time.time()
  76. return True
  77. ### Code runs
  78. s_prep = socket.socket()
  79. s_prep.connect((SERVER, PORT))
  80. s_prep.send(("PASS " + PASS + "\r\n").encode())
  81. s_prep.send(("NICK " + BOT + "\r\n").encode())
  82. s_prep.send(("JOIN #" + CHANNEL + "\r\n").encode())
  83. s = s_prep
  84. joinchat()
  85. readbuffer = ""
  86.  
  87. def Console(line):
  88. # gets if it is a user or twitch server
  89. if "PRIVMSG" in line:
  90. return False
  91. else:
  92. return True
  93.  
  94.  
  95. while True:
  96. try:
  97. readbuffer = s.recv(1024)
  98. readbuffer = readbuffer.decode()
  99. temp = readbuffer.split("\n")
  100. readbuffer = readbuffer.encode()
  101. readbuffer = temp.pop()
  102. except:
  103. temp = ""
  104. for line in temp:
  105. if line == "":
  106. break
  107. # So twitch doesn't timeout the bot.
  108. if "PING" in line and Console(line):
  109. msgg = "PONG tmi.twitch.tv\r\n".encode()
  110. s.send(msgg)
  111. print(msgg)
  112. break
  113. # get user
  114. user = getUser(line)
  115. # get message send by user'
  116. lineE = line.encode('utf-8')
  117. message = getMessage(lineE)
  118. # for you to see the chat from CMD
  119. print(user + " > " + message)
  120. # sends private msg to the user (start line)
  121. PMSG = "/w " + user + " "
  122.  
  123. ################################# Command ##################################
  124. ############ Here you can add as meny commands as you wish of ! ############
  125. ############################################################################
  126. clubquestion = "club"
  127. dancing = "dance"
  128. twerkrequest = "twerk"
  129. wtfisthis = "wtf is this"
  130. extreme = "extreme"
  131. Nut = " N "
  132. makeitjingle = "make it jingle"
  133. console = "!console"
  134.  
  135. #if user == OWNER and "!command" in message:
  136. #sendMessage(s, "This can only be used by the owner")
  137. #break
  138. print(type(message))
  139. if clubquestion and dancing in message and process_command(clubquestion):
  140. sendMessage(s, "/me If you're asking if Avery goes to clubs, the answer is no")
  141. if twerkrequest in message and process_command(twerkrequest):
  142. sendMessage(s, "/me I shall shake my posterior for you human *twerkles*")
  143. if wtfisthis in message and process_command(wtfisthis):
  144. sendMessage(s, "@" + user + " " + "This is what we would like to call dancing, it's really fun")
  145. if extreme in message and process_command(extreme):
  146. sendMessage(s, "/me Do you want her to die?")
  147. if Nut in message and process_command(Nut):
  148. sendMessage(s, "NUT Kreygasm")
  149. if makeitjingle in message and process_command(makeitjingle):
  150. 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")
  151. if console in message and process_command(console):
  152. 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.")
  153. ############################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement