upvoteComment :: MonadIO m => Options -> Comment -> m (EitherR ())
upvoteComment opts Comment{..} = do
  let CommentID cid = commentID
      R subr = subreddit
  case optCredentials opts of
    Nothing -> do
      logFmt Warn
        "Cannot upvote comment #{} in /r/{} due to lack of credentials"
        (cid, subr)
      return $ Left $ APIError CredentialsError
    _ -> do
      logFmt Info "Upvoting comment #{} in /r/{} [{}] -> [{}]"
        (cid, subr, showScore score, showScore $ (+1) <$> score)
      result <- runReddit opts $ R.upvoteComment commentID
      case result of
        Left err ->
          logFmt Warn "Failed to upvote comment #{}: {}" (cid, tshow err)
        Right _ -> logFmt Debug "Successfully upvoted comment #{} in /r/{}"
                                (cid, subr)
      return result
  where
  -- Current score may be absent in the Comment record
  showScore = fromMaybe "?" . (tshow <$>)


-- Utilities

-- | Run a RedditT action using program Options.
upvoteComment :: MonadIO m => Options -> Comment -> m (EitherR ())
upvoteComment opts Comment{..} = do
  let CommentID cid = commentID
      R subr = subreddit
  case optCredentials opts of
    Nothing -> do
      logFmt Warn
        "Cannot upvote comment #{} in /r/{} due to lack of credentials"
        (cid, subr)
      return $ Left $ APIError CredentialsError
    _ -> do
      logFmt Info "Upvoting comment #{} in /r/{} [{}] -> [{}]"
        (cid, subr, showScore score, showScore $ (+1) <$> score)
      result <- runReddit opts $ R.upvoteComment commentID
      case result of
        Left err ->
          logFmt Warn "Failed to upvote comment #{}: {}" (cid, tshow err)
        Right _ -> logFmt Debug "Successfully upvoted comment #{} in /r/{}"
                                (cid, subr)
      return result
  where
  -- Current score may be absent in the Comment record
  showScore = fromMaybe "?" . (tshow <$>)


-- Utilities

-- | Run a RedditT action using program Options.
upvoteComment opts Comment{..} = do
  let CommentID cid = commentID
      R subr = subreddit
  case optCredentials opts of
    Nothing -> do
      logFmt Warn
        "Cannot upvote comment #{} in /r/{} due to lack of credentials"
        (cid, subr)
      return $ Left $ APIError CredentialsError
    _ -> do
      logFmt Info "Upvoting comment #{} in /r/{} [{}] -> [{}]"
        (cid, subr, showScore score, showScore $ (+1) <$> score)
      result <- runReddit opts $ R.upvoteComment commentID
      case result of
        Left err ->
          logFmt Warn "Failed to upvote comment #{}: {}" (cid, tshow err)
        Right _ -> logFmt Debug "Successfully upvoted comment #{} in /r/{}"
                                (cid, subr)
      return result
  where
  -- Current score may be absent in the Comment record
  showScore = fromMaybe "?" . (tshow <$>)


-- Utilities

-- | Run a RedditT action using program Options.