module Web.Slack.State where
import Control.Applicative
import Control.Lens
import Control.Monad.IO.Class
import qualified Control.Monad.State as S
import qualified Network.WebSockets as WS
import Web.Slack.Types
import Web.Slack.WebAPI (SlackConfig)
import Prelude
newtype Slack s a = Slack {runSlack :: S.StateT (SlackState s) IO a}
deriving (Monad, Functor, Applicative, S.MonadState (SlackState s), MonadIO)
type SlackBot s = Event -> Slack s ()
data Metainfo = Meta
{ _metaConnection :: WS.Connection
, _msgCounter :: Int
}
instance Show Metainfo where
show (Meta _ b) = "Metainfo: " ++ "<connection> " ++ show b
data SlackState s = SlackState
{ _meta :: Metainfo
, _session :: SlackSession
, _userState :: s
, _config :: SlackConfig
} deriving Show
makeLenses ''SlackState
makeLenses ''Metainfo
slackLog :: Show a => a -> MonadIO m => m ()
slackLog = liftIO . print
counter :: Slack s Int
counter = meta . msgCounter <<+= 1
connection :: Lens' (SlackState s) WS.Connection
connection = meta . metaConnection