SHARE
TWEET

CB trivia snippet

fire219 May 24th, 2016 (edited) 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  if stringdetect(":CB trivia"):
  2.     triviakill = 0
  3.     badfile = 0
  4.     scores = dict()
  5.     triviatype = stringSplit(ircmsg, "trivia", 7)
  6.     print("Trivia type:"+triviatype)
  7.     if os.path.isfile(os.path.normpath(filelocation+'/trivia-'+triviatype)) == True:
  8.         ircsock.send("PRIVMSG "+ channel +" :Loading trivia pack "+triviatype+"!\n")
  9.         print("Loading trivia")
  10.         time.sleep(1)  
  11.         with open(os.path.normpath(filelocation+'/trivia-'+triviatype)) as triviafile:
  12.             try:
  13.                 triviapack = triviafile.read()
  14.                 print(triviapack)
  15.                 triviapack = eval(triviapack)
  16.                 trivq = triviapack.keys()
  17.                 triva = triviapack.values()
  18.                 print(trivq)
  19.                 print(triva)
  20.             except:
  21.                 ircsock.send("PRIVMSG "+ channel +" :Bad trivia file.\n")
  22.                 badfile = 1
  23.                 ircmsg = ""
  24.         if badfile == 0:       
  25.             ircsock.send("PRIVMSG "+ channel +" :Trivia mode is activated. All other bot functions will not work. Type 'CB trivia stop' to stop the game.\n")
  26.             trivcounter = 0
  27.             trivanswered = 0
  28.             for x in trivq:
  29.                 trivcounter = trivcounter + 1
  30.                 ircsock.send("PRIVMSG "+ channel +" :\x0304Question "+str(trivcounter)+": "+trivq[trivcounter - 1]+"\x03\n")
  31.                 while trivanswered == 0:
  32.                     ircmsg = ircsock.recv(2048) # receive data from the server
  33.                     ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
  34.                     print(ircmsg) # Here we print what's coming from the server
  35.                     if stringdetect(":CB trivia stop"):
  36.                         if any(word in ircmsg for word in mods):
  37.                             ircsock.send("PRIVMSG "+ channel +" :Stopping trivia game immediately.\n")
  38.                             triviakill = 1
  39.                             break
  40.                         else:
  41.                             ircsock.send("PRIVMSG "+ channel +" :You are not authorized to stop the game!\n")
  42.                     if str(triva[trivcounter - 1]).lower()  in ircmsg.lower():
  43.                         trivanswered = 1
  44.                 if triviakill == 1:
  45.                     break
  46.                 user = ircmsg[1:]
  47.                 ircmsgr = user.index("!")
  48.                 user = user[:ircmsgr]
  49.                 ircsock.send("PRIVMSG "+ channel +" :"+user+" got it right!\n")
  50.                 try:
  51.                     scores[user] = scores[user] + 1
  52.                 except:
  53.                     scores[user] = 1
  54.                 ircmsg = ""
  55.                 trivanswered = 0
  56.             ircsock.send("PRIVMSG "+ channel +" :Game over! :) \n")
  57.             ircsock.send("PRIVMSG "+ channel +" :Scores:\n")
  58.             scoresstr = str(scores)
  59.             scoresstr = scoresstr.strip("{")
  60.             scoresstr = scoresstr.strip("}")
  61.             ircsock.send("PRIVMSG "+ channel +" :"+scoresstr+"\n") 
  62.     else:
  63.         ircsock.send("PRIVMSG "+ channel +" :Trivia pack not found!\n")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top