Archived
1
0
Fork 0

Improved message utilities.

This commit is contained in:
Julien Dessaux 2011-04-30 02:24:43 +02:00
parent 864a364da9
commit 7e89b50bfe

View file

@ -1,21 +1,25 @@
module Hsbot.Message
( readMsg
( answerMsg
, readMsg
, writeMsg
) where
import Control.Concurrent
import Control.Monad.State
import qualified Network.IRC as IRC
import Hsbot.Types
-- Plugin Utils
readMsg :: Plugin IO (Message)
readMsg = do
chan <- gets pluginChan
liftIO $ readChan chan >>= return
readMsg = gets pluginChan >>= liftIO . readChan >>= return
writeMsg :: Message -> Plugin IO ()
writeMsg msg = do
chan <- gets pluginMaster
liftIO $ writeChan chan msg
writeMsg msg = gets pluginMaster >>= liftIO . flip writeChan msg
answerMsg :: IRC.Message -> String -> Plugin IO ()
answerMsg request msg =
case IRC.msg_params request of
sender:_ -> writeMsg . OutgoingMsg $ IRC.Message Nothing "PRIVMSG" [sender, msg]
[] -> return ()