Пример #1
0
        /// <summary>
        /// Posts all links archived, throws <see cref="ArgumentNullException"/> if you attempt to call this with any null arguments
        /// </summary>
        /// <param name="config"></param>
        /// <param name="state"></param>
        /// <param name="head"></param>
        /// <param name="post"></param>
        /// <param name="ArchiveList"></param>
        public static void PostArchiveLinks(Config config, IBotState state, string head, Post post, List <string> ArchiveList)
        {
            if (config == null || state == null || head == null || post == null || ArchiveList == null)
            {
                throw new ArgumentNullException(config == null ? nameof(config) : state == null ? nameof(state) : head == null ? nameof(head) : post == null ? nameof(post) : nameof(ArchiveList));
            }
            Console.Title = $"Posting new comment to post {post.Id}";
            string  LinksListBody = string.Join("", ArchiveList);
            string  c             = head + LinksListBody + "\n" + string.Format(Program.Headers[3], config.FlavorText[rand.Next(0, config.FlavorText.Length)]);
            Comment botComment    = post.Comment(c);

            try
            {
                state.AddBotComment(post.Id, botComment.Id);
                Console.WriteLine(c);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine($"Caught exception replying to post {post.Id} with new comment  {Regex.Replace(botComment.Id, "t1_", "")}: {e.Message}");
                botComment.Del();
            }
        }