public async Task EditCategoriaAsync(CommandContext ctx, DiscordChannel canalReactRole = null, [RemainingText] string nomeDaCategoria = null) { try { await ctx.TriggerTypingAsync(); DiscordEmbedBuilder embed = new DiscordEmbedBuilder(); if (canalReactRole == null || string.IsNullOrWhiteSpace(nomeDaCategoria)) { embed.WithAuthor("Como executar este comando:", null, Values.infoLogo) .WithColor(Program.Bot.Utilities.HelpCommandsColor()) .AddField("PC/Mobile", $"{ctx.Prefix}rr cat.edit Canal[Id] Nome[Jogos: FPS]") .WithFooter($"Comando requisitado pelo: {Program.Bot.Utilities.DiscordNick(ctx.Member)}", iconUrl: ctx.Member.AvatarUrl) .WithTimestamp(DateTime.Now); await ctx.RespondAsync(embed : embed.Build()); return; } InteractivityExtension Interact = ctx.Client.GetInteractivity(); IMongoDatabase local = Program.Bot.LocalDB; IMongoCollection <Reacts> reacts = local.GetCollection <Reacts>(Values.Mongo.reacts); IMongoCollection <Jogos> jogos = local.GetCollection <Jogos>(Values.Mongo.jogos); FilterDefinition <Reacts> filtroMenu = Builders <Reacts> .Filter.Eq(x => x.categoria, nomeDaCategoria); FilterDefinition <Jogos> filtroJogos = Builders <Jogos> .Filter.Eq(x => x.nomeDaCategoria, nomeDaCategoria); List <Reacts> listaFiltro = await(await reacts.FindAsync(filtroMenu)).ToListAsync(); if (listaFiltro.Count == 0) { embed.WithAuthor("Essa categoria não existe!", null, Values.logoUBGE) .WithColor(Program.Bot.Utilities.HelpCommandsColor()) .WithThumbnailUrl(ctx.Member.AvatarUrl) .WithDescription(":thumbsup:") .WithFooter($"Comando requisitado pelo: {Program.Bot.Utilities.DiscordNick(ctx.Member)}", iconUrl: ctx.Member.AvatarUrl) .WithTimestamp(DateTime.Now); await ctx.RespondAsync(embed : embed.Build()); return; } Reacts ultimaRespostaLista = listaFiltro.FirstOrDefault(); DiscordMessage mensagemEmbed = await canalReactRole.GetMessageAsync(ultimaRespostaLista.idDaMensagem); DiscordEmbed embedJogo = mensagemEmbed.Embeds.FirstOrDefault(); DiscordEmbedBuilder embedNovoReactRole = new DiscordEmbedBuilder(embedJogo); embed.WithAuthor($"Digite o novo título da categoria: \"{nomeDaCategoria}\"", null, Values.logoUBGE) .WithColor(Program.Bot.Utilities.RandomColorEmbed()); await ctx.RespondAsync(embed : embed.Build()); string input = await Program.Bot.Utilities.GetAnswer(Interact, ctx); embedNovoReactRole.WithAuthor(input, null, Values.logoUBGE); DiscordMessage msgEmbed = await mensagemEmbed.ModifyAsync(embed : embedNovoReactRole.Build()); await reacts.UpdateManyAsync(filtroMenu, Builders <Reacts> .Update.Set(x => x.categoria, input)); await jogos.UpdateManyAsync(filtroJogos, Builders <Jogos> .Update.Set(x => x.nomeDaCategoria, input)); Program.Bot.Utilities.ClearEmbed(embed); embed.WithAuthor("Título do embed foi modificado com sucesso!", null, Values.logoUBGE) .WithColor(Program.Bot.Utilities.RandomColorEmbed()) .WithDescription($"Novo título: \"{input}\"") .WithThumbnailUrl(ctx.Member.AvatarUrl) .WithFooter($"Comando requisitado pelo: {Program.Bot.Utilities.DiscordNick(ctx.Member)}", iconUrl: ctx.Member.AvatarUrl) .WithTimestamp(DateTime.Now); await ctx.RespondAsync(embed : embed.Build()); } catch (Exception exception) { await Program.Bot.Logger.Error(Log.TypeError.Commands, exception); } }
public async Task RemoveCargoReactRoleAsync(CommandContext ctx, DiscordChannel canalReactRole = null, DiscordEmoji emoji = null) { await ctx.TriggerTypingAsync(); new Thread(async() => { try { DiscordEmbedBuilder embed = new DiscordEmbedBuilder(); if (canalReactRole == null || emoji == null) { embed.WithColor(Program.Bot.Utilities.HelpCommandsColor()) .WithAuthor("Como executar este comando:", null, Values.infoLogo) .AddField("PC/Mobile", $"{ctx.Prefix}rr cargo.del Canal[Id] Emoji") .WithFooter($"Comando requisitado pelo: {Program.Bot.Utilities.DiscordNick(ctx.Member)}", iconUrl: ctx.Member.AvatarUrl) .WithTimestamp(DateTime.Now); await ctx.RespondAsync(embed: embed.Build()); return; } if (string.IsNullOrWhiteSpace(emoji.Url)) { embed.WithAuthor("Emoji inválido!", null, Values.infoLogo) .WithColor(Program.Bot.Utilities.RandomColorEmbed()) .WithDescription("Digite um emoji válido!") .WithFooter($"Comando requisitado pelo: {Program.Bot.Utilities.DiscordNick(ctx.Member)}", iconUrl: ctx.Member.AvatarUrl) .WithTimestamp(DateTime.Now); await ctx.RespondAsync(embed: embed.Build()); return; } IMongoDatabase local = Program.Bot.LocalDB; IMongoCollection <Jogos> jogos = local.GetCollection <Jogos>(Values.Mongo.jogos); IMongoCollection <Reacts> reacts = local.GetCollection <Reacts>(Values.Mongo.reacts); FilterDefinition <Jogos> filtroJogos = Builders <Jogos> .Filter.Eq(x => x.idDoEmoji, emoji.Id); List <Jogos> resultadoJogos = await(await jogos.FindAsync(filtroJogos)).ToListAsync(); Jogos ultimoResultadoJogo = resultadoJogos.LastOrDefault(); List <Reacts> resultadoReacts = await(await reacts.FindAsync(Builders <Reacts> .Filter.Eq(x => x.categoria, ultimoResultadoJogo.nomeDaCategoria))).ToListAsync(); Reacts ultimoResultadoReact = resultadoReacts.LastOrDefault(); if (resultadoJogos.Count != 0 && resultadoReacts.Count != 0) { DiscordMessage mensagem = await canalReactRole.GetMessageAsync(ultimoResultadoReact.idDaMensagem); DiscordEmbed embedMensagemReactRole = mensagem.Embeds.LastOrDefault(); DiscordEmbedBuilder builder = new DiscordEmbedBuilder(embedMensagemReactRole); DiscordRole cargoJogoEmbed = ctx.Guild.GetRole(ultimoResultadoJogo.idDoCargo); IReadOnlyList <DiscordUser> MembrosReacoes = await mensagem.GetReactionsAsync(emoji); string linhaMensagemEmbed = $"{emoji.ToString()} - {cargoJogoEmbed.Name}"; if (embedMensagemReactRole.Description.Contains(linhaMensagemEmbed)) { string descricaoEmbed = embedMensagemReactRole.Description; List <string> lista = descricaoEmbed.Split('\n').ToList(); lista.RemoveAt(lista.FindIndex(linha => linha.Contains(linhaMensagemEmbed))); StringBuilder strEmbedFinal = new StringBuilder(); foreach (string linha in lista) { strEmbedFinal.Append($"{linha}\n"); } builder.WithDescription(strEmbedFinal.ToString()); builder.WithAuthor(embedMensagemReactRole.Author.Name, null, Values.logoUBGE); builder.WithColor(embedMensagemReactRole.Color.Value); await mensagem.ModifyAsync(embed: builder.Build()); } await jogos.DeleteOneAsync(filtroJogos); DiscordMessage msgAguarde = await ctx.RespondAsync($"Aguarde, estou removendo as reações dos membros que está no {canalReactRole.Mention}..."); int i = 0; foreach (DiscordUser Membro in MembrosReacoes) { try { await Task.Delay(200); await mensagem.DeleteReactionAsync(emoji, Membro); } catch (Exception) { ++i; } } await msgAguarde.DeleteAsync(); if (i != 0) { await ctx.RespondAsync($"Existem **{i}** reações que não foram removidas por que os membros saíram da {ctx.Guild.Name}, por favor, remova-as manualmente. :wink:"); } embed.WithAuthor("Jogo removido!", null, Values.logoUBGE) .WithColor(Program.Bot.Utilities.RandomColorEmbed()) .WithThumbnailUrl(emoji.Url) .WithDescription($"O cargo: {cargoJogoEmbed.Mention} e a reação: {emoji.ToString()} foram removidos com sucesso!{(i != 0 ? $"\n\n{i} reações restantes para serem removidas manualmente." : string.Empty)}") .WithFooter($"Comando requisitado pelo: {Program.Bot.Utilities.DiscordNick(ctx.Member)}", iconUrl: ctx.Member.AvatarUrl) .WithTimestamp(DateTime.Now); await ctx.RespondAsync(embed: embed.Build()); } else if (resultadoReacts.Count == 0) { await ctx.RespondAsync($"{ctx.Member.Mention}, essa categoria não existe!"); } else if (resultadoJogos.Count == 0) { await ctx.RespondAsync($"{ctx.Member.Mention}, esse jogo não existe!"); } } catch (ArgumentException) { await ctx.RespondAsync($"{ctx.Member.Mention}, este emoji não foi encontrado!"); } catch (Exception exception) { await Program.Bot.Logger.Error(Log.TypeError.Commands, exception); } }).Start(); }