示例#1
0
        private void ScheduleDelayedCheck(Post post, Comment replyComment)
        {
            var timer = new Timer {
                Interval = TimeSpan.FromMinutes(_timeLimitMinutes).TotalMilliseconds
            };

            timer.Elapsed += (object sender, ElapsedEventArgs e) =>
            {
                timer.Stop();
                timer.Dispose();

                var comments = post.Comments.GetComments();
                if (!comments.Any(c => c.Depth == 0 && c.Author.Equals(post.Author)))
                {
                    post.Remove();
                    _logger.Information($"[{nameof(KnifePicsPostHandler)}]: Removed a post by {post.Author} since they did not post a top level comment within the allowed time.");
                }
                else
                {
                    // Delete the comment if OP followed the instructions.
                    replyComment.Delete();

                    // Update the comment in the database. There has to be a more elegant way to do this...
                    var databaseComment = replyComment.ToSelfComment(post.Id, RedditThingType.Post, post.Listing.LinkFlairTemplateId);
                    databaseComment.IsDeleted = true;
                    _service.SelfCommentDatabase.Upsert(databaseComment);
                }
            };

            timer.Enabled = true;
            timer.Start();
        }
示例#2
0
        public async Task <bool> Process(BaseController baseController, Func <string, Task> callback)
        {
            var comment = baseController as Comment;

            if (comment == null)
            {
                return(false);
            }

            if (_service.SelfCommentDatabase.GetAny(nameof(SelfComment.ParentId), comment.Id).Result != null)
            {
                return(false);
            }

            if (_rykyPhrases.Any(p => comment.Body.Contains(p, StringComparison.OrdinalIgnoreCase)))
            {
                if (!DryRun)
                {
                    Comment reply = null;
                    if (_rykyAuthors.Any(p => comment.Author.Equals(p, StringComparison.OrdinalIgnoreCase)))
                    {
                        if (_random.Next(100) >= 75)
                        {
                            reply = comment.Reply("Our Ryky who art on YouTube hallowed be thy brick Thy combo stone come, thy will be done Give us this day our daily brick And forgive us our dull knives as we forgive those who have dulled them Lead us not into actual good knives But deliver us a sponsored recommendation, amen");
                        }
                    }
                    else
                    {
                        if (_random.Next(100) >= 75)
                        {
                            reply = comment.Reply("Praise be!");
                        }
                    }

                    if (reply != null)
                    {
                        _service.SelfCommentDatabase.Upsert(reply.ToSelfComment(comment.ParentId, RedditThingType.Comment, comment.Listing.AuthorFlairTemplateId));
                    }
                }
            }

            return(false);
        }
示例#3
0
        /// <summary>
        /// Create a new instance of the comments controller.
        /// </summary>
        /// <param name="dispatch"></param>
        /// <param name="postId">The ID36 of the parent post</param>
        /// <param name="subreddit">The name of the parent subreddit</param>
        /// <param name="comment">The parent comment instance</param>
        /// <param name="confidence"></param>
        /// <param name="top"></param>
        /// <param name="newComments"></param>
        /// <param name="controversial"></param>
        /// <param name="old"></param>
        /// <param name="random"></param>
        /// <param name="qa"></param>
        /// <param name="live"></param>
        public Comments(Dispatch dispatch, string postId = null, string subreddit             = null, Comment comment    = null, List <Comment> confidence = null, List <Comment> top = null,
                        List <Comment> newComments       = null, List <Comment> controversial = null, List <Comment> old = null, List <Comment> random     = null, List <Comment> qa  = null, List <Comment> live = null)
            : base()
        {
            Dispatch  = dispatch;
            Subreddit = subreddit;
            PostId    = postId;

            Confidence    = confidence ?? new List <Comment>();
            Top           = top ?? new List <Comment>();
            New           = newComments ?? new List <Comment>();
            Controversial = controversial ?? new List <Comment>();
            Old           = old ?? new List <Comment>();
            Random        = random ?? new List <Comment>();
            QA            = qa ?? new List <Comment>();
            Live          = live ?? new List <Comment>();

            Comment = comment;

            SubKey = (comment?.Fullname != null ? comment.Fullname : "t3_" + PostId);
        }