Open kevinlul opened 3 years ago
While commands are extracted, each one should not absorb errors silently and instead provide the user some feedback. The same applies to any action conducted in direct messages.
Assert that the calling user is a host for the tournament that exists. NEW: Assert that the tournament hasn't started yet in the database.
PROCEDURE START_TOURNAMENT Assert that we have at least two players and notify the caller if not. Delete all register messages the database and then Discord. ~Eris has a bulk delete method.~ Drop all pending players from the database. Queue a task to notify them of the drop. Assign round-one byes on Challonge and then start the tournament on Challonge. REORDERED: Send a user guide to public channels. REORDERED: Send a user guide to private channels. CHANGED: drop round-one byes from Challonge. CHANGED: mark the tournament as started in the database. CHANGED: CALL NEW_ROUND
PROCEDURE NEW_ROUND NEW: Assert that the tournament is in progress. Abort all outstanding persistent timers for the tournament. Retrieve the current round number from Challonge. (NETFAIL) If we are sending direct message pairings: Retrieve pairings, snowflakes, and natural bye from Challonge. (NETFAIL) Sort the player-snowflakes in a Map by Challonge ID. For each pairing, check if both players are still in the server. If one or both are not in the server, ENQUEUE DROP_TOURNAMENT_PLAYER. If one dropped or is a round-one bye, inform the to-be opponent. Direct message the pairing to the players that are still active. Notify the private channel in the event of any direct message failures. Inform the player with the natural bye of their fortune. Create the persistent timer for this round.
PROCEDURE DROP_TOURNAMENT_PLAYER Update the database accordingly (but guildMemberRemove doesn't need this and we can batch this for NEW_ROUND) Notify private channels for the tournament about who dropped. If the tournament was in progress: Find the current pairing. If the opponent is still active, submit a score in favour of the opponent. If the opponent also dropped, update the score to a 0-0 draw. Message the opponent about the drop if still active. Remove the player from Challonge. Message the private channels.
CLASS SCORER Member: Map from Challonge match id (number) to informational object for the submitted score by one party. Instances are constructed on demand if one is missing when score-type commands are invoked . They could also additionally be constructed when a tournament starts. Scores submitted by one party are stored in the map. Scores confirmed by the other party or overridden by a host are removed from the map. Instances are destroyed when the tournament is cancelled or finished. Either scoring methods are attached to this class so we could test in isolation, or scoring logic is in commands so we just have one meaningful test for each command, and this class isn't necessary, just a map of maps.
Actually, it would make sense to drop players who left explicitly before starting the tournament. New round is out of our hands though as the command really only sends messages out.
[x] create module for messageDelete from DiscordWrapperEris (#339)
[ ] add on-demand integration tests for Challonge
[ ] add tests for events systems
In progress
Done