Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.13 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 = 10
  8. threemin = 180
  9. begintime = 0
  10. used = {}
  11. jdnamelst = list()
  12. jdsongdict = {}
  13. count = 0
  14. ### Options (Don't edit)
  15. SERVER = "irc.twitch.tv" # server
  16. PORT = 6667 # port
  17. ### Options (Edit this)
  18. PASS = "" # bot password can be found on https://twitchapps.com/tmi/
  19. BOT = "twerkrobot" # Bot's name [NO CAPITALS]
  20. CHANNEL = "littlesiha" # Channal name [NO CAPITALS]
  21. OWNER = "criogenesis" # Owner's name [NO CAPITALS]
  22. MOD = ['criogenesis', 'kompakt', 'dustyn', 'brosephstalin', 'littlesiha', 'unicorn_pudding', 'sammyy']
  23. # moderator names [NO CAPITALS]
  24.  
  25. ################################# Request Features ##################################
  26. ############ Here is where code goes when concerning song requests ############
  27. ############################################################################
  28. import re
  29. justdancelst = list()
  30. jdlstcomplete = list()
  31. justdanceun = 'Just dance unlimited.txt'
  32. jh = open(justdanceun)
  33. for line in jh:
  34. obj = "\'\'\[\[(.*?)\]\]\'\'"
  35. obj2 = "\[\'(.*?)\'\]"
  36. parsedata = re.findall(obj, line)
  37. if len(parsedata) < 1:
  38. continue
  39. else:
  40. justdancelst.append(parsedata)
  41.  
  42. justdancelststr = str(justdancelst)[1:-1]
  43. #print(justdancelststr)
  44. parsestr = re.findall(obj2, justdancelststr)
  45. #print(parsestr)
  46.  
  47. ### Functions
  48.  
  49. def sendMessage(s, message):
  50. messageTemp = "PRIVMSG #" + CHANNEL + " :" + message
  51. print(messageTemp)
  52. s.send((messageTemp + "\r\n").encode())
  53.  
  54. def getUser(line):
  55. separate = line.split(":", 2)
  56. user = separate[1].split("!", 1)[0]
  57. return user
  58. def getMessage(line):
  59. #print(line)
  60. global message
  61. try:
  62. #lined = line.decode('utf-8')
  63. #print(lined)
  64. message = (line.split(":", 2))[2]
  65. #print('test1')
  66.  
  67. except:
  68.  
  69. message = ""
  70. #print('test2')
  71. return message.lower()
  72. def joinchat():
  73. readbuffer_join = "".encode()
  74. Loading = True
  75. while Loading:
  76. readbuffer_join = s.recv(1024)
  77. readbuffer_join = readbuffer_join.decode()
  78. temp = readbuffer_join.split("\n")
  79. readbuffer_join = readbuffer_join.encode()
  80. readbuffer_join = temp.pop()
  81. for line in temp:
  82. Loading = loadingCompleted(line)
  83. #sendMessage(s, "Chat room joined!")
  84. print("Bot has joined " + CHANNEL + " Channel!")
  85.  
  86. def loadingCompleted(line):
  87. if ("End of /NAMES list" in line):
  88. return False
  89. else:
  90. return True
  91.  
  92. def call_command(command):
  93. print('Calling command `%s`.' % command)
  94.  
  95. def cooldown(command):
  96. print('You have used command `%s` in the last %u seconds.' % (command, min_call_freq))
  97.  
  98. def process_commandfive(command):
  99. if command not in used:
  100. used[command] = time.time() - min_call_freq
  101.  
  102. if time.time() - used[command] < min_call_freq:
  103. return False
  104. else:
  105. used[command] = time.time()
  106. return True
  107. def process_command3min(command):
  108. if command not in used:
  109. used[command] = time.time() - threemin
  110.  
  111. if time.time() - used[command] < threemin:
  112. return False
  113. else:
  114. used[command] = time.time()
  115. return True
  116. def jdusercheck(user):
  117. if user not in jdnamelst:
  118. jdnamelst.append(user)
  119. print('test 1')
  120. return True
  121. else:
  122. return False
  123. print('test 2')
  124. def jdsongcheck(song):
  125. if song in parsestr:
  126. count = count + 1
  127. jdsongdict[song] = count
  128. print('song added')
  129. print(jdsongdict)
  130.  
  131.  
  132.  
  133. ### Code runs
  134. s_prep = socket.socket()
  135. s_prep.connect((SERVER, PORT))
  136. s_prep.send(("PASS " + PASS + "\r\n").encode())
  137. s_prep.send(("NICK " + BOT + "\r\n").encode())
  138. s_prep.send(("JOIN #" + CHANNEL + "\r\n").encode())
  139. s = s_prep
  140. joinchat()
  141. readbuffer = ""
  142.  
  143. def Console(line):
  144. # gets if it is a user or twitch server
  145. if "PRIVMSG" in line:
  146. return False
  147. else:
  148. return True
  149.  
  150.  
  151. while True:
  152. try:
  153. readbuffer = s.recv(1024)
  154. readbuffer = readbuffer.decode()
  155. temp = readbuffer.split("\n")
  156. readbuffer = readbuffer.encode()
  157. readbuffer = temp.pop()
  158. except:
  159. temp = ""
  160. for line in temp:
  161. if line == "":
  162. break
  163. # So twitch doesn't timeout the bot.
  164. if "PING" in line and Console(line):
  165. msgg = "PONG tmi.twitch.tv\r\n".encode()
  166. s.send(msgg)
  167. print(msgg)
  168. break
  169. # get user
  170. user = getUser(line)
  171. # get message send by user'
  172. #lineE = line.encode('utf-8')
  173.  
  174. message = getMessage(line)
  175.  
  176. #print(locale.getpreferredencoding())
  177. # for you to see the chat from CMD
  178. #print(user + " > " + message)
  179. # sends private msg to the user (start line)
  180. PMSG = "/w " + user + " "
  181.  
  182.  
  183.  
  184.  
  185.  
  186. ################################# Command ##################################
  187. ############ Here you can add as meny commands as you wish of ! ############
  188. ############################################################################
  189. clubquestion = "club"
  190. tbot = "twerkrobot"
  191. tbot2 = "twerkbot"
  192. dancing = "dance"
  193. twerkrequest = "twerk"
  194. wtfisthis = "wtf is this"
  195. dancepls = "dance pls"
  196. Nut = " n "
  197. makeitjingle = "make it jingle"
  198. console = "!console"
  199. boyfriend = "does she have a boyfriend"
  200. bf = "does she have a bf"
  201. sam = "who is sam"
  202.  
  203. whatistb = "!whatistbot"
  204. nosubgift = "!nosubgift"
  205. nospam = "!nospam"
  206. petname = "!name"
  207. requeston = "!requeston"
  208. requestoff = "!requestoff"
  209. case = "!case"
  210.  
  211.  
  212. #scheduleformat
  213. commandlist = ["/me If you're asking if Avery goes to clubs, the answer is no sihaShark","/me sihaButt I shall shake my posterior for you human *twerkles* sihaButt"
  214. ,"This is what we would like to call dancing, it's really fun sihaGood","Please do not tell her to dance, she will dance when she is ready sihaShark sihaREE","NUT Kreygasm",
  215. "Avery can't do that song because it includes twerking and she doesn't feel comfortable twerking so stop asking. However I am a bot so I can make twerk sihaShark",
  216. "/me If you have a big enough room, Siha recommends using the Xbox with the Kinect sihaHype (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 sihaButt and features that other consoles don't have. sihaOmg",
  217. "/me Yes, Avery has a boyfriend and his name is Sam, his channel is twitch.tv/iamsp00n sihaShark","/me Sam is her boyfriend sihaShark","scheduleformat","Twerkrobot is a handmade bot coded in Python. Criogenesis, one of our mods, made it! sihaHype", "/me Do not ask for a gifted sub even as a joke, you will be timed out as a warning and banned if you ask again sihaShark","/me Do not spam requests in chat, Avery will get to you when she can. If you spam requests we'll time you out as a warning and Ban if you continue","/me Please don't call Avery creepy names of endearment or degrading names. Calling her Littlesiha, Siha, or Avery is okay, but things like 'sexy', 'wife', 'honey', 'babe', etc. will be given a warning purge and timed out after if it continues"
  218. ,"/me Nancy Drew, you're off the case!","The Just Dance Unlimited request feature has now been started! copy and paste your desired just dance unlimited song (exactly from the wiki) and a vote will be counted to see the top two most requested songs."]
  219.  
  220.  
  221.  
  222. #if user == OWNER and "!command" in message:
  223. #sendMessage(s, "This can only be used by the owner")
  224. #break
  225. #print(type(message))
  226. if clubquestion in message and dancing in message and process_commandfive(clubquestion):
  227. sendMessage(s, commandlist[0])
  228. break
  229. if makeitjingle in message and process_commandfive(makeitjingle):
  230. sendMessage(s, "@" + user + " " + commandlist[5])
  231. break
  232. if twerkrequest in message and not tbot in message and not tbot2 in message and process_command3min(twerkrequest):
  233. sendMessage(s, commandlist[1])
  234. break
  235. if wtfisthis in message and process_commandfive(wtfisthis):
  236. sendMessage(s, "@" + user + " " + commandlist[2])
  237. break
  238. if dancepls in message and process_commandfive(dancepls):
  239. sendMessage(s, "@" + user + " " + commandlist[3])
  240. break
  241. #if Nut in message and process_commandfive(Nut):
  242. #sendMessage(s, commandlist[4])
  243. if user in MOD and console in message and process_commandfive(console):
  244. sendMessage(s, commandlist[6])
  245. break
  246. if boyfriend in message or bf in message and process_command3min(boyfriend):
  247. sendMessage(s, commandlist[7])
  248. break
  249. if sam in message and process_commandfive(boyfriend):
  250. sendMessage(s, commandlist[8])
  251. break
  252. #if schedule in message and process_command3min(schedule):
  253. sendMessage(s, commandlist[9])
  254. if user in MOD and whatistb in message and process_commandfive(whatistb):
  255. sendMessage(s, commandlist[10])
  256. break
  257. if user in MOD and nosubgift in message and process_commandfive(nosubgift):
  258. sendMessage(s, commandlist[11])
  259. break
  260. if user in MOD and nospam in message and process_commandfive(nospam):
  261. sendMessage(s, commandlist[12])
  262. break
  263. if user in MOD and petname in message and process_commandfive(petname):
  264. sendMessage(s, commandlist[13])
  265. break
  266. if user in MOD and requestoff in message and process_commandfive(requestoff):
  267. jdnamelst = list()
  268. print('Its off, list cleared')
  269. print(jdnamelst)
  270. if jdusercheck(user) and message in parsestr:
  271. jdsongcheck(message)
  272. print(jdnamelst)
  273. continue
  274. else:
  275. print('They already requested a song')
  276. print(jdnamelst)
  277. break
  278.  
  279.  
  280.  
  281. while True:
  282. if user in MOD and case in message and process_commandfive(case):
  283. count = count + 1
  284. counts = str(count)
  285. sendMessage(s, commandlist[14] + " Number of times off the case: " + counts)
  286. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement