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(); }
private void SendMakerPostSticky(Post post) { var replyMessage = new StringBuilder(); replyMessage.AppendLine( "This post has been identified as a maker post! If you have not done so please review the [Maker FAQ](https://www.reddit.com/r/chefknives/wiki/makerfaq). \n\n " + "As a reminder to all readers, you may not discuss sales, pricing, for OP to make you something, or where to buy what OP is displaying or similar in this thread " + "or anywhere on r/chefknives. Use private messages for any such inquiries. \n\n"); var postHistory = _service.RedditPostDatabase .GetByFilter(nameof(RedditThing.Author), post.Author).Result .Where(p => p.Flair != null && p.Flair.Equals(_makerPostName)); if (postHistory != null && postHistory.Any()) { replyMessage.AppendLine("---"); replyMessage.AppendLine($"Here are some past Maker Posts from u/{post.Author}:"); postHistory.Take(5).ToList() .ForEach(p => replyMessage.AppendLine($"* [{p.Title}]({_postUrlFirstPart}{p.Id})")); } _logger.Information($"Commented with SendTenToOneWarningMessage on post by {post.Author}. "); if (!DryRun) { var reply = post .Reply(replyMessage.ToString()) .Distinguish("yes", true); _service.SelfCommentDatabase.Upsert(reply.ToSelfComment(post.Id, RedditThingType.Post, post.Listing.LinkFlairTemplateId)); } _logger.Information($"Commented with maker warning on post by {post.Author}"); }
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}"); }
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}."); }
public IActionResult AddPost(Post post) { service.AddNewPost(post); return(RedirectToAction("List")); }