summaryrefslogtreecommitdiff
path: root/Hsbot/Message.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-24 23:50:59 +0200
committerJulien Dessaux2010-05-24 23:52:47 +0200
commit8b33600f3818edd9aa9dedfa7a9a03d6e2af3276 (patch)
tree50a8ae73d0c67df2f9349d96fd47b65a10244185 /Hsbot/Message.hs
parentImplemented ircbot update messages. (diff)
downloadhsbot-8b33600f3818edd9aa9dedfa7a9a03d6e2af3276.tar.gz
hsbot-8b33600f3818edd9aa9dedfa7a9a03d6e2af3276.tar.bz2
hsbot-8b33600f3818edd9aa9dedfa7a9a03d6e2af3276.zip
Implemented update message handling in the bot's core.
Diffstat (limited to '')
-rw-r--r--Hsbot/Message.hs40
1 files changed, 29 insertions, 11 deletions
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 }