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); }
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); }
private async Task SetRostersFromRolesForSheets(string sheetsUrl, GoogleSheetsType type) { if (!(this.Context.Channel is IGuildChannel guildChannel)) { 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 {type.ToString()} scoresheet"); // TODO: Figure out an limitation story (count as export? Separate DB field?) string teamRolePrefix; using (DatabaseAction action = this.DatabaseActionFactory.Create()) { teamRolePrefix = await action.GetTeamRolePrefixAsync(this.Context.Guild.Id); } if (string.IsNullOrEmpty(teamRolePrefix)) { await this.Context.Channel.SendMessageAsync( "Couldn't export to the rosters sheet. This server is not using the team role prefix. Use !setTeamRolePrefix to set the prefix for role names to use for teams."); return; } IByRoleTeamManager teamManager = new ByRoleTeamManager(guildChannel, teamRolePrefix); IGoogleSheetsGenerator generator = this.GoogleSheetsGeneratorFactory.Create(type); IResult <string> result = await generator.TryUpdateRosters(teamManager, sheetsUri); if (!result.Success) { await this.Context.Channel.SendMessageAsync(result.ErrorMessage); return; } await this.Context.Channel.SendMessageAsync("Rosters updated."); }