irc-core-2.13: IRC core library for glirc

Copyright | (c) Eric Mertens 2016
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Irc.RawIrcMsg

Contents

- Low-level IRC messages
- Text format for IRC messages
- Permissive text decoder

Description

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

data RawIrcMsg Source #

`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

Constructors

RawIrcMsg |

Fields

- _msgTags :: [TagEntry]

  IRCv3.2 message tags

- _msgPrefix :: Maybe UserInfo

  Optional sender of message

- _msgCommand :: !Text

  Command

- _msgParams :: [Text]

  Command parameters

#### Instances

Instances details

Read RawIrcMsg Source # |
Instance details Defined in Irc.RawIrcMsg Methods readsPrec :: Int -> ReadS RawIrcMsg Source # readList :: ReadS [RawIrcMsg] Source # readPrec :: ReadPrec RawIrcMsg Source # readListPrec :: ReadPrec [RawIrcMsg] Source #
Show RawIrcMsg Source # |
Instance details Defined in Irc.RawIrcMsg Methods showsPrec :: Int -> RawIrcMsg -> ShowS Source # show :: RawIrcMsg -> String Source # showList :: [RawIrcMsg] -> ShowS Source #
Eq RawIrcMsg Source # |
Instance details Defined in Irc.RawIrcMsg Methods (==) :: RawIrcMsg -> RawIrcMsg -> Bool Source # (/=) :: RawIrcMsg -> RawIrcMsg -> Bool Source #

data TagEntry Source #

Key value pair representing an IRCv3.2 message tag. The value in this pair has had the message tag unescape algorithm applied.

Constructors

TagEntry !Text !Text |

#### Instances

Instances details

Read TagEntry Source # |
Instance details Defined in Irc.RawIrcMsg Methods readsPrec :: Int -> ReadS TagEntry Source # readList :: ReadS [TagEntry] Source # readPrec :: ReadPrec TagEntry Source # readListPrec :: ReadPrec [TagEntry] Source #
Show TagEntry Source # |
Instance details Defined in Irc.RawIrcMsg Methods showsPrec :: Int -> TagEntry -> ShowS Source # show :: TagEntry -> String Source # showList :: [TagEntry] -> ShowS Source #
Eq TagEntry Source # |
Instance details Defined in Irc.RawIrcMsg Methods (==) :: TagEntry -> TagEntry -> Bool Source # (/=) :: TagEntry -> TagEntry -> Bool Source #

rawIrcMsg Source #

Arguments

:: Text | command
-> [Text] | parameters
-> RawIrcMsg |

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.

prefixParser :: Parser UserInfo Source #

Parse a rendered `UserInfo` token.

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.