Пример #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
        private void SendNeverContributedWarningMessage(Post post)
        {
            if (!DryRun)
            {
                var reply = post
                            .Reply(
                    $"It looks like you haven't recently commented on any posts within this community. " +
                    $"Please sufficiently interact with r/{_service.Subreddit.Name} by constructively commenting on posts other than your own before submitting a Maker Post.\n\n" +
                    $"For more information review the [Maker FAQ](https://www.reddit.com/r/chefknives/wiki/makerfaq)")
                            .Distinguish("yes", false);

                _service.SelfCommentDatabase.Upsert(reply.ToSelfComment(post.Id, RedditThingType.Post, post.Listing.LinkFlairTemplateId));

                post.Remove();
            }

            _logger.Information($"Commented with SendNeverContributedWarningMessage on post by {post.Author}");
        }
Пример #3
0
        private void SendTenToOneWarningMessage(Post post, int nonMakerComments, int makerPostCount)
        {
            if (!DryRun)
            {
                var reply = post
                            .Reply(
                    $"It looks like you've submitted {makerPostCount} Maker Posts but only authored {nonMakerComments} comments outside of your own Maker Posts. " +
                    $"Please sufficiently interact with r/{_service.Subreddit.Name} by constructively commenting on posts other than your own before submitting a new Maker Post.\n\n" +
                    $"For more information review the [Maker FAQ](https://www.reddit.com/r/chefknives/wiki/makerfaq)")
                            .Distinguish("yes", false);

                _service.SelfCommentDatabase.Upsert(reply.ToSelfComment(post.Id, RedditThingType.Post, post.Listing.LinkFlairTemplateId));

                post.Remove();
            }

            _logger.Information($"Commented with SendTenToOneWarningMessage on post by {post.Author}.");
        }