Esempio n. 1
0
        static HTMLBase getMessageHeader(ReturnedMsg msg, string authorName, string roleColor)
        {
            var h2 = new H2(cls: "header-23xsNx");

            h2.Children.Add(new Span(cls: "latin24CompactTimeStamp-2V7XIQ timestamp-3ZCmNB timestampVisibleOnHover-2bQeI4")
            {
                Children =
                {
                    new Span()
                    {
                        Children =
                        {
                            new ItalicText("[",                                cls: "separator-2nZzUB").WithTag("aria-hidden", "true"),
                            new RawObject(msg.CreatedAt.ToString("hh:mm tt")),
                            new ItalicText("] ",                               cls: "separator-2nZzUB").WithTag("aria-hidden", "true")
                        }
                    }.WithTag("aria-label", msg.CreatedAt.ToString("hh:mm tt"))
                }
            });
            var usernameStuffs = new Span(cls: "headerText-3Uvj1Y");

            usernameStuffs.Children.Add(new Span(cls: "username-1A8OIy clickable-1bVtEA")
                                        .WithTag("style", $"color: {roleColor}")
                                        .WithTag("tabIndex", "0")
                                        .WithTag("aria-controls", "popout_320")
                                        .WithTag("aria-expanded", "false")
                                        .WithTag("role", "button")
                                        .WithRawText(authorName));
            usernameStuffs.Children.Add(new ItalicText(":", cls: "separator-2nZzUB"));
            h2.Children.Add(usernameStuffs);
            return(h2);
        }
Esempio n. 2
0
        static HTMLBase getMsgAttachments(ReturnedMsg message, bool doProxy)
        {
            var split = message.Attachments.Split(',').Where(x => isImage(x)).ToList();

            if (split.Count == 0)
            {
                return(null);
            }
            var container = new Div(cls: "container-1ov-mD");

            foreach (var image in split)
            {
                var anchor = new Anchor(image, cls: "anchor-3Z-8Bb anchorUnderlineOnHover-2ESHQB imageWrapper-2p5ogY imageZoom-1n-ADA clickable-3Ya1ho embedWrapper-lXpS3L");
                anchor.RawText = "";
                anchor.Style   = "min-height: 50px; width: 100%;";
                var img = new DiscordBot.Classes.HTMLHelpers.Objects.Img();
                img.Style = "position: relative; max-height: 300px; max-width: 90%; width: auto;";
                if (doProxy)
                {
                    var uri = new Uri(image);
                    img.Src = $"{Handler.LocalAPIUrl}{uri.PathAndQuery}";
                }
                else
                {
                    img.Src = image;
                }
                anchor.Children.Add(img);
                container.Children.Add(anchor);
            }
            return(container);
        }
Esempio n. 3
0
        static HTMLBase getMsgContent(IGuild guild, ReturnedMsg m, ulong contextUser, bool shouldRedactDeleted, out bool mentioned)
        {
            var div   = new Div(cls: "markup-2BOw-j messageContent-2qWWxC");
            var basic = parseMarkdown(guild, m.Content, contextUser, out mentioned, shouldRedactDeleted);

            return(div.WithRawText(basic));
        }
Esempio n. 4
0
        public static HTMLBase getMessage(ReturnedMsg msg, IGuild guild, string authorName, string roleColor, ulong contextUser, bool shouldRedact, bool doProxy)
        {
            var messageDiv = new Div(id: msg.Id.ToString(), cls: "message-2qnXI6 groupStart-23k01U wrapper-2a6GCs compact-T3H92H zalgo-jN1Ica");

            messageDiv.WithTag("role", "group")
            .WithTag("tabindex", "-1");
            messageDiv.OnClick = "ctrlPopupId(this, event);";
            var contentsDiv = new Div(cls: "contents-2mQqc9").WithTag("role", "document");

            if (msg.IsDeleted)
            {
                messageDiv.ClassList.Add("message-deleted");
            }
            contentsDiv.Children.Add(getMessageHeader(msg, authorName, roleColor));
            bool mentioned = false;

            try
            {
                contentsDiv.Children.Add(getMsgContent(guild, msg, contextUser, shouldRedact, out mentioned));
            }
            catch (Exception ex)
            {
                Program.LogMsg($"Failed with {msg.Id}", LogSeverity.Critical, "VPN");
                Program.LogMsg($"{msg.Author == null}");
                Program.LogMsg($"{msg.Content == null}");
                Program.LogMsg($"{msg.CreatedAt == null}");
                Program.LogMsg($"{msg.Timestamp == null}");
                throw;
            }
            var attachments = getMsgAttachments(msg, doProxy);

            if (attachments != null)
            {
                contentsDiv.Children.Add(attachments);
            }
            messageDiv.Children.Add(contentsDiv);
            if (mentioned)
            {
                messageDiv.ClassList.Add("mentioned-xhSam7");
            }

            if (msg.Embeds.Count > 0)
            {
                var containerDiv = new Div(cls: "container-1ov-mD");
                messageDiv.Children.Add(containerDiv);
                foreach (var embed in msg.Embeds)
                {
                    containerDiv.Children.Add(getEmbed(guild, embed, contextUser));
                }
            }

            return(messageDiv);
        }
Esempio n. 5
0
        bool isMessageNew(SocketTextChannel channel, ReturnedMsg message)
        {
            DateTime last;

            if (Context.User.LastVisitVPN.TryGetValue(channel.Id, out var item))
            {
                last = item;
            }
            else
            {
                last = DateTime.Now.AddDays(-1);
            }
            return(message.CreatedAt.DateTime > last);
        }