private EmbedBuilder PrepareEmbed(EmbedType type)
        {
            var embed = new EmbedBuilder();

            switch (type)
            {
            case EmbedType.Info:
                embed.Color = new s.Color(0, 127, 255);
                break;

            case EmbedType.Success:
                embed.Color = new s.Color(127, 255, 0);
                break;

            case EmbedType.Warning:
                embed.Color = new s.Color(255, 255, 0);
                break;

            case EmbedType.Error:
                embed.Color = new s.Color(255, 127, 0);
                break;

            default:
                embed.Color = new s.Color(255, 255, 255);
                break;
            }
            embed.ThumbnailUrl = AdaBotCore.AdaClient.CurrentUser.AvatarUrl;
            return(embed);
        }
Example #2
0
 private static void AdjustFillPanel(Control child, EmbedType type, SplitContainer splitter)
 {
     if (type == EmbedType.Left)
     {
         splitter.SplitterDistance = child.Width;
         child.Height = splitter.Height;
     }
     else if (type == EmbedType.Right)
     {
         splitter.SplitterDistance = splitter.Width - child.Width;
         child.Height = splitter.Height;
     }
     else if (type == EmbedType.Top)
     {
         splitter.SplitterDistance = child.Height;
         child.Width = splitter.Width;
     }
     else if (type == EmbedType.Bottom)
     {
         splitter.SplitterDistance = splitter.Height - child.Height;
         child.Width = splitter.Width;
     }
     if (type != EmbedType.None)
     {
         child.Dock = DockStyle.Fill;
     }
 }
Example #3
0
        public static LocalEmbedBuilder CreateEmbed(EmbedType type, string title, string content = null)
        {
            LocalEmbedBuilder embed = new LocalEmbedBuilder();

            switch (type)
            {
            case EmbedType.Info:
                embed.WithAuthor(title);
                embed.WithColor(new Color(67, 181, 129));
                break;

            case EmbedType.Success:
                embed.WithAuthor(title, "https://i.imgur.com/XnVa7ta.png");
                embed.WithColor(new Color(67, 181, 129));
                break;

            case EmbedType.Failure:
                embed.WithAuthor(title, "https://i.imgur.com/Sg4663k.png");
                embed.WithColor(new Color(67, 181, 129));
                break;
            }

            embed.WithDescription(content);

            return(embed);
        }
Example #4
0
        private static void GenerateSplitter(Control target, EmbedType type, EmbedableTag tag, out SplitContainer splitter, out SplitterPanel fillPanel, out SplitterPanel contentPanel, bool isSizable)
        {
            splitter  = new SplitContainer();
            fillPanel = null;

            if (type == EmbedType.Left || type == EmbedType.Right)
            {
                splitter.Orientation = Orientation.Vertical;
                if (type == EmbedType.Left)
                {
                    fillPanel    = splitter.Panel1;
                    contentPanel = splitter.Panel2;
                    if (!isSizable)
                    {
                        splitter.FixedPanel = FixedPanel.Panel1;
                    }
                }
                else
                {
                    fillPanel    = splitter.Panel2;
                    contentPanel = splitter.Panel1;
                    if (!isSizable)
                    {
                        splitter.FixedPanel = FixedPanel.Panel2;
                    }
                }
            }
            else
            {
                splitter.Orientation = Orientation.Horizontal;
                if (type == EmbedType.Top)
                {
                    fillPanel    = splitter.Panel1;
                    contentPanel = splitter.Panel2;
                    if (!isSizable)
                    {
                        splitter.FixedPanel = FixedPanel.Panel1;
                    }
                }
                else
                {
                    fillPanel    = splitter.Panel2;
                    contentPanel = splitter.Panel1;
                    if (!isSizable)
                    {
                        splitter.FixedPanel = FixedPanel.Panel2;
                    }
                }
            }
            if (tag != null && tag.ContentRegion != null && tag.ContentRegion.Controls.Count > 0)            // target.Controls.Count > 0)
            {
                foreach (Control item in target.Controls)
                {
                    target.Controls.Remove(item);

                    contentPanel.Controls.Add(item);
                }
            }
            tag.ContentRegion = contentPanel;
        }
