summaryrefslogtreecommitdiff
path: root/Hsbot/Message.hs
blob: f38438f110d1e9266c687c2ca01f09434807dc0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Hsbot.Message
    ( 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 (BotStatus)
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 ()
      return BotContinue
processInternalMessage _ = return BotContinue

processCoreMessage :: Msg -> Bot (BotStatus)
processCoreMessage msg = do
    case msgType msg of
        "REBOOT" -> return BotReboot
        _        -> return BotContinue