module Network.FastIRC.IO
( hGetIRCLine,
hGetMessage,
hPutCommand,
hPutMessage
)
where
import qualified Data.ByteString.Char8 as B
import Network.FastIRC.Messages
import Network.FastIRC.Types
import Network.FastIRC.Utils
import System.IO
hGetIRCLine :: Handle -> IO MsgString
hGetIRCLine h = getl B.empty
where
getl :: MsgString -> IO MsgString
getl buf = do
c <- hGetChar h
if isIRCEOLChar c
then return buf
else getl (B.snoc buf c)
hGetMessage :: Handle -> IO Message
hGetMessage h = do
line <- hGetIRCLine h
if B.null line
then hGetMessage h
else
case readMessage line of
Just msg -> return msg
Nothing -> hGetMessage h
hPutCommand :: Handle -> Command -> IO ()
hPutCommand h cmd =
B.hPutStr h $ B.append (showCommand cmd) "\r\n"
hPutMessage :: Handle -> Message -> IO ()
hPutMessage h msg =
B.hPutStr h $ B.append (showMessage msg) "\r\n"