Example #5
0
 internal Embed(EmbedType type,
                string title,
                string description,
                string url,
                DateTimeOffset?timestamp,
                Color?color,
                EmbedImage?image,
                EmbedVideo?video,
                EmbedAuthor?author,
                EmbedFooter?footer,
                EmbedProvider?provider,
                EmbedThumbnail?thumbnail,
                ImmutableArray <EmbedField> fields)
 {
     Type        = type;
     Title       = title;
     Description = description;
     Url         = url;
     Color       = color;
     Timestamp   = timestamp;
     Image       = image;
     Video       = video;
     Author      = author;
     Footer      = footer;
     Provider    = provider;
     Thumbnail   = thumbnail;
     Fields      = fields;
 }
Example #6
0
        public static async Task SendEmbedAsync(CommandContext ctx, string message, EmbedType type = EmbedType.Default)
        {
            var          prefix = string.Empty;
            DiscordColor color;

            switch (type)
            {
            case EmbedType.Good:
                color = DiscordColor.Green;
                break;

            case EmbedType.Warning:
                prefix = ":warning: ";
                color  = DiscordColor.Yellow;
                break;

            case EmbedType.Missing:
                prefix = ":mag: ";
                color  = DiscordColor.Wheat;
                break;

            case EmbedType.Error:
                prefix = ":no_entry: ";
                color  = DiscordColor.Red;
                break;

            default:
                color = new DiscordColor("#00FF7F");
                break;
            }
            var output = new DiscordEmbedBuilder()
                         .WithDescription(prefix + message)
                         .WithColor(color);
            await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);
        }
Example #7
0
    /// <summary>
    /// Parse a generic embedded object
    /// </summary>
    /// <param name="content">Post content</param>
    /// <param name="type">EmbedType</param>
    /// <param name="provider">Provider</param>
    /// <param name="format">Function to parse matched content</param>
    internal static string Parse(string content, EmbedType type, Provider provider, Func <string, EmbedParsed, string> format)
    {
        // Get Embedded info
        const string pattern = "<!-- wp:embed ({.*?}) -->(.*?)<!-- /wp:embed -->";
        var          matches = Regex.Matches(content, pattern, RegexOptions.Singleline);

        if (matches.Count == 0)
        {
            return(content);
        }

        // Parse each match
        foreach (Match match in matches)
        {
            // Info is encoded as JSON so deserialise it first
            var info = match.Groups[1].Value;
            _ = JsonF.Deserialise <EmbedParsed>(info).IfSome(embed =>
            {
                // Only replace matching embed types
                if (embed.Type == type && embed.ProviderNameSlug == provider)
                {
                    // Replace content using child Format() method
                    content = content.Replace(
                        match.Value,
                        format(Rnd.StringF.Get(10), embed)
                        );
                }
            });
        }

        // Return parsed content
        return(content);
    }
        private EmbedBuilder PrepareEmbed(string title, string desc, EmbedType type)
        {
            var embed = this.PrepareEmbed(type);

            embed.Title       = title;
            embed.Description = desc;
            return(embed);
        }
Example #9
0
        public EmbedBuilder Generate(EmbedType requestedType, string title, string description)
        {
            var embedInfo   = embedInformation.FirstOrDefault(e => e.Type == requestedType);
            var embedResult = new EmbedBuilder()
                              .WithTitle(title)
                              .WithDescription(description)
                              .WithColor(embedInfo.Color);

            return(embedResult);
        }
Example #10
0
 public IEmbeder GetInstance(EmbedType embedType, EmbedingOptions options)
 {
     switch (embedType)
     {
         case EmbedType.Lsb:
             return new LsbEmbeder(options);
         case EmbedType.None:
             return new MockEmbeder();
         default:
             return new LsbEmbeder(options);
     }
 }
