コード例 #1
0
        public Task SetupTournamentAsync(string tournamentName)
        {
            // It's okay not to harden this too much, because they can retry the action, and their failure doesn't
            // make anything inconsistent.
            if (string.IsNullOrEmpty(tournamentName))
            {
                this.Logger.Debug("Couldn't setup with blank name");
                return(Task.CompletedTask);
            }

            TournamentsManager manager = this.GlobalManager.GetOrAdd(this.Context.Guild.Id, CreateTournamentsManager);

            // If the tournament didn't exist before, create it now. This must be an admin user who wanted to create
            // the tournament without any other directors.
            if (!manager.TryGetTournament(tournamentName, out ITournamentState state))
            {
                manager.AddOrUpdateTournament(tournamentName, new TournamentState(
                                                  this.Context.Guild.Id, tournamentName), (name, oldState) => oldState);
            }

            if (!manager.TrySetCurrentTournament(tournamentName, out string errorMessage))
            {
                this.Logger.Debug("Error when setting up tournament: {errorMessage}", errorMessage);
                return(this.SendChannelMessage(
                           BotStrings.ErrorSettingCurrentTournament(this.Context.Guild.Name, errorMessage)));
            }

            return(this.DoReadWriteActionOnCurrentTournamentAsync(
                       currentTournament => this.UpdateStageAsync(currentTournament, TournamentStage.AddReaders)));
        }