Added message command for inter handler messaging

This commit is contained in:
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 = readChan
sendMessage :: Chan Line -> Message -> IO ()
sendMessage = (. Line) . writeChan
listenerLoop :: Chan Line -> Chan Cmd -> Int -> IRC ()
listenerLoop lineChan commandChan idleFor = do
status <- get
@ -122,7 +125,9 @@ listenerLoop lineChan commandChan idleFor = do
mCmd <- runMsgHandler msgHandler botConfig message
case mCmd of
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@BotConfig { .. } =

View File

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

View File

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