summaryrefslogtreecommitdiff
path: root/Hsbot/IRCParser.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-02-04 20:36:58 +0100
committerJulien Dessaux2010-02-04 20:36:58 +0100
commit884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5 (patch)
treec5941649d7fe1ac23d5ee673c240efb8508b3db2 /Hsbot/IRCParser.hs
parentRewrote the whole architecture. (diff)
downloadhsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.tar.gz
hsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.tar.bz2
hsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.zip
Reorganized code and types, changed slightly the architecture.
Diffstat (limited to 'Hsbot/IRCParser.hs')
-rw-r--r--Hsbot/IRCParser.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/Hsbot/IRCParser.hs b/Hsbot/IRCParser.hs
index 5c1034e..ebf8f71 100644
--- a/Hsbot/IRCParser.hs
+++ b/Hsbot/IRCParser.hs
@@ -1,13 +1,13 @@
module Hsbot.IRCParser
( ParseError
, parseIrcMsg
+ , serializeIrcMsg
) where
import Control.Monad.Identity
--- import Data.List
import Text.Parsec
-import Hsbot.Core
+import Hsbot.Types
-- | Parses an IrcInput
parseIrcMsg :: String -> Either ParseError IrcMsg
@@ -38,3 +38,14 @@ pLongParam = char ':' >> (many1 (noneOf "\r"))
pShortParam :: ParsecT String u Identity [Char]
pShortParam = many1 (noneOf " \r")
+-- |Serialize an IRC message to a string.
+serializeIrcMsg :: IrcMsg -> String
+serializeIrcMsg (IrcMsg pfx cmd params) = pfxStr ++ cmd ++ paramStr
+ where pfxStr = case pfx of
+ Nothing -> ""
+ Just pfx' -> ":" ++ pfx' ++ " "
+ paramStr = concat (map paramToStr (init params)
+ ++ [lastParamToStr (last params)])
+ paramToStr p = " " ++ p
+ lastParamToStr p = " :" ++ p
+