summaryrefslogtreecommitdiff
path: root/Hsbot/Message.hs
blob: e95c3e73c4f3ef49375b2c173754b15daf362591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Hsbot.Message
    ( 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 = gets pluginChan >>= liftIO . readChan >>= return

writeMsg :: Message -> Plugin IO ()
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 ()