55
66async def start_voting (bot , channel ):
77 sd = bot .server_data [channel .id ]
8-
8+
99 if sd ['voting' ]:
1010 await bot .send_message (channel , 'Voting is already active.' )
1111 return
12-
12+
1313 round = sd ['seasons' ]['season-{}' .format (sd ['season' ])]['rounds' ]['round-{}' .format (sd ['round' ])]
1414 if len (round ['responses' ]) < 2 :
1515 await bot .send_message (channel , 'There aren\' t enough responses to start voting. You need at least 2.' )
@@ -26,23 +26,23 @@ async def start_voting(bot, channel):
2626 round ['restimer' ] = datetime .datetime .utcnow ()+ sd ['queuetimer' ]['results' ]
2727 bot .save_data ()
2828 await bot .send_message (channel , 'Voting has been activated.' )
29-
29+
3030async def do_results (bot , channel , guild , nums = '' , message = None ):
3131 sd = bot .server_data [channel .id ]
3232 round = sd ['seasons' ]['season-{}' .format (sd ['season' ])]['rounds' ]['round-{}' .format (sd ['round' ])]
33-
33+
3434 if not sd ['voting' ]:
3535 await bot .send_message (channel , 'Voting hasn\' t even started yet...' )
3636 if round ['restimer' ] != None :
3737 round ['restimer' ] = None
3838 bot .save_data ()
3939 return
40-
40+
4141 if 'season-{}' .format (sd ['season' ]) not in sd ['seasons' ]:
4242 sd ['seasons' ]['season-{}' .format (sd ['season' ])] = {}
4343 if 'round-{}' .format (sd ['round' ]) not in sd ['seasons' ]['season-{}' .format (sd ['season' ])]['rounds' ]:
4444 sd ['seasons' ]['season-{}' .format (sd ['season' ])]['rounds' ]['round-{}' .format (sd ['round' ])] = dict (templates .round ())
45-
45+
4646 voted_ons = set ()
4747 for vote in round ['votes' ]: voted_ons |= set (vote ['vote' ])
4848 if set (round ['responses' ]) != voted_ons :
@@ -56,7 +56,7 @@ async def do_results(bot, channel, guild, nums='', message=None):
5656 totals = results .count_votes (round , round ['alive' ])
5757 msg = '**Results for round {}, season {}:**' .format (sd ['round' ], sd ['season' ])
5858 if message != None :
59- await message .delete ()
59+ await message .delete ()
6060 eliminated = []
6161 living = []
6262 elim = int (0.8 * len (totals ))
@@ -79,25 +79,27 @@ async def do_results(bot, channel, guild, nums='', message=None):
7979 if votec != 1 : votest += 's'
8080 voterst = '{} voter' .format (voterc )
8181 if voterc != 1 : voterst += 's'
82-
82+
8383 await asyncio .sleep (1 )
8484 await bot .send_message (channel , '{} submitted {}.' .format (voterst , votest ))
85-
85+
8686 for msg , dead , uid , n in results .get_results (totals , elim , round ):
8787 user = guild .get_member (uid )
8888 name = ''
8989 if user is not None :
9090 name = user .mention
9191 else :
9292 name = str (uid )
93-
93+
9494 if dead :
9595 eliminated .append ((name , user ))
9696 else :
9797 living .append ((name , user ))
98-
98+
9999 await asyncio .sleep (len (totals ) - n / 2 )
100- await bot .send_message (channel ,msg .format (name ))
100+ await bot .send_message (channel , msg .format (name ))
101+
102+ # Winner/looser stuff
101103 user = guild .get_member (totals [0 ]['name' ])
102104 if user is not None :
103105 name = user .mention
@@ -106,13 +108,14 @@ async def do_results(bot, channel, guild, nums='', message=None):
106108 msg = '{}\n The winner was {}! Well done!' .format ('=' * 50 , name )
107109 await bot .send_message (channel ,msg )
108110 round ['winner' ] = user .id
109-
111+
110112 if eliminated :
111113 await bot .send_message (channel ,
112114 'Sadly though, we have to say goodbye to {}.' .format (', ' .join ([i [0 ] for i in eliminated ])))
113115 else :
114116 await bot .send_message (channel , 'You all lived on. I would say well done, but The elimination threshold was probably at 0.' )
115117 advance = False
118+
116119 # Do all the round incrementing and stuff.
117120 if len (totals ) - len (eliminated ) <= 1 :
118121 await bot .send_message (channel ,'**This season has ended! The winner was {}!**' .format (name ))
@@ -128,17 +131,17 @@ async def do_results(bot, channel, guild, nums='', message=None):
128131 if sd ['canqueue' ] and len (sd ['queue' ]) > 0 :
129132 if sd ['queuetimer' ]['prompt' ] != None :
130133 sd ['hosttimer' ] = datetime .datetime .utcnow ()+ sd ['queuetimer' ]['prompt' ]
131-
134+
132135 if 'season-{}' .format (sd ['season' ]) not in sd ['seasons' ]:#new season
133136 sd ['seasons' ]['season-{}' .format (sd ['season' ])] = {'rounds' :{}}
134137 living = []
135138 if 'round-{}' .format (sd ['round' ]) not in sd ['seasons' ]['season-{}' .format (sd ['season' ])]['rounds' ]:#new round
136139 sd ['seasons' ]['season-{}' .format (sd ['season' ])]['rounds' ]['round-{}' .format (sd ['round' ])] = dict (templates .round ())
137140 sd ['seasons' ]['season-{}' .format (sd ['season' ])]['rounds' ]['round-{}' .format (sd ['round' ])]['alive' ]= [t [1 ].id for t in living ]
138-
141+
139142 if advance :
140143 await twow_helper .next_host (bot , channel , sd )
141-
144+
142145 sd ['voting' ] = False
143-
146+
144147 bot .save_data ()
0 commit comments