Пример #1
0
        public CustomEmbed GetFormattedEmbed(ulong guildID, ulong userID, string commandName, string unformattedText)
        {
            _guildID     = guildID;
            _userID      = userID;
            _commandName = commandName;

            var unformattedEmbed = JsonConvert.DeserializeObject <CustomEmbed>(unformattedText);


            var formattedEmbed = new CustomEmbed()
            {
                PlainText         = StringFormatter(unformattedEmbed.PlainText),
                AuthorIconUrl     = StringFormatter(unformattedEmbed.AuthorIconUrl),
                AuthorName        = StringFormatter(unformattedEmbed.AuthorName),
                AuthorUrl         = StringFormatter(unformattedEmbed.AuthorUrl),
                Description       = StringFormatter(unformattedEmbed.Description),
                EmbedUrl          = StringFormatter(unformattedEmbed.EmbedUrl),
                FooterText        = StringFormatter(unformattedEmbed.FooterText),
                FooterUrl         = StringFormatter(unformattedEmbed.FooterText),
                ImageUrl          = StringFormatter(unformattedEmbed.ImageUrl),
                ThumbnailUrl      = StringFormatter(unformattedEmbed.ThumbnailUrl),
                Title             = StringFormatter(unformattedEmbed.Title),
                FieldTitles       = StringFormatter(unformattedEmbed.FieldTitles),
                FieldValues       = StringFormatter(unformattedEmbed.FieldTitles),
                FieldInlineValues = unformattedEmbed.FieldInlineValues,
                Colour            = unformattedEmbed.Colour,
                TimeStamp         = unformattedEmbed.TimeStamp
            };

            return(formattedEmbed);
        }
Пример #2
0
        private static List <CustomField> GetFields(this CustomEmbed embed, out int amountsFailed)
        {
            var CustomFields            = new List <CustomField>();
            int amountOfSucceededFields = 0;

            for (int i = 0; i < embed.FieldTitles.Length; i++)
            {
                if (embed.FieldTitles[i] == String.Empty || embed.FieldTitles[i] == null)
                {
                    continue;
                }
                var field = new CustomField()
                {
                    FieldTitle  = embed.FieldTitles[i],
                    FieldValue  = embed.FieldValues[i],
                    InlineValue = embed.FieldInlineValues[i]
                };

                CustomFields.Add(field);
                amountOfSucceededFields++;
            }

            amountsFailed = embed.FieldTitles.Length - amountOfSucceededFields;
            return(CustomFields);
        }
Пример #3
0
        public static Embed CreateEmbed(this CustomEmbed embed, out int createFieldFailAmount)
        {
            uint color = Convert.ToUInt32(embed.Colour, 16);
            var  eb    = new EmbedBuilder();

            eb.WithAuthor(embed.AuthorName, embed.AuthorIconUrl, embed.AuthorUrl);
            eb.WithColor(color);
            eb.WithFooter(embed.FooterText, embed.FooterUrl);
            eb.WithDescription(embed.Description);
            eb.WithImageUrl(embed.ImageUrl);
            eb.WithThumbnailUrl(embed.ThumbnailUrl);
            eb.WithTitle(embed.Title);
            eb.WithUrl(embed.EmbedUrl);
            eb.WithTimestamp(embed.TimeStamp.GetValueOrDefault(DateTimeOffset.UtcNow));

            int amountsFailed = 0;

            if (!(embed.FieldTitles == null))
            {
                var fields = embed.GetFields(out amountsFailed);

                for (int i = 0; i < fields.Count; i++)
                {
                    eb.AddField(fields[i].FieldTitle, fields[i].FieldValue, fields[i].InlineValue);
                }
            }

            if (eb.Length == 0)
            {
                createFieldFailAmount = 0;
                return(null);
            }

            createFieldFailAmount = amountsFailed;
            return(eb.Build());
        }