summaryrefslogtreecommitdiff
path: root/Hsbot
diff options
context:
space:
mode:
authorJulien Dessaux2011-04-30 02:24:43 +0200
committerJulien Dessaux2011-05-01 03:28:28 +0200
commit7e89b50bfe019462a5b1f980dc722a65e5a56992 (patch)
treeb5579eb3cfb99d9a8b96dae84c98dc5a11a604a9 /Hsbot
parentSome API refactoring. (diff)
downloadhsbot-7e89b50bfe019462a5b1f980dc722a65e5a56992.tar.gz
hsbot-7e89b50bfe019462a5b1f980dc722a65e5a56992.tar.bz2
hsbot-7e89b50bfe019462a5b1f980dc722a65e5a56992.zip
Improved message utilities.
Diffstat (limited to '')
-rw-r--r--Hsbot/Message.hs18
1 files changed, 11 insertions, 7 deletions
diff --git a/Hsbot/Message.hs b/Hsbot/Message.hs
index 067a740..e95c3e7 100644
--- a/Hsbot/Message.hs
+++ b/Hsbot/Message.hs
@@ -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 ()