From 884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 4 Feb 2010 20:36:58 +0100 Subject: Reorganized code and types, changed slightly the architecture. --- Hsbot/IRCParser.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Hsbot/IRCParser.hs') 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 + -- cgit v1.2.3