private DB4Comment validateAndAward(DB4Thing qualifiedComment) { // Validate comment var commentValidationResult = _commentValidator.Validate(qualifiedComment); if (commentValidationResult.IsValidDelta) { // Award the delta // parentThing must be a Comment here - deltas are only // valid when the parent is a Comment Assert.That(qualifiedComment.ParentThing.Type == DB4ThingType.Comment); _deltaAwarder.Award(qualifiedComment); } return(commentValidationResult); }
public void Handle(DB4Thing privateMessage) { // The body should be the URL to a comment string commentUrl = privateMessage.Body.Trim(); try { // Get comment by url var comment = _redditService.GetCommentByUrl(commentUrl); // If that succeeded, we need the full comment with children to check for replies _redditService.PopulateParentAndChildren(comment); // Check for replies var db4ReplyResult = _commentDetector.DidDB4Reply(comment); // If a the parent authorname is DeltaBot, bail if (comment.ParentThing.AuthorName == _appConfiguration.DB4Username) { _redditService.ReplyToPrivateMessage(privateMessage.Id, AddFailedCantAwardDeltaBot); return; } // If a the parent authorname is [deleted], bail if (comment.ParentThing.AuthorName == Constants.DeletedAuthorName) { _redditService.ReplyToPrivateMessage(privateMessage.Id, AddFailedAuthorDeletedMessage); return; } // If a delta was already awarded successfully, bail if (db4ReplyResult.HasDB4Replied && db4ReplyResult.WasSuccessReply || db4ReplyResult.CommentType == DB4CommentType.ModeratorAdded) { _redditService.ReplyToPrivateMessage(privateMessage.Id, AddFailedAlreadyAwardedMessage); return; } // Build the normal success message // IMPORTANT: Build reply *before* awarding. This has to do with a quirk with getting the correct // delta count to build the reply. My bad... var reply = _commentBuilder.BuildReply(DB4CommentType.SuccessDeltaAwarded, comment); // Award delta _deltaAwarder.Award(comment); // Don't edit the existing comment - delete it and reply with the mod added reply // db4ReplyResult.Comment will be null if the mod is adding a delta directly to a comment if (db4ReplyResult.Comment != null) { _replier.DeleteReply(db4ReplyResult.Comment); } _replier.Reply(comment, reply); // Build modmail body string body = _appConfiguration.PrivateMessages.ModAddedDeltaNotificationMessage .Replace(_appConfiguration.ReplaceTokens.UsernameToken, privateMessage.AuthorName) .Replace(_appConfiguration.ReplaceTokens.CommentLink, commentUrl); // Reply with modmail indicating success _redditService.SendPrivateMessage(_appConfiguration.PrivateMessages.ModAddedDeltaNotificationSubject, body, $"/r/{_appConfiguration.SubredditName}"); // Reply to user _redditService.ReplyToPrivateMessage(privateMessage.Id, AddSucceededMessage); } catch (Exception ex) { // Reply indicating failure _redditService.ReplyToPrivateMessage(privateMessage.Id, string.Format(AddFailedErrorMessageFormat, ex.ToString())); // Rethrow for logging purposes throw; } }