Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.19 KB | None | 0 0
  1. ### The only import you need!
  2. import socket
  3. import time
  4. import random
  5. ### Cooldown variables
  6. min_call_freq = 10
  7. threemin = 180
  8. begintime = 0
  9. used = {}
  10. jdnamelst = list()
  11. jdsongdict = {}
  12. count = 0
  13. acceptingrequest = None
  14. acceptingrandom = None
  15. randomdict = {}
  16. ### Options (Don't edit)
  17. SERVER = "irc.twitch.tv" # server
  18. PORT = 6667 # port
  19. ### Options (Edit this)
  20. PASS = "" # bot password can be found on https://twitchapps.com/tmi/
  21. BOT = "" # Bot's name [NO CAPITALS]
  22. CHANNEL = "" # Channal name [NO CAPITALS]
  23. OWNER = "" # Owner's name [NO CAPITALS]
  24. MOD = []
  25. # moderator names [NO CAPITALS]
  26.  
  27.  
  28. ################################# Request Features ##################################
  29. ############ Here is where code goes when concerning song requests ############
  30. ############################################################################
  31. import re
  32. justdancelst = list()
  33. jdlstcomplete = list()
  34. justdanceun = 'Just dance unlimited.txt'
  35. jh = open(justdanceun)
  36. for line in jh:
  37. obj = "\'\'\[\[(.*?)\]\]\'\'"
  38. obj2 = "\[\'(.*?)\'\]"
  39. parsedata = re.findall(obj, line)
  40. if len(parsedata) < 1:
  41. continue
  42. else:
  43. justdancelst.append(parsedata)
  44.  
  45. justdancelststr = str(justdancelst)[1:-1]
  46. #print(justdancelststr)
  47. parsestr = re.findall(obj2, justdancelststr)
  48. parsestrlower = [i.lower() for i in parsestr]
  49. def remove_duplicates(parsestrlower):
  50. output = []
  51. seen = set()
  52. for value in parsestrlower:
  53. if value not in seen:
  54. output.append(value)
  55. seen.add(value)
  56. return output
  57. parseunique = remove_duplicates(parsestrlower)
  58.  
  59.  
  60. ### Functions
  61.  
  62. def sendMessage(s, message):
  63. messageTemp = "PRIVMSG #" + CHANNEL + " :" + message
  64. print(messageTemp)
  65. s.send((messageTemp + "\r\n").encode())
  66.  
  67. def getUser(line):
  68. separate = line.split(":", 2)
  69. user = separate[1].split("!", 1)[0]
  70. return user
  71. def getMessage(line):
  72. #print(line)
  73. global message
  74. try:
  75. #lined = line.decode('utf-8')
  76. #print(lined)
  77. message = (line.split(":", 2))[2]
  78. #print('test1')
  79.  
  80. except:
  81.  
  82. message = ""
  83. #print('test2')
  84. return message.lower()
  85. def joinchat():
  86. readbuffer_join = "".encode()
  87. Loading = True
  88. while Loading:
  89. readbuffer_join = s.recv(1024)
  90. readbuffer_join = readbuffer_join.decode()
  91. temp = readbuffer_join.split("\n")
  92. readbuffer_join = readbuffer_join.encode()
  93. readbuffer_join = temp.pop()
  94. for line in temp:
  95. Loading = loadingCompleted(line)
  96. #sendMessage(s, "Chat room joined!")
  97. print("Bot has joined " + CHANNEL + " Channel!")
  98.  
  99. def loadingCompleted(line):
  100. if ("End of /NAMES list" in line):
  101. return False
  102. else:
  103. return True
  104.  
  105. def call_command(command):
  106. print('Calling command `%s`.' % command)
  107.  
  108. def cooldown(command):
  109. print('You have used command `%s` in the last %u seconds.' % (command, min_call_freq))
  110.  
  111. def process_commandfive(command):
  112. if command not in used:
  113. used[command] = time.time() - min_call_freq
  114.  
  115. if time.time() - used[command] < min_call_freq:
  116. return False
  117. else:
  118. used[command] = time.time()
  119. return True
  120. def process_command3min(command):
  121. if command not in used:
  122. used[command] = time.time() - threemin
  123.  
  124. if time.time() - used[command] < threemin:
  125. return False
  126. else:
  127. used[command] = time.time()
  128. return True
  129. def jdusercheck(user):
  130. if user not in jdnamelst:
  131. jdnamelst.append(user)
  132. print('test 1')
  133. return True
  134. else:
  135. #print('test 22')
  136. return False
  137.  
  138. def jdsongcheck(i):
  139. global count
  140. if i not in jdsongdict:
  141. jdsongdict[i] = 1
  142. print('song initialized')
  143. else:
  144. jdsongdict[i] += 1
  145. print('song added')
  146. print(jdsongdict)
  147. def randomcheck(x):
  148. global count
  149. if x not in randomdict:
  150. randomdict[x] = 1
  151. print(randomdict)
  152. else:
  153. randomdict[x] += 1
  154. print('vote counted')
  155. print(randomdict)
  156.  
  157. ### Code runs
  158. s_prep = socket.socket()
  159. s_prep.connect((SERVER, PORT))
  160. s_prep.send(("PASS " + PASS + "\r\n").encode())
  161. s_prep.send(("NICK " + BOT + "\r\n").encode())
  162. s_prep.send(("JOIN #" + CHANNEL + "\r\n").encode())
  163. s = s_prep
  164. joinchat()
  165. readbuffer = ""
  166.  
  167. def Console(line):
  168. # gets if it is a user or twitch server
  169. if "PRIVMSG" in line:
  170. return False
  171. else:
  172. return True
  173.  
  174.  
  175. while True:
  176. try:
  177. readbuffer = s.recv(1024)
  178. readbuffer = readbuffer.decode()
  179. temp = readbuffer.split("\n")
  180. readbuffer = readbuffer.encode()
  181. readbuffer = temp.pop()
  182. except:
  183. temp = ""
  184. for line in temp:
  185. if line == "":
  186. break
  187. # So twitch doesn't timeout the bot.
  188. if "PING" in line and Console(line):
  189. msgg = "PONG tmi.twitch.tv\r\n".encode()
  190. s.send(msgg)
  191. print(msgg)
  192. break
  193. # get user
  194. user = getUser(line)
  195. # get message send by user'
  196. #lineE = line.encode('utf-8')
  197.  
  198. message = getMessage(line)
  199. print(message)
  200. #print(type(message))
  201. #print(locale.getpreferredencoding())
  202. # for you to see the chat from CMD
  203. #print(user + " > " + message)
  204. # sends private msg to the user (start line)
  205. PMSG = "/w " + user + " "
  206.  
  207.  
  208.  
  209.  
  210.  
  211. ################################# Command ##################################
  212. ############ Here you can add as meny commands as you wish of ! ############
  213. ############################################################################
  214.  
  215.  
  216. clubquestion = "club"
  217. tbot = "twerkrobot"
  218. tbot2 = "twerkbot"
  219. dancing = "dance"
  220. twerkrequest = "twerk"
  221. boyfriend = "does she have a boyfriend"
  222. bf = "does she have a bf"
  223. sr = "!sr"
  224. requeston = "!requeston"
  225. requestoff = "!requestoff"
  226. case = "!case"
  227. songclear = "!songclear"
  228. randomsongon = "!randomsongon"
  229. randomsongoff = "!randomsongoff"
  230. vote = "!vote"
  231. one = "1"
  232. two = "2"
  233. slur1 = "nigg"
  234. slur2 = "nibba"
  235. unlimitedlst = [s.replace("’", '') for s in parseunique]
  236. #print(unlimitedlst)
  237. songchoice1 = random.choice(unlimitedlst)
  238. songchoice2 = random.choice(unlimitedlst)
  239.  
  240.  
  241.  
  242. 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","/me Yes, Avery has a boyfriend and his name is Sam, his channel is twitch.tv/iamsp00n sihaShark","/me Nancy Drew, you're off the case!",
  243. "/me The Just Dance Unlimited request feature has now been started! copy and paste your desired just dance unlimited song (exactly from the wiki). Requests are read as follows: !sr songname. A vote will be counted to see the top requested song.",
  244. "/me @littlesiha The results have been tallied, the winner of the song request is: ",
  245. "Stop triggering this command you fuck",("/me The random request feature is now live, if you would like to see Avery dance to either"
  246. + " (" + songchoice1 + ") " + "or" + " (" + songchoice2 + ") " + "type !vote 1 for" + " (" + songchoice1 + "), " + "or type !vote 2 for"+ " (" + songchoice2 + ") " +
  247. "in chat"),"nigg","nibba"]
  248. for triggerlst, triggerlstre in zip(["wtf is this","dance pls","make it jingle","who is sam"],
  249. ["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",
  250. "Avery doesn't feel comfortable twerking on stream. Sorry! However, I am a bot, so I can make twerk for you. sihaShark","Sam is her boyfriend sihaShark"]):
  251. if triggerlst in message and process_commandfive(triggerlst):
  252. sendMessage(s, "@" + user + " " + triggerlstre)
  253. break
  254.  
  255. for executelst, executelstre in zip(["!console","!whatistbot","!nosubgift","!nospam","!name","!nobackseat"],
  256. ["/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",
  257. "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",
  258. "/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",
  259. "/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",
  260. "/me Please do not backseat or provide solutions to puzzles unless Avery specifically asks for help from the chat. You will be purged as a warning and then timed out if you continue."]):
  261. if executelst in message and process_commandfive(executelst):
  262. sendMessage(s, executelstre)
  263. break
  264.  
  265. if user == "dustyn" and "wtf is this" in message and process_commandfive("wtf is this"):
  266. sendMessage(s, "@" + user + " " + commandlist[6])
  267. break
  268. if slur1 in message or slur2 in message:
  269. sendMessage(s, "/timeout " + user)
  270. break
  271. if clubquestion in message and dancing in message and process_commandfive(clubquestion):
  272. sendMessage(s, commandlist[0])
  273. break
  274. if twerkrequest in message and not tbot in message and not tbot2 in message and process_command3min(twerkrequest):
  275. sendMessage(s, commandlist[1])
  276. break
  277. if boyfriend in message or bf in message and process_command3min(boyfriend):
  278. sendMessage(s, commandlist[2])
  279. break
  280. if user in MOD and songclear in message and process_commandfive(requestoff):
  281. jdsongdict.clear()
  282. print('Its off, list cleared')
  283. print(jdsongdict)
  284. break
  285. if user in MOD and requeston in message and process_commandfive(requeston):
  286. acceptingrequest = True
  287. sendMessage(s, commandlist[4])
  288. print('feature is on')
  289. if user in MOD and randomsongon in message and process_commandfive(randomsongon):
  290. acceptingrandom = True
  291. sendMessage(s, commandlist[7])
  292. randomlstdict = {songchoice1:"1",songchoice2:"2"}
  293. print(randomlstdict)
  294. print(randomdict)
  295. #sendMessage(s, songchoice1 + " " + "," + songchoice2)
  296. if "list check" in message:
  297. print('They already requested a song')
  298. print(jdnamelst)
  299. print(jdsongdict)
  300. #print(randomlst)
  301. print(randomdict)
  302. break
  303.  
  304. while True:
  305. if acceptingrandom == True:
  306. for x,y in randomlstdict.items():
  307. if y in message and vote in message and jdusercheck(user):
  308. randomcheck(x)
  309. print('in it')
  310. break
  311. #break
  312. try:
  313. if user in MOD and randomsongoff in message and process_commandfive(randomsongoff):
  314. acceptingrandom = False
  315. winningrandom = max(randomdict, key=randomdict.get)
  316. randomdict.clear()
  317. del jdnamelst[:]
  318. #del randomlst[:]
  319. sendMessage(s, commandlist[5] + winningrandom)
  320. print('Its off, list cleared')
  321. print(randomdict)
  322. print(randomlstdict)
  323. #print('aaaaaaaaah')
  324. break
  325. else:
  326. #print('blahblah')
  327. break
  328. except:
  329. #print('going here')
  330. break
  331.  
  332. while True:
  333. if acceptingrequest == True:
  334. #print('test')
  335. for i in unlimitedlst:
  336. if i in message and sr in message and jdusercheck(user):
  337. jdsongcheck(i)
  338. print('in it')
  339. break
  340. try:
  341. if user in MOD and requestoff in message and process_commandfive(requestoff):
  342. winningsong = max(jdsongdict, key=jdsongdict.get)
  343. acceptingrequest = False
  344. del jdnamelst[:]
  345. jdsongdict.clear()
  346. sendMessage(s, commandlist[5] + winningsong)
  347. print('Its off, list cleared')
  348. print(jdnamelst)
  349. print(jdsongdict)
  350. break
  351. else:
  352. #print('leaving loop')
  353. break
  354. except:
  355. break
  356.  
  357.  
  358. while True:
  359. if user in MOD and case in message and process_commandfive(case):
  360. count = count + 1
  361. counts = str(count)
  362. sendMessage(s, commandlist[3] + " Number of times off the case: " + counts)
  363. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement