From 8b33600f3818edd9aa9dedfa7a9a03d6e2af3276 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 24 May 2010 23:50:59 +0200 Subject: Implemented update message handling in the bot's core. --- Hsbot/Message.hs | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'Hsbot/Message.hs') diff --git a/Hsbot/Message.hs b/Hsbot/Message.hs index 83d4c08..d2cb085 100644 --- a/Hsbot/Message.hs +++ b/Hsbot/Message.hs @@ -1,18 +1,36 @@ module Hsbot.Message - ( BotMsg (..) - , Msg (..) - , processInternalMessage + ( processInternalMessage ) where +import Control.Monad.State +import qualified Data.Map as M + import Hsbot.PluginUtils +import Hsbot.Types + +-- | Processes an internal message +processInternalMessage :: BotMsg -> Bot () +processInternalMessage (IntMsg msg) + | msgTo msg == "CORE" = processCoreMessage msg + | otherwise = do + plugins <- gets botPlugins + case M.lookup (msgTo msg) plugins of + Just (plugin, _) -> sendToPlugin (IntMsg msg) plugin + Nothing -> return () +processInternalMessage _ = return () --- | A hsbot message -data Msg = Msg - { msgType :: String -- the message type - , msgFrom :: String -- who issues it - , msgTo :: String -- who it is destinated to - , msgCmd :: String -- the message to be transfered - } deriving (Show) +processCoreMessage :: Msg -> Bot () +processCoreMessage msg = do + case msgCmd msg of + "UPDATE" -> processUpdateCommand msg + _ -> return () -data BotMsg = InMsg Msg | OutMsg Msg | IntMsg Msg deriving (Show) +-- | Process an update command +processUpdateCommand :: Msg -> Bot () +processUpdateCommand msg = do + bot <- get + let oldData = botResumeData bot + from = msgFrom msg + stuff = msgCmd msg + put $ bot { botResumeData = M.insert from stuff oldData } -- cgit v1.2.3