/// <summary> /// Updates the application's slash commands. /// </summary> /// <param name="guildID">The ID of the guild to update slash commands in, if any.</param> /// <param name="ct">The cancellation token for this operation.</param> /// <returns>A result which may or may not have succeeded.</returns> public async Task <Result> UpdateSlashCommandsAsync ( Snowflake?guildID = null, CancellationToken ct = default ) { var getApplication = await _oauth2API.GetCurrentBotApplicationInformationAsync(ct); if (!getApplication.IsSuccess) { return(Result.FromError(getApplication)); } var application = getApplication.Entity; var createCommands = _commandTree.CreateApplicationCommands(); if (!createCommands.IsSuccess) { return(Result.FromError(createCommands)); } // Upsert the current valid command set var updateResult = await ( guildID is null ? _applicationAPI.BulkOverwriteGlobalApplicationCommandsAsync ( application.ID, createCommands.Entity, ct ) : _applicationAPI.BulkOverwriteGuildApplicationCommandsAsync ( application.ID, guildID.Value, createCommands.Entity, ct ) ); return(updateResult.IsSuccess ? Result.FromSuccess() : Result.FromError(updateResult)); }
/// <inheritdoc /> public async ValueTask <Result> CheckAsync(RequireOwnerAttribute attribute, CancellationToken ct = default) { var getApplication = await _oauth2API.GetCurrentBotApplicationInformationAsync(ct); if (!getApplication.IsSuccess) { return(Result.FromError(getApplication)); } var application = getApplication.Entity; if (application.Owner is null || !application.Owner.ID.HasValue) { return(new GenericError("The application owner's ID was not present.")); } return(application.Owner.ID.Value == _context.User.ID ? Result.FromSuccess() : new ConditionNotSatisfiedError("You need to be the bot owner to do that.")); }
/// <summary> /// Updates the application's slash commands. /// </summary> /// <param name="guildID">The ID of the guild to update slash commands in, if any.</param> /// <param name="ct">The cancellation token for this operation.</param> /// <returns>A result which may or may not have succeeded.</returns> public async Task <Result> UpdateSlashCommandsAsync ( Snowflake?guildID = null, CancellationToken ct = default ) { var getApplication = await _oauth2API.GetCurrentBotApplicationInformationAsync(ct); if (!getApplication.IsSuccess) { return(Result.FromError(getApplication)); } var application = getApplication.Entity; var createCommands = _commandTree.CreateApplicationCommands(); if (!createCommands.IsSuccess) { return(Result.FromError(createCommands)); } CreateInteractionMethods ( guildID, application, out var updateMethod, ct ); var commands = createCommands.Entity; // Upsert the current valid command set var updateCommands = await updateMethod(commands); return(updateCommands.IsSuccess ? Result.FromSuccess() : Result.FromError(updateCommands)); }
public async Task <IRemoraResult> GetLastGameAsync() { Result <IApplication> bot = await _oauth2API.GetCurrentBotApplicationInformationAsync(); if (!bot.IsSuccess || bot.Entity.Icon is null) { return(await ReplyAsync("Erreur inconnue")); } IEnumerable <GameDto> games = await _gameService.GetAllAsync(); GameDetailDto?game = await _gameService.GetAsync(games.OrderByDescending(g => g.Date).First().Id); if (game is null) { return(await ReplyAsync("Erreur inconnue")); } var fields = new List <EmbedField>() { new ("Cartes", string.Join(", ", game.Challenges.Select(c => c.MapName))), new ("Joueurs", string.Join(", ", game.Players.Select(c => c.Name))), }; var embed = new Embed( Title: game.Name, Type: EmbedType.Rich, Url: new Uri(_options.GeoNRageUrl, $"/games/{game.Id}").ToString(), Colour: System.Drawing.Color.FromArgb(0x37, 0x5a, 0x7f), Footer: new EmbedFooter("Rageux/20"), Fields: fields); Result <IMessage> reply = await _feedbackService.SendContextualEmbedAsync(embed, ct : CancellationToken); return(!reply.IsSuccess ? Result.FromError(reply) : Result.FromSuccess()); }