Пример #1
0
        /// <summary>
        /// An asyncronous version of <seealso cref="ArchiveCommentLinks(Config, IBotState, Reddit, Comment, List{string}, List{string})"/> with <see cref="List{ArchiveLink}"/> support instead
        /// </summary>
        /// <param name="config">A <see cref="Config"/> used for flavortext</param>
        /// <param name="state">An <see cref="IBotState"/> used for keeping track of things</param>
        /// <param name="reddit">A <see cref="Reddit"/> used for getting things</param>
        /// <param name="comment">The <see cref="Comment"/> you are archiving</param>
        /// <param name="archiveLinks">A <see cref="List{ArchiveLink}"/> used for archived links</param>
        /// <returns>A <see cref="Task"/> for asyncronous using</returns>
        public static async Task ArchiveCommentLinksAsync(Config config, IBotState state, Reddit reddit, Comment comment, List <ArchiveLink> archiveLinks)
        {
            if (archiveLinks.Count < 1)
            {
                return;
            }
            List <string>         Links     = new List <string>();
            string                commentID = comment.Id;
            string                postID    = comment.LinkId.Substring(3);
            Task <List <string> > linksTask = Task.Run(() =>
            {
                List <string> links = new List <string>();
                foreach (ArchiveLink link in archiveLinks)
                {
                    if (link.IsExcluded)
                    {
                        continue;
                    }
                    links.Add($"* **By [{comment.AuthorName.DeMarkup()}]({comment.Shortlink.Replace("oauth", "www")})** ([{link.Hostname}]({link.OriginalLink})): {link.ArchivedLink}\n");
                }
                return(links);
            });

            if (state.DoesCommentExist(postID))
            {
                string botCommentThingID = state.GetCommentForPost(postID);
                if (!botCommentThingID.Contains("t1_"))
                {
                    botCommentThingID = "t1_" + botCommentThingID;
                }
                Console.WriteLine($"Already have post in {postID}, getting comment {botCommentThingID.Substring(3)}");
                Links = await linksTask;
                if (!EditArchiveComment((Comment)reddit.GetThingByFullname(botCommentThingID), Links))
                {
                    PostArchiveLinksToComment(config, state, Program.Headers[2], comment, Links);
                }
            }
            else
            {
                Links = await linksTask;
                Console.WriteLine($"No comment in {postID} to edit, making new one");
                PostArchiveLinks(config, state, Program.Headers[2], comment.GetCommentPost(reddit), Links);
            }
            state.AddCheckedComment(commentID);
        }