-- | Contains Captcha-related actions. Reddit sometimes requests Captchas in order
--   to prevent spambots, and you can use this module to get more info on them.
--   Unfortunately the library doesn't yet support answering Captchas on a widespread
--   scale, and you have to use slightly modified variants of other functions to
--   convince Reddit that you aren't a robot.
module Reddit.Actions.Captcha
  ( needsCaptcha
  , newCaptcha ) where

import Reddit.Types.Captcha
import Reddit.Types.Reddit
import qualified Reddit.Routes.Captcha as Route

-- | Find out if the account currently logged in requires a captcha to be submitted for
--   certain requests (like sending a private message or submitting a post).
needsCaptcha :: Monad m => RedditT m Bool
needsCaptcha :: RedditT m Bool
needsCaptcha = Route -> RedditT m Bool
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute Route
Route.needsCaptcha

-- | Returns the ID of a captcha to be completed (the image for which can be found at
--   <http://reddit.com/captcha/$CAPTCHA_ID>)
newCaptcha :: Monad m => RedditT m CaptchaID
newCaptcha :: RedditT m CaptchaID
newCaptcha = do
  POSTWrapped CaptchaID
c <- Route -> RedditT m (POSTWrapped CaptchaID)
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute Route
Route.newCaptcha
  CaptchaID -> RedditT m CaptchaID
forall (m :: * -> *) a. Monad m => a -> m a
return CaptchaID
c