Added message command for inter handler messaging

master
Abhinav Sarkar 2014-05-13 03:21:41 +05:30
parent fea56c17bf
commit e054e51cf8
3 changed files with 11 additions and 1 deletions

View File

@ -80,6 +80,9 @@ readLineLoop mvBotStatus (lineChan, latch) bot@Bot { .. } timeoutDelay = do
readLine :: Chan Line -> IO Line readLine :: Chan Line -> IO Line
readLine = readChan readLine = readChan
sendMessage :: Chan Line -> Message -> IO ()
sendMessage = (. Line) . writeChan
listenerLoop :: Chan Line -> Chan Cmd -> Int -> IRC () listenerLoop :: Chan Line -> Chan Cmd -> Int -> IRC ()
listenerLoop lineChan commandChan idleFor = do listenerLoop lineChan commandChan idleFor = do
status <- get status <- get
@ -122,7 +125,9 @@ listenerLoop lineChan commandChan idleFor = do
mCmd <- runMsgHandler msgHandler botConfig message mCmd <- runMsgHandler msgHandler botConfig message
case mCmd of case mCmd of
Nothing -> return () Nothing -> return ()
Just cmd -> sendCommand commandChan (Cmd cmd) Just cmd -> case cmd of
MessageCmd msg -> sendMessage lineChan msg
_ -> sendCommand commandChan (Cmd cmd)
loadMsgHandlers :: BotConfig -> IO (Map MsgHandlerName MsgHandler) loadMsgHandlers :: BotConfig -> IO (Map MsgHandlerName MsgHandler)
loadMsgHandlers botConfig@BotConfig { .. } = loadMsgHandlers botConfig@BotConfig { .. } =

View File

@ -108,4 +108,8 @@ messageLogger NickMsg { .. } = withLogFile $ \logFile ->
TF.hprint logFile "[{}] ** {} CHANGED NICK TO {}\n" $ TF.hprint logFile "[{}] ** {} CHANGED NICK TO {}\n" $
TF.buildParams (fmtTime msgTime, userNick user, nick) TF.buildParams (fmtTime msgTime, userNick user, nick)
--messageLogger IdleMsg = const . liftIO $ do
-- now <- getCurrentTime
-- return . Just . MessageCmd $
messageLogger _ = const $ return Nothing messageLogger _ = const $ return Nothing

View File

@ -50,6 +50,7 @@ data Command =
| NickCmd | NickCmd
| UserCmd | UserCmd
| JoinCmd | JoinCmd
| MessageCmd Message
deriving (Show, Eq) deriving (Show, Eq)
data BotConfig = BotConfig { server :: !Text data BotConfig = BotConfig { server :: !Text