diff options
author | Julien Dessaux | 2010-07-03 21:26:00 +0200 |
---|---|---|
committer | Julien Dessaux | 2010-07-03 22:40:17 +0200 |
commit | 11c2c16835b3e8368be77ccc5b7ddf949021eccd (patch) | |
tree | 7733132ee370335156219ff6eb4f0ef2dbd1c8ff /HsbotMaster/Hsbot/Types.hs | |
parent | Wrote most of the resume code for the core and the irc plugin. (diff) | |
download | hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.tar.gz hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.tar.bz2 hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.zip |
Moved files around as a preliminary for architectural changes.
Diffstat (limited to 'HsbotMaster/Hsbot/Types.hs')
-rw-r--r-- | HsbotMaster/Hsbot/Types.hs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/HsbotMaster/Hsbot/Types.hs b/HsbotMaster/Hsbot/Types.hs new file mode 100644 index 0000000..66b4d6b --- /dev/null +++ b/HsbotMaster/Hsbot/Types.hs @@ -0,0 +1,75 @@ +module Hsbot.Types + ( Bot + , BotMsg (..) + , BotResumeData + , BotState (..) + , BotStatus (..) + , ExitMsg (..) + , Msg (..) + , Plugin + , PluginState (..) + , RebootMsg (..) + , ResumeData + , ResumeMsg (..) + ) where + +import Control.Concurrent +import Control.Monad.State +import qualified Data.Map as M +import Data.Time +import System.IO + +import Hsbot.Config + +-- | The Bot monad +type Bot = StateT BotState IO + +-- | An Hsbot state +data BotState = BotState + { botStartTime :: UTCTime -- the bot's uptime + , botPlugins :: M.Map String (PluginState, MVar (), ThreadId) -- Loaded plugins + , botChan :: Chan BotMsg -- the bot's communication channel + , botConfig :: [BotConfig] -- the bot's starting config + , botResumeData :: MVar BotResumeData -- the necessary data to resume the bot's operations on reboot + } + +-- | how we exit from the botLoop +data BotStatus = BotExit | BotReboot | BotContinue deriving (Eq) + +-- | Types to factorise resume data +type ResumeData = M.Map String String +type BotResumeData = M.Map String ResumeData + +-- | The Plugin monad +type Plugin = StateT PluginState IO + +-- | A plugin state +data PluginState = PluginState + { pluginName :: String -- The plugin's name + , pluginChan :: Chan BotMsg -- The plugin chan + , pluginHandles :: M.Map String Handle -- the plugins's handles + } + +-- | A hsbot message +data Msg = Msg + { msgType :: String -- the message type + , msgFrom :: String -- who issues it + , msgTo :: String -- who it is destinated to + , msgStuff :: String -- the message to be transfered + } deriving (Show) + +data ResumeMsg = ResMsg + { resMsgFrom :: String + , resMsgData :: ResumeData + } deriving (Show) + +data RebootMsg = RebootMsg + { rebMsgFrom :: String + } deriving (Show) + +data ExitMsg = ExitMsg + { exiMsgFrom :: String + } deriving (Show) + +data BotMsg = IntMsg Msg | UpdMsg ResumeMsg | RebMsg RebootMsg | ExiMsg ExitMsg deriving (Show) + |