Example #11
0
        public static Key GenerateKey(Container container, string message, CryptType cryptType, EmbedType embedType, IKeyAware keyParser, string stringkey)
        {
            if (!keyParser.ValidateKey(stringkey))
                throw new ArgumentException("Key is not valid.");

            Key key = new Key();
            key.CryptType = cryptType;
            key.EmbedType = embedType;
            key.MessageLength = Constants.DEFAULT_ENCODING.GetByteCount(message);
            key.Value = keyParser.ParseKey(stringkey);

            return key;
        }
Example #12
0
        public static void EmbedInto(this Control child, Control parent, EmbedType type, EmbededCallback embededCallback, bool isFixed = false, bool isSizable = false)
        {
            if (child != null && parent != null)
            {
                EmbedableTag tag = EmbedableTag.GetInstance(parent);
                tag.NewlyEmbededControls.Add(child);
                tag.Parent = parent;
                Control container = tag.ContentRegion;

                if (type == EmbedType.Fill || type == EmbedType.None)
                {
                    child.EmbedInto(container, type == EmbedType.Fill);
                    return;
                }


                #region Generate SplitContainer according to the EmbedType
                SplitContainer splitter;
                SplitterPanel  fillPanel;
                SplitterPanel  contentPanel;
                GenerateSplitter(parent, type, tag, out splitter, out fillPanel, out contentPanel, isSizable);
                #endregion
                if (splitter != null)
                {
                    splitter.IsSplitterFixed = isFixed;
                }
                fillPanel.Controls.Add(child);
                container.Controls.Add(splitter);
                splitter.Dock     = DockStyle.Fill;
                tag.ContentRegion = contentPanel;

                #region Adjust fill panel size
                AdjustFillPanel(child, type, splitter);
                #endregion
                if (child is ScreenRegion)
                {
                    child.Show();
                }
                if (embededCallback != null)
                {
                    embededCallback(child);
                }
            }
        }
Example #13
0
        private void Init(EmbedType type = EmbedType.None)
        {
            EmbedType = type;
            WithThumbnailUrl(DefaultThumbnailUrl);
            Color color;

            switch (type)
            {
            case EmbedType.None:
                color = NoneColor;
                break;

            case EmbedType.Error:
                color = ErrorColor;
                break;

            case EmbedType.Success:
                color = SuccessColor;
                break;

            case EmbedType.Debug:
                color = DebugColor;
                break;

            case EmbedType.Info:
                color = InfoColor;
                break;

            case EmbedType.Warning:
                color = WarningColor;
                break;

            default:
                color = NoneColor;
                break;
            }
            WithColor(color);
        }
Example #14
0
 public Embed()
 {
     this.type = EmbedType.Link;
 }
Example #15
0
 internal Embed(EmbedType type)
 {
     Type   = type;
     Fields = ImmutableArray.Create <EmbedField>();
 }
Example #16
0
 public Embed(EmbedType type)
 {
     this.type = type;
 }
Example #17
0
 public Embed(string url, int width, int height)
 {
     this.type = EmbedType.Photo;
     this.url = url;
     this.width = width.ToString();
     this.height = height.ToString();
 }
Example #18
0
 public static void Embed(this Control parent, Control child, EmbedType type, EmbededCallback embededCallback = null)
 {
     EmbedInto(child, parent, type, embededCallback);
 }
Example #19
0
 public Embed(EmbedType type, string html, int width, int height)
 {
     this.type = type;
     this.html = html;
     this.width = width.ToString();
     this.height = height.ToString();
 }
Example #20
0
 public CakeEmbedBuilder(EmbedType type)
 {
     Init(type);
 }
Example #21
0
 public EmbedInfo(EmbedType type, Color color)
 {
     Type  = type;
     Color = color;
 }