Added the IRCParser (thx galdor), and PrivMsg handling (simply repeat)
This commit is contained in:
parent
65646eb07f
commit
dfd0b3dcd7
4 changed files with 78 additions and 19 deletions
36
Hsbot/IRCParser.hs
Normal file
36
Hsbot/IRCParser.hs
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Hsbot.IRCParser
|
||||
( IrcMsg (..)
|
||||
, ircParser
|
||||
) where
|
||||
|
||||
--import Text.Parsec
|
||||
import Text.ParserCombinators.Parsec
|
||||
|
||||
-- |An IRC message.
|
||||
data IrcMsg = IrcMsg (Maybe String) String [String] -- (Maybe first statement) cmd [chan, params/sentence]
|
||||
deriving (Show)
|
||||
|
||||
--ircParser :: String -> IrcInput
|
||||
ircParser :: String -> Either ParseError IrcMsg
|
||||
ircParser str = parse pMsg "" str
|
||||
|
||||
pMsg = do
|
||||
pfx <- optionMaybe pPrefix
|
||||
cmd <- pCommand
|
||||
params <- many (char ' ' >> (pLongParam <|> pShortParam))
|
||||
char '\r'
|
||||
eof
|
||||
return $ IrcMsg pfx cmd params
|
||||
|
||||
pPrefix = do
|
||||
char ':'
|
||||
pfx <- many1 (noneOf " ")
|
||||
space
|
||||
return pfx
|
||||
|
||||
pCommand = count 3 digit <|> many1 upper
|
||||
|
||||
pLongParam = char ':' >> (many1 (noneOf "\r"))
|
||||
|
||||
pShortParam = many1 (noneOf " \r")
|
||||
|
Reference in a new issue