-- | Contains actions for voting on posts and comments. There are functions
--   for upvoting ('upvotePost', 'upvoteComment'), downvoting ('downvotePost',
--   'downVoteComment') as well as removing votes that have already been cast
--   ('unvotePost', 'unvoteComment').
--
--   Please note that automated voting (i.e. by a bot, as opposed to being
--   specifically ordered to by a person) is strictly against the Reddit rules,
--   and is a very effective way of getting your bot shadowbanned.
module Reddit.Actions.Voting
  ( upvotePost
  , downvotePost
  , unvotePost
  , upvoteComment
  , downvoteComment
  , unvoteComment ) where

import Reddit.Routes.Vote (VoteDirection(..))
import Reddit.Types
import Reddit.Types.Empty
import Reddit.Types.Reddit
import qualified Reddit.Routes as Route

vote :: (Monad m, Thing a) => VoteDirection -> a -> RedditT m ()
vote :: VoteDirection -> a -> RedditT m ()
vote VoteDirection
dir = RedditT m Empty -> RedditT m ()
forall (m :: * -> *). Monad m => m Empty -> m ()
nothing (RedditT m Empty -> RedditT m ())
-> (a -> RedditT m Empty) -> a -> RedditT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Route -> RedditT m Empty
forall a (m :: * -> *).
(FromJSON a, Monad m) =>
Route -> RedditT m a
runRoute (Route -> RedditT m Empty) -> (a -> Route) -> a -> RedditT m Empty
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VoteDirection -> a -> Route
forall a. Thing a => VoteDirection -> a -> Route
Route.vote VoteDirection
dir

-- | Upvote a post.
upvotePost :: Monad m => PostID -> RedditT m ()
upvotePost :: PostID -> RedditT m ()
upvotePost = VoteDirection -> PostID -> RedditT m ()
forall (m :: * -> *) a.
(Monad m, Thing a) =>
VoteDirection -> a -> RedditT m ()
vote VoteDirection
UpVote

-- | Downvote a post.
downvotePost :: Monad m => PostID -> RedditT m ()
downvotePost :: PostID -> RedditT m ()
downvotePost = VoteDirection -> PostID -> RedditT m ()
forall (m :: * -> *) a.
(Monad m, Thing a) =>
VoteDirection -> a -> RedditT m ()
vote VoteDirection
DownVote

-- | Remove a vote from a post.
unvotePost :: Monad m => PostID -> RedditT m ()
unvotePost :: PostID -> RedditT m ()
unvotePost = VoteDirection -> PostID -> RedditT m ()
forall (m :: * -> *) a.
(Monad m, Thing a) =>
VoteDirection -> a -> RedditT m ()
vote VoteDirection
RemoveVote

-- | Upvote a comment.
upvoteComment :: Monad m => CommentID -> RedditT m ()
upvoteComment :: CommentID -> RedditT m ()
upvoteComment = VoteDirection -> CommentID -> RedditT m ()
forall (m :: * -> *) a.
(Monad m, Thing a) =>
VoteDirection -> a -> RedditT m ()
vote VoteDirection
UpVote

-- | Downvote a comment.
downvoteComment :: Monad m => CommentID -> RedditT m ()
downvoteComment :: CommentID -> RedditT m ()
downvoteComment = VoteDirection -> CommentID -> RedditT m ()
forall (m :: * -> *) a.
(Monad m, Thing a) =>
VoteDirection -> a -> RedditT m ()
vote VoteDirection
RemoveVote

-- | Remove a previously-cast vote from a comment.
unvoteComment :: Monad m => CommentID -> RedditT m ()
unvoteComment :: CommentID -> RedditT m ()
unvoteComment = VoteDirection -> CommentID -> RedditT m ()
forall (m :: * -> *) a.
(Monad m, Thing a) =>
VoteDirection -> a -> RedditT m ()
vote VoteDirection
DownVote