summaryrefslogtreecommitdiff
path: root/Hsbot/IRCParser.hs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Hsbot/Irc/Message.hs (renamed from Hsbot/IRCParser.hs)30
1 files changed, 26 insertions, 4 deletions
diff --git a/Hsbot/IRCParser.hs b/Hsbot/Irc/Message.hs
index d284377..e92a9d0 100644
--- a/Hsbot/IRCParser.hs
+++ b/Hsbot/Irc/Message.hs
@@ -1,5 +1,8 @@
-module Hsbot.IRCParser
- ( ParseError
+module Hsbot.Irc.Message
+ ( IrcBotMsg (..)
+ , IrcCmd (..)
+ , IrcMsg (..)
+ , emptyIrcMsg
, parseIrcMsg
, serializeIrcMsg
) where
@@ -7,7 +10,26 @@ module Hsbot.IRCParser
import Control.Monad.Identity
import Text.Parsec
-import Hsbot.Types
+-- | An IRC message
+data IrcMsg = IrcMsg
+ { ircMsgPrefix :: Maybe String -- the message prefix
+ , ircMsgCommand :: String -- the message command
+ , ircMsgParameters :: [String] -- the message parameters
+ } deriving (Show)
+
+emptyIrcMsg :: IrcMsg
+emptyIrcMsg = IrcMsg Nothing "" []
+
+-- | An internal command
+data IrcCmd = IrcCmd
+ { ircCmdCmd :: String -- the internal command
+ , ircCmdFrom :: String -- who issues it
+ , ircCmdTo :: String -- who it is destinated to
+ , ircCmdMsg :: String -- the message to be transfered
+ , ircCmdBotMsg :: IrcMsg -- An IrcMsg attached to the command
+ } deriving (Show)
+
+data IrcBotMsg = InIrcMsg IrcMsg | OutIrcMsg IrcMsg | IntIrcCmd IrcCmd deriving (Show)
-- | Parses an IrcInput
parseIrcMsg :: String -> Either ParseError IrcMsg
@@ -38,7 +60,7 @@ pLongParam = char ':' >> (many1 (noneOf "\r"))
pShortParam :: ParsecT String u Identity [Char]
pShortParam = many1 (noneOf " \r")
--- |Serialize an IRC message to a string.
+-- | Serialize an IRC message to a string.
serializeIrcMsg :: IrcMsg -> String
serializeIrcMsg (IrcMsg pfx cmd params) = pfxStr ++ cmd ++ paramStr
where pfxStr = case pfx of