Beispiel #1
0
        private EmbedBuilder BuildImageEmbed(PostData postData, string embedDescription)
        {
            StringBuilder seriesNames     = new StringBuilder(TagParser.EscapeUnderscore(postData.SeriesName));
            StringBuilder title           = new StringBuilder(TagParser.BuildTitle(postData.TagName));
            StringBuilder tagIds          = new StringBuilder(postData.TagId.ToString());
            StringBuilder tagIdTitle      = new StringBuilder("Character ID");
            StringBuilder seriesNameTitle = new StringBuilder("Series Name");

            if (postData.AdditionalData != null)
            {
                foreach (string s in postData.AdditionalData.AdditionalTagNames)
                {
                    title.Append($", {TagParser.BuildTitle(s)}");
                }

                foreach (int i in postData.AdditionalData.AdditionalTagIds)
                {
                    tagIds.Append($", {i}");
                }

                tagIdTitle.Append("s");

                foreach (string s in postData.AdditionalData.AdditionalSeriesNames)
                {
                    if (s != postData.SeriesName)
                    {
                        seriesNames.Append($", {s}");
                    }
                }

                seriesNameTitle.Append("s");
            }

            return(new EmbedBuilder().WithTitle(title.ToString())
                   .AddField(tagIdTitle.ToString(), tagIds.ToString(), true)
                   .AddField("Post ID", postData.LinkId, true)
                   .AddField(seriesNameTitle.ToString(), seriesNames.ToString(), true)
                   .WithDescription(embedDescription)
                   .WithImageUrl(postData.Link)
                   .WithUrl(postData.Link)
                   .WithAuthor(Context.Client.CurrentUser)
                   .WithFooter($"Image {postData.PostIndex + 1} of {postData.PostCount}")
                   .WithColor(Color.DarkGrey)
                   .WithCurrentTimestamp());
        }
Beispiel #2
0
        private async Task <EmbedBuilder> RandomPostAsync()
        {
            if (!_pageService.HandlerAdded)
            {
                Context.Client.ReactionAdded += ReactionAdded_Event;
                _pageService.HandlerAdded     = true;
            }

            DbCharacterIndex characterIndex = _characterIndex;

            using (MySqlConnection conn = _characterIndex.GetConnection())
            {
                EmbedBuilder embed;
                PostData     postData;
                string       tag = characterIndex.LookupRandomTag(conn);
                string       title;

                if (!string.IsNullOrEmpty(tag))
                {
                    title    = TagParser.BuildTitle(tag);
                    postData = characterIndex.LookupRandomPost(tag, conn);

                    while (postData == null)
                    {
                        tag      = characterIndex.LookupRandomTag(conn);
                        title    = TagParser.BuildTitle(tag);
                        postData = characterIndex.LookupRandomPost(tag, conn);
                    }

                    string embedDescription = rerollRandomDescription + "." +
                                              Environment.NewLine +
                                              listCharactersDescription + ".";

                    embed = BuildImageEmbed(postData, embedDescription);
                }
                else
                {
                    await ReplyAsync("An error occurred during random tag lookup.");

                    return(null);
                }

                return(embed);
            }
        }