コード例 #1
0
        public async Task ExportToUCSD(string sheetsUrl, int round)
        {
            if (!this.Manager.TryGet(this.Context.Channel.Id, out GameState game))
            {
                // This command only works during a game
                return;
            }

            if (!(this.Context.User is IGuildUser _))
            {
                return;
            }

            if (!(this.Context.Channel is IGuildChannel _))
            {
                return;
            }

            // This would be nicer if it was done in the scoresheet generator, but it's easier to check for here
            // If all of the scoresheets have the same type of name for the sheets, we should just pass in the round
            // number to the interface, and then do the check there
            if (round < 1 || round > 15)
            {
                await this.Context.Channel.SendMessageAsync(
                    "The round is out of range. The round number must be between 1 and 15 (inclusive).");

                return;
            }

            if (!Uri.TryCreate(sheetsUrl, UriKind.Absolute, out Uri sheetsUri))
            {
                await this.Context.Channel.SendMessageAsync(
                    "The link to the Google Sheet wasn't understandable. Be sure to copy the full URL from the address bar.");

                return;
            }

            Logger.Information($"User {this.Context.User.Id} attempting to export a UCSD scoresheet");

            (bool isBelowExportLimit, _) = await this.VerifyBelowExportLimit();

            if (!isBelowExportLimit)
            {
                return;
            }

            IGoogleSheetsGenerator generator = this.GoogleSheetsGeneratorFactory.Create(GoogleSheetsType.UCSD);
            IResult <string>       result    = await generator.TryCreateScoresheet(game, sheetsUri, round);

            if (!result.Success)
            {
                await this.Context.Channel.SendMessageAsync(result.ErrorMessage);

                return;
            }

            await this.Context.Channel.SendMessageAsync(result.Value);
        }
コード例 #2
0
        public async Task ExportToTJ(string sheetsUrl, int round)
        {
            if (!this.Manager.TryGet(this.Context.Channel.Id, out GameState game))
            {
                // This command only works during a game
                return;
            }

            if (!(this.Context.User is IGuildUser _))
            {
                return;
            }

            if (!(this.Context.Channel is IGuildChannel _))
            {
                return;
            }

            if (round < 1)
            {
                await this.Context.Channel.SendMessageAsync(
                    "The round is out of range. The round number must be at least 1.");

                return;
            }

            if (!Uri.TryCreate(sheetsUrl, UriKind.Absolute, out Uri sheetsUri))
            {
                await this.Context.Channel.SendMessageAsync(
                    "The link to the Google Sheet wasn't understandable. Be sure to copy the full URL from the address bar.");

                return;
            }

            Logger.Information($"User {this.Context.User.Id} attempting to export a TJ scoresheet");

            (bool isBelowExportLimit, _) = await this.VerifyBelowExportLimit();

            if (!isBelowExportLimit)
            {
                return;
            }

            IGoogleSheetsGenerator generator = this.GoogleSheetsGeneratorFactory.Create(GoogleSheetsType.TJ);
            IResult <string>       result    = await generator.TryCreateScoresheet(game, sheetsUri, round);

            if (!result.Success)
            {
                await this.Context.Channel.SendMessageAsync(result.ErrorMessage);

                return;
            }

            await this.Context.Channel.SendMessageAsync(result.Value);
        }