Advertisement
Guest User

Untitled

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