Example #1
0
        private async Task SendConfirmNotificationAsync(ExteralApplication app, VetMember user, ExteralApplicationPayment eap)
        {
            Discord.EmbedBuilder builder = new Discord.EmbedBuilder();

            builder.WithTitle($"{app.Name}:購入確認");
            builder.WithUrl(app.CallbackUrl + $"?id={eap.Id}");
            builder.WithAuthor(app.VetMember.Name, app.VetMember.GetAvaterIconUrl(), app.VetMember.GetMemberPageUrl(StaticSettings.SiteBaseUrl));
            builder.AddField("金額", eap.Amount);
            builder.WithDescription(eap.Description);
            builder.WithFooter("よろしければ、タイトルをクリックして購入処理をつづけてください");

            await CoreService.SendDirectMessage(new[] { user }, string.Empty, builder.Build());
        }
Example #2
0
        private static async Task <Discord.Embed> GetStory(FicLink link, bool alreadyLinked, string forUser)
        {
            try
            {
                Story story;

                if (link.Network == FicNetwork.FFN)
                {
                    story = await FFNCrawler.CrawlStory(link.ID);
                }
                else if (link.Network == FicNetwork.AO3)
                {
                    story = await AO3Crawler.CrawlStory(link.ID);
                }
                else
                {
                    return(null);
                }

                string statusLine = "Published " + story.Published.ToShortDateString();
                if (story.Updated != null)
                {
                    statusLine += ", Updated " + ((DateTime)story.Updated).ToShortDateString();
                }

                statusLine += "  -  " + story.NumReviews + " Reviews, " + story.NumFavorites + " Favorites";

                string numWords = story.NumWords.ToString("N0", CultureInfo.InvariantCulture).Replace(",", "'");


                var numRecs = RecCounter.GetNumRecommendations(story);

                if (forUser != null)
                {
                    numRecs = RecCounter.Recommend(story, forUser);
                }

                var desc = story.Description;

                List <string> descriptionLines = new List <string>();

                while (desc.Length > 100)
                {
                    var lastSpaceRight = desc.LastIndexOf(' ', 100);
                    if (lastSpaceRight == -1)
                    {
                        lastSpaceRight = desc.IndexOf(' ');
                        if (lastSpaceRight == -1)
                        {
                            descriptionLines.Add(desc);
                            break;
                        }
                    }
                    descriptionLines.Add(desc.Substring(0, lastSpaceRight));
                    desc = desc.Substring(lastSpaceRight + 1);
                }

                if (desc.Length > 0)
                {
                    descriptionLines.Add(desc);
                }

                string description = Clean(story.Description);
                var    updated     = story.Updated ?? story.Published;

                var builder = new Discord.EmbedBuilder();
                builder.WithAuthor(story.Author.PenName, url: story.Author.Url);
                builder.Title       = story.Title;
                builder.Url         = story.Url;
                builder.Description = story.Description;

                var book = "";
                if (story.IsComplete || DateTime.Now.Subtract(updated).TotalDays < 14)
                {
                    book = ":green_book:";
                }
                else if (DateTime.Now.Subtract(updated).TotalDays < 180)
                {
                    book = ":orange_book:";
                }
                else
                {
                    book = ":closed_book:";
                }

                var updateString = AgoString(updated) + (story.IsComplete ? " - Complete!" : "");

                builder.AddInlineField(book + " Last Updated", updateString);

                builder.AddInlineField(":book: Length", $"{FormatBigNumber(story.NumWords)} words in {story.NumChapters} chapters");

                return(builder.Build());
            }
            catch (Exception e)
            {
                Console.WriteLine("Error when crawling story " + link.ID + " at " + link.Network);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(null);
            }
        }