Created
November 2, 2015 09:20
-
-
Save wision/b49975ea0c50ecce5204 to your computer and use it in GitHub Desktop.
create draft teams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def draftCreateTeams(self, nick): | |
if not self.needs_admin(nick): | |
return | |
if self._draftIsTournament(): | |
players = self.draft.get_players(self.tournamentid, 1) | |
if len(players) < 8: | |
msg = "There are not enough players for the tournament yet. Minimum number of players: 8 Currently signed up: " + str(len(players)) | |
else: | |
numberOfTeams = int(math.floor(len(players) / 4)) | |
url = '/create-teams/output/json/distributeUnranked/0/numberOfTeams/' + str(numberOfTeams) + '/players/' | |
i = 0 | |
subs = '' | |
subs_count = 0 | |
for player in players: | |
i += 1 | |
if i > numberOfTeams * 4: | |
subs += ' ' + player[0] | |
subs_count += 1 | |
else: | |
url += player[0] + '+' | |
outtext = urllib.urlopen(self.cfg['statsSite'] + url) | |
teamsData = json.load(outtext) | |
msgs = ['', '', '', ''] | |
msgs[0] = "Teams: " + str(len(teamsData[0])) + " Players: " + str(len(teamsData[1]['ranked'])) | |
self.draft.clear_team_info(self.tournamentid) | |
if len(subs) > 0: | |
msgs[0] += " Subs: " + str(subs_count) + " (" + subs + ")" | |
i = 0 | |
cnt = 0 | |
for team in teamsData[0]: | |
i += 1 | |
j = abs( cnt / 40) | |
msgs[j] += " \x02#" + str(i) + ":\x0f" | |
for player in team['players']: | |
cnt += 1 | |
msgs[j] += " " + player['name'] | |
self.draft.add_player_team(str(i), player['name'], self.tournamentid) | |
self.draft.teamsmessage = msgs | |
for msg in msgs: | |
self.connection.privmsg( self.channel, msg ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment