Improved message utilities.
This commit is contained in:
parent
864a364da9
commit
7e89b50bfe
1 changed files with 11 additions and 7 deletions
|
@ -1,21 +1,25 @@
|
||||||
module Hsbot.Message
|
module Hsbot.Message
|
||||||
( readMsg
|
( answerMsg
|
||||||
|
, readMsg
|
||||||
, writeMsg
|
, writeMsg
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
import qualified Network.IRC as IRC
|
||||||
|
|
||||||
import Hsbot.Types
|
import Hsbot.Types
|
||||||
|
|
||||||
-- Plugin Utils
|
-- Plugin Utils
|
||||||
readMsg :: Plugin IO (Message)
|
readMsg :: Plugin IO (Message)
|
||||||
readMsg = do
|
readMsg = gets pluginChan >>= liftIO . readChan >>= return
|
||||||
chan <- gets pluginChan
|
|
||||||
liftIO $ readChan chan >>= return
|
|
||||||
|
|
||||||
writeMsg :: Message -> Plugin IO ()
|
writeMsg :: Message -> Plugin IO ()
|
||||||
writeMsg msg = do
|
writeMsg msg = gets pluginMaster >>= liftIO . flip writeChan msg
|
||||||
chan <- gets pluginMaster
|
|
||||||
liftIO $ writeChan chan 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 ()
|
||||||
|
|
||||||
|
|
Reference in a new issue