{-# LANGUAGE TemplateHaskell #-}
module Calamity.Cache.Eff
( CacheEff(..)
, setBotUser
, updateBotUser
, getBotUser
, setGuild
, updateGuild
, getGuild
, delGuild
, setDM
, updateDM
, getDM
, delDM
, setUser
, updateUser
, getUser
, delUser
, setUnavailableGuild
, isUnavailableGuild
, delUnavailableGuild
, setMessage
, updateMessage
, getMessage
, delMessage ) where
import Calamity.Internal.Utils
import Calamity.Types.Model.Channel
import Calamity.Types.Model.Guild
import Calamity.Types.Model.User
import Calamity.Types.Snowflake
import Polysemy
import qualified Polysemy as P
data CacheEff m a where
SetBotUser :: User -> CacheEff m ()
GetBotUser :: CacheEff m (Maybe User)
SetGuild :: Guild -> CacheEff m ()
GetGuild :: Snowflake Guild -> CacheEff m (Maybe Guild)
DelGuild :: Snowflake Guild -> CacheEff m ()
SetDM :: DMChannel -> CacheEff m ()
GetDM :: Snowflake DMChannel -> CacheEff m (Maybe DMChannel)
DelDM :: Snowflake DMChannel -> CacheEff m ()
SetUser :: User -> CacheEff m ()
GetUser :: Snowflake User -> CacheEff m (Maybe User)
DelUser :: Snowflake User -> CacheEff m ()
SetUnavailableGuild :: Snowflake Guild -> CacheEff m ()
IsUnavailableGuild :: Snowflake Guild -> CacheEff m Bool
DelUnavailableGuild :: Snowflake Guild -> CacheEff m ()
SetMessage :: Message -> CacheEff m ()
GetMessage :: Snowflake Message -> CacheEff m (Maybe Message)
DelMessage :: Snowflake Message -> CacheEff m ()
makeSem ''CacheEff
updateBotUser :: P.Member CacheEff r => (User -> User) -> Sem r ()
updateBotUser f = getBotUser >>= flip whenJust (setBotUser . f)
updateGuild :: P.Member CacheEff r => Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild id f = getGuild id >>= flip whenJust (setGuild . f)
updateDM :: P.Member CacheEff r => Snowflake DMChannel -> (DMChannel -> DMChannel) -> Sem r ()
updateDM id f = getDM id >>= flip whenJust (setDM . f)
updateUser :: P.Member CacheEff r => Snowflake User -> (User -> User) -> Sem r ()
updateUser id f = getUser id >>= flip whenJust (setUser . f)
updateMessage :: P.Member CacheEff r => Snowflake Message -> (Message -> Message) -> Sem r ()
updateMessage id f = getMessage id >>= flip whenJust (setMessage . f)