Advertisement
luckytyphlosion

relevant goldenslots code

Dec 1st, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.95 KB | None | 0 0
  1. reel_list = []
  2. goldenslots_flag = False
  3. delay_value = 0.2
  4. cur_delay = delay_value
  5. which_reel = 0
  6. animated_msg = None
  7. goldenslots_msg = None
  8. disable_interrupts = False
  9. goldenslots_user = None
  10.  
  11. def kill_timers():
  12.     global reel_list
  13.     for reel_object in reel_list:
  14.         reel_object.cancel()
  15.  
  16. def kill_goldenslots():
  17.     kill_timers()
  18.     botchannelobject = None
  19.     for server in client.servers:
  20.         if server.name == "PokemonSpeedruns":
  21.             for channel in server.channels:
  22.                 if channel.name == config.bot_channel:
  23.                     botchannelobject = channel
  24.                     break
  25.                    
  26.     client.send_message(channel,"Inactivity with current GoldenSlots, shutting down!")
  27.     global goldenslots_flag
  28.     goldenslots_flag = False
  29.  
  30. def cmd_goldenslots(queries,saved_message,author,taguser,checkForProfile,userNoProfile,correctcase_usernames):
  31.     global goldenslots_flag
  32.    
  33.     if goldenslots_flag:
  34.         client.send_message(saved_message.channel,"GoldenSlots is currently assisting someone.")
  35.        
  36.     global goldenslots_user
  37.     goldenslots_user = author
  38.    
  39.     num_loops = 5 #int(queries["2"])
  40.     max_slot = 17 #int(queries["1"])
  41.    
  42.     intro_msg = client.send_message(saved_message.channel,"Time to play GoldenSlots!")
  43.    
  44.     separator = " | "
  45.     all_goldenslots = []
  46.     reel_1 = []
  47.     reel_2 = []
  48.     reel_3 = []
  49.    
  50.     goldenslots_emotes = random.sample(config.emotes, 16)
  51.     for slot in range(max_slot):
  52.         temp_emotes = []
  53.         for random_emote in range(3):
  54.             temp_emotes.append(random.choice(goldenslots_emotes))
  55.        
  56.         reel_1.append(temp_emotes[0])
  57.         reel_2.append(temp_emotes[1])
  58.         reel_3.append(temp_emotes[2])
  59.        
  60.         all_goldenslots.append(temp_emotes[0] + separator + temp_emotes[1] + separator + temp_emotes[2])
  61.    
  62.     old_times = []
  63.    
  64.     initialslots = ""
  65.    
  66.     print all_goldenslots
  67.     for initial_reel in all_goldenslots[0:3]:
  68.         initialslots += initial_reel + "\r\n"
  69.    
  70.     initialslots = initialslots[:-2]
  71.    
  72.     global goldenslots_msg
  73.     goldenslots_msg = client.send_message(saved_message.channel,initialslots)
  74.    
  75.     global animated_msg
  76.     animated_msg = initialslots
  77.    
  78.     reel_1_final_emotes = []
  79.     reel_2_final_emotes = []
  80.     reel_3_final_emotes = []
  81.    
  82.     global disable_interrupts
  83.    
  84.     def goldenslots_reel_firstround(cur_slot):
  85.         global animated_msg
  86.         temp_slot = cur_slot
  87.         old_times.append([time.clock()])
  88.        
  89.         animated_msg = ((animated_msg.split("\r\n", 1))[1] + "\r\n" + all_goldenslots[cur_slot])
  90.         client.edit_message(goldenslots_msg,animated_msg)
  91.        
  92.         old_times[temp_slot-3].append(time.clock())
  93.  
  94.     def goldenslots_reel(times_index,index):
  95.         global delay_value
  96.         global cur_delay
  97.         global goldenslots_flag
  98.         global which_reel
  99.         global animated_msg
  100.         global disable_interrupts
  101.        
  102.         if goldenslots_flag:
  103.             old_times.append([time.clock()])
  104.            
  105.             if not which_reel:
  106.                 animated_msg = ((animated_msg.split("\r\n", 1))[1] + "\r\n" + all_goldenslots[index])
  107.                 client.edit_message(goldenslots_msg,animated_msg)
  108.            
  109.             elif which_reel == 1:
  110.                 if not disable_interrupts:
  111.                     disable_interrupts = True
  112.                     reel_1_final_emotes.append(reel_1[index-2])
  113.                     reel_1_final_emotes.append(reel_1[index-1])
  114.                     reel_1_final_emotes.append(reel_1[index])
  115.                    
  116.                     animated_msg = "%s | %s | %s\r\n%s | %s | %s\r\n%s | %s | %s" % (
  117.                     reel_1_final_emotes[0], reel_2[index-2], reel_3[index-2],
  118.                     reel_1_final_emotes[1], reel_2[index-1], reel_3[index-1],
  119.                     reel_1_final_emotes[2], reel_2[index],   reel_3[index]
  120.                     )
  121.                    
  122.                     client.edit_message(goldenslots_msg,animated_msg)
  123.                     which_reel += 1
  124.                     disable_interrupts = False
  125.                
  126.             elif which_reel == 2:
  127.                 animated_msg = "%s | %s | %s\r\n%s | %s | %s\r\n%s | %s | %s" % (
  128.                 reel_1_final_emotes[0], reel_2[index-2], reel_3[index-2],
  129.                 reel_1_final_emotes[1], reel_2[index-1], reel_3[index-1],
  130.                 reel_1_final_emotes[2], reel_2[index],   reel_3[index]
  131.                 )
  132.                
  133.                 client.edit_message(goldenslots_msg,animated_msg)
  134.                
  135.             elif which_reel == 3:
  136.                 if not disable_interrupts:
  137.                     disable_interrupts = True
  138.                     reel_2_final_emotes.append(reel_2[index-2])
  139.                     reel_2_final_emotes.append(reel_2[index-1])
  140.                     reel_2_final_emotes.append(reel_2[index])
  141.                    
  142.                     animated_msg = "%s | %s | %s\r\n%s | %s | %s\r\n%s | %s | %s" % (
  143.                     reel_1_final_emotes[0], reel_2_final_emotes[0], reel_3[index-2],
  144.                     reel_1_final_emotes[1], reel_2_final_emotes[1], reel_3[index-1],
  145.                     reel_1_final_emotes[2], reel_2_final_emotes[2], reel_3[index]
  146.                     )
  147.                    
  148.                     client.edit_message(goldenslots_msg,animated_msg)
  149.                     which_reel += 1
  150.                     disable_interrupts = False
  151.                
  152.             elif which_reel == 4:
  153.                 animated_msg = "%s | %s | %s\r\n%s | %s | %s\r\n%s | %s | %s" % (
  154.                 reel_1_final_emotes[0], reel_2_final_emotes[0], reel_3[index-2],
  155.                 reel_1_final_emotes[1], reel_2_final_emotes[1], reel_3[index-1],
  156.                 reel_1_final_emotes[2], reel_2_final_emotes[2], reel_3[index]
  157.                 )
  158.                
  159.                 client.edit_message(goldenslots_msg,animated_msg)          
  160.            
  161.             reel_list[index] = (threading.Timer(cur_delay, goldenslots_reel, [times_index,index]))
  162.                
  163.             reel_list[index].daemon = True
  164.             (reel_list[index]).start()
  165.                
  166.        
  167.             old_times[times_index].append(time.clock())
  168.        
  169.     def wait_for_timers():
  170.         count = 0
  171.         none_alive = False
  172.         reel_list_len = len(reel_list) - 1
  173.         while not none_alive:
  174.             if len(reel_list) == 0:
  175.                 break
  176.             for reel in reel_list:
  177.                 if reel.is_alive():
  178.                     break
  179.                 elif reel_list.index(reel) == reel_list_len:
  180.                     none_alive = True
  181.                    
  182.     global reel_list
  183.     reel_list = []
  184.    
  185.     global delay_value
  186.     global cur_delay
  187.    
  188.     for cur_slot in range(3,max_slot)
  189.         reel_list.append(threading.Timer(cur_delay, goldenslots_reel_firstround, [cur_slot]))
  190.         reel_list[cur_slot-3].daemon = True
  191.         (reel_list[cur_slot-3]).start()
  192.         cur_delay += delay_value
  193.    
  194.     wait_for_timers()
  195.    
  196.    
  197.     global which_reel
  198.     which_reel = 0
  199.    
  200.     index = 0
  201.     reel_list = []
  202.     delay_value = 0.2
  203.     cur_delay = delay_value
  204.     for i in range(max_slot):
  205.         times_index = len(old_times) + i
  206.         reel_list.append(threading.Timer(cur_delay, goldenslots_reel, [times_index,i]))
  207.         reel_list[i].daemon = True
  208.         (reel_list[i]).start()
  209.         cur_delay += delay_value
  210.    
  211.     reel_list.append(threading.Timer(30, kill_goldenslots))
  212.     reel_list[len(reel_list) - 1].daemon = True
  213.     reel_list[len(reel_list) - 1].start()
  214.    
  215.     goldenslots_flag = True
  216.     client.send_message(saved_message.channel,'Use "!reel" to stop the reels!')
  217.  
  218. def cmd_reel(queries,saved_message,author,taguser,checkForProfile,userNoProfile,correctcase_usernames):
  219.     global goldenslots_flag
  220.     global goldenslots_msg
  221.     global goldenslots_user
  222.    
  223.     if not goldenslots_flag:
  224.         client.send_message(saved_message.channel,"GoldenSlots hasn't been activated yet.")
  225.         return
  226.     elif goldenslots_user != author:
  227.         client.send_message(saved_message.channel,"Someone is currently using GoldenSlots.")
  228.         return
  229.    
  230.     global which_reel
  231.    
  232.     if which_reel == 4:
  233.         kill_timers()
  234.    
  235.         client.send_message(saved_message.channel,"GoldenSlots has been completed.")
  236.         goldenslots_flag = False
  237.    
  238.     elif which_reel == 0 or which_reel == 2:
  239.         which_reel += 1
  240.         print which_reel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement