module Needles.Bot.Types (
BotState(..)
, Trigger(..)
, TriggerAct(..)
, Configuration(..)
, MessageType(..)
, MessageInfo(..)
) where
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.State.Strict
import Data.Map (Map)
import Data.Text (Text)
import qualified Network.WebSockets as WS
data BotState =
BotState { bName :: String
, bPass :: String
, bConn :: WS.Connection
, bTriggers :: [Trigger]
, bConfig :: Configuration
, bMessChan :: Text -> IO ()
, bTimestamps :: Map Text Integer
}
data MessageType = MTChat
| MTPm
| MTRaw
| MTBase
| MTUnknown
deriving (Show, Eq)
data MessageInfo = MessageInfo { mType :: MessageType
, what :: Text
, who :: Text
, rank :: Char
, mRoom :: Text
, respond :: forall a b. Text -> TriggerAct a b ()
}
data Trigger =
Trigger { trigTest :: MessageInfo -> Bool
, trigAct :: MessageInfo -> StateT BotState IO (Trigger)
}
data TriggerAct var perma r where
Send :: Text -> TriggerAct a b ()
PrintLn :: Text -> TriggerAct a b ()
GetVar :: TriggerAct a b a
StoreVar :: a -> TriggerAct a b ()
DuraGet :: TriggerAct a b b
DuraStore :: b -> TriggerAct a b ()
DoIO :: IO c -> TriggerAct a b c
Bind :: TriggerAct a b c -> (c -> TriggerAct a b d) -> TriggerAct a b d
Pure :: c -> TriggerAct a b c
instance Functor (TriggerAct a b) where
fmap = liftM
instance Applicative (TriggerAct a b) where
pure = Pure
(<*>) = ap
instance Monad (TriggerAct a b) where
return = Pure
(>>=) = Bind
instance MonadIO (TriggerAct a b) where
liftIO = DoIO
data Configuration =
Configuration { cUsername :: String
, cPassword :: String
, cServer :: String
, cPort :: Int
, cPath :: String
, cRooms :: [String]
, cTriggers :: [Trigger]
}