public async ValueTask <AdminCommandResult> DeconstructMessageAsync(RestUserMessage jumpLink)
        {
            JsonEmbed embed;

            if (jumpLink.Embeds.FirstOrDefault() is { } messageEmbed)
            {
                embed = new JsonEmbed(jumpLink.Content, LocalEmbedBuilder.FromEmbed(messageEmbed).Build());
            }
Exemple #2
0
            public async ValueTask <AdminCommandResult> AddReasonAsync([MustBe(Operator.GreaterThan, 0)] int id,
                                                                       [Remainder] string reason)
            {
                var punishment =
                    await Context.Database.Punishments.FirstOrDefaultAsync(x =>
                                                                           x.GuildId == Context.Guild.Id && x.Id == id);

                if (punishment is null)
                {
                    return(CommandErrorLocalized("punishment_notfound_id"));
                }

                if (!string.IsNullOrEmpty(punishment.Reason))
                {
                    return(CommandErrorLocalized("punishment_reason_exists"));
                }

                punishment.Reason = reason;
                Context.Database.Punishments.Update(punishment);
                await Context.Database.SaveChangesAsync();

                if (!(Context.Guild.GetTextChannel(punishment.LogMessageChannelId) is CachedTextChannel channel) ||
                    !(await channel.GetMessageAsync(punishment.LogMessageId) is IUserMessage message))
                {
                    return(CommandSuccess(string.Join('\n', Context.Localize("punishment_reason_success"), Context.Localize("punishment_reason_missingmessage"))));
                }

                await message.ModifyAsync(x =>
                {
                    var builder = LocalEmbedBuilder.FromEmbed(message.Embeds[0]);
                    var field   = builder.Fields.FirstOrDefault(y => y.Name.Equals(Context.Localize("title_reason")));
                    if (!(field is null))
                    {
                        builder.Fields.First(y => y.Name.Equals(field.Name)).Value = reason;
                    }
                    x.Embed = builder.Build();
                });

                if (channel.Id == Context.Channel.Id)
                {
                    _ = Context.Message.DeleteAsync();
                    return(CommandSuccess());
                }

                return(CommandSuccess("punishment_reason_success"));
            }