Copyright | (c) Eric Mertens 2016 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
This module provides a parser and printer for the low-level IRC message format. It handles splitting up IRC commands into the prefix, command, and arguments.
Synopsis
- data RawIrcMsg = RawIrcMsg {
- _msgTags :: [TagEntry]
- _msgPrefix :: Maybe UserInfo
- _msgCommand :: !Text
- _msgParams :: [Text]
- data TagEntry = TagEntry !Text !Text
- rawIrcMsg :: Text -> [Text] -> RawIrcMsg
- msgTags :: Functor f => ([TagEntry] -> f [TagEntry]) -> RawIrcMsg -> f RawIrcMsg
- msgPrefix :: Functor f => (Maybe UserInfo -> f (Maybe UserInfo)) -> RawIrcMsg -> f RawIrcMsg
- msgCommand :: Functor f => (Text -> f Text) -> RawIrcMsg -> f RawIrcMsg
- msgParams :: Functor f => ([Text] -> f [Text]) -> RawIrcMsg -> f RawIrcMsg
- parseRawIrcMsg :: Text -> Maybe RawIrcMsg
- renderRawIrcMsg :: RawIrcMsg -> ByteString
- prefixParser :: Parser UserInfo
- simpleTokenParser :: Parser Text
- asUtf8 :: ByteString -> Text
Low-level IRC messages
RawIrcMsg
breaks down the IRC protocol into its most basic parts.
The "trailing" parameter indicated in the IRC protocol with a leading
colon will appear as the last parameter in the parameter list.
Note that RFC 2812 specifies a maximum of 15 parameters.
This parser is permissive regarding spaces. It aims to parse carefully constructed messages exactly and to make a best effort to recover from extraneous spaces. It makes no effort to validate nicknames, usernames, hostnames, commands, etc. Servers don't all agree on these things.
:prefix COMMAND param0 param1 param2 .. paramN
RawIrcMsg | |
|
Key value pair representing an IRCv3.2 message tag. The value in this pair has had the message tag unescape algorithm applied.
Construct a new RawIrcMsg
without a time or prefix.
msgTags :: Functor f => ([TagEntry] -> f [TagEntry]) -> RawIrcMsg -> f RawIrcMsg Source #
Lens for _msgTags
msgPrefix :: Functor f => (Maybe UserInfo -> f (Maybe UserInfo)) -> RawIrcMsg -> f RawIrcMsg Source #
Lens for _msgPrefix
msgCommand :: Functor f => (Text -> f Text) -> RawIrcMsg -> f RawIrcMsg Source #
Lens for _msgCommand
msgParams :: Functor f => ([Text] -> f [Text]) -> RawIrcMsg -> f RawIrcMsg Source #
Lens for _msgParams
Text format for IRC messages
parseRawIrcMsg :: Text -> Maybe RawIrcMsg Source #
Attempt to split an IRC protocol message without its trailing newline information into a structured message.
renderRawIrcMsg :: RawIrcMsg -> ByteString Source #
Serialize a structured IRC protocol message back into its wire format. This command adds the required trailing newline.
simpleTokenParser :: Parser Text Source #
Take the next space-delimited lexeme
Permissive text decoder
asUtf8 :: ByteString -> Text Source #
Try to decode a message as UTF-8. If that fails interpret it as Windows CP1252 This helps deal with clients like XChat that get clever and otherwise misconfigured clients.