Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def outputResults(mentionPlayers):
- """Outputs the results from the race
- Results format: 1. racerName racerTime racerComments
- racerTime can also be 'Forfeited' if the racer did not finish the race.
- racerTime and racerComments can be empty if the racer did not set an
- end status on the race. Also outputs results in the same format to a textfile
- in comma-delimited rows (with the comments on new lines).
- """
- racerNotFinished = {}
- racerForfeited = {}
- racerDone = {}
- for racer in racerDict:
- if racerDict[racer] is None:
- racerNotFinished[racer] = ''
- elif racerDict[racer] == 'Forfeited':
- racerForfeited[racer] = 'Forfeited'
- else:
- racerDone[racer] = racerDict[racer]
- sortedRacerDone = sorted(racerDone.items(), key=operator.itemgetter(1))
- if mentionPlayers:
- resultLine = '{}{}. <@{}> {} {}\n'
- else:
- resultLine = '{}{}. {} {} {}\n'
- fileLine = '{}{}.|{}|{}\n{}\n'
- resultsString = ''
- fileString = ''
- count = 1
- for racer in sortedRacerDone:
- if mentionPlayers:
- resultsString = resultLine.format(resultsString, count, racer[0].id,
- roundTime(racer[1]), racerComments[racer[0]])
- else:
- resultsString = resultLine.format(resultsString, count, trimMemberName('{}'.format(racer[0])),
- roundTime(racer[1]), racerComments[racer[0]])
- fileString = fileLine.format(fileString, count, trimMemberName('{}'.format(racer[0])),
- roundTime(racer[1]), racerComments[racer[0]])
- count += 1
- for racer in racerForfeited:
- if mentionPlayers:
- resultsString = resultLine.format(resultsString, count, racer.id, 'Forfeited', racerComments[racer])
- else:
- resultsString = resultLine.format(resultsString, count,
- trimMemberName('{}'.format(racer)), 'Forfeited', racerComments[racer])
- fileString = fileLine.format(fileString, count,
- trimMemberName('{}'.format(racer)), 'Forfeited', racerComments[racer])
- count += 1
- for racer in racerNotFinished:
- if mentionPlayers:
- resultsString = '{}{}. <@{}>\n'.format(resultsString, count, racer.id)
- else:
- resultsString = '{}{}. {}\n'.format(resultsString, count, trimMemberName('{}'.format(racer)))
- fileString = '{}{}.|{}\n'.format(fileString, count, trimMemberName('{}'.format(racer)))
- count += 1
- if resultsString:
- await bot.say('Race game: {}'.format(raceGame))
- await bot.say('Race goal: {}'.format(raceGoal))
- await bot.say('Race results:')
- await bot.say(resultsString)
- if fileString:
- raceFile = open(raceFileName, 'w+')
- raceFile.write(fileString)
- raceFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement