<commit_before>{-# LANGUAGE OverloadedStrings #-}
-- -----------------------------------------------------------------------------
-- |
-- Module      :  Network.IRC.Message.Types
-- Copyright   :  (c) <NAME> 2011
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  portable
--
-- Types for working with IRC messages.

module Network.IRC.Message.Types
  (
    Message(..)
  , Command(..)
  , Prefix(..)
  , Params(..)
  ) where

import           Prelude hiding (takeWhile)
import           Control.Applicative hiding (many)
import           Data.Attoparsec
import qualified Data.Attoparsec.Char8 as P8
import           Data.Attoparsec.Char8 (char8)
import Data.Word (Word8)
import qualified Data.ByteString.Char8 as B hiding (map)
import qualified Data.ByteString as BS

data Message = Message !(Maybe Prefix) !Command !Params
  deriving (Eq, Ord, Show)

type User = B.ByteString

data Prefix = PrefixServer !Servername
            | PrefixNick !Nick !(Maybe User) !(Maybe Host)
  deriving (Eq,Ord,Show)

data Command =
    CmdNumericReply Int
  | ADMIN
  | AWAY
  | CONNECT
  | DIE
  | ERROR
  | INFO
  | INVITE
  | ISON
  | JOIN
  | KICK
  | KILL
  | LINKS
  | LIST
  | LUSERS
  | MODE
  | MOTD
  | NAMES
  | NICK
  | NOTICE
  | OPER
  | PART
  | PASS
  | PING
  | PONG
  | PRIVMSG
  | QUIT
  | REHASH
  | RESTART
  | SERVICE
  | SERVLIST
  | SQUERY
  | SQUIT
  | STATS
  | SUMMON
  | TIME
  | TOPIC
  | TRACE
  | USER
  | USERHOST
  | USERS
  | VERSION
  | WALLOPS
  | WHO
  | WHOIS
  | WHOWAS
  deriving (Show,Read,Eq,Ord)

data Params = Params [B.ByteString] (Maybe B.ByteString)
  deriving (Eq,Ord,Show,Read)

type Mask = B.ByteString
type Target = [To]
data To = ToChannel Channel
        | ToUserAtServer User Servername
        | ToNick Nick
        | ToMask Mask

type Channel = B.ByteString
type Servername = Host
type Host = B.ByteString
type Nick = B.ByteString<commit_msg>added type for server replies and errors<commit_after>{-# LANGUAGE OverloadedStrings #-}
-- -----------------------------------------------------------------------------
-- |
-- Module      :  Network.IRC.Message.Types
-- Copyright   :  (c) <NAME> 2011
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  portable
--
-- Types for working with IRC messages.

module Network.IRC.Message.Types
  (
    Message(..)
  , Command(..)
  , Prefix(..)
  , Params(..)
  , NumericReply(..)
  , numericMsg
  ) where

import           Prelude hiding (takeWhile)
import           Control.Applicative hiding (many)
import           Data.Attoparsec
import qualified Data.Attoparsec.Char8 as P8
import           Data.Attoparsec.Char8 (char8)
import Data.Word (Word8)
import qualified Data.ByteString.Char8 as B hiding (map)
import qualified Data.ByteString as BS

data Message = Message !(Maybe Prefix) !Command !Params
  deriving (Eq, Ord, Show)

type User = B.ByteString

data Prefix = PrefixServer !Servername
            | PrefixNick !Nick !(Maybe User) !(Maybe Host)
  deriving (Eq,Ord,Show)

data Command =
    CmdNumericReply Int
  | ADMIN
  | AWAY
  | CONNECT
  | DIE
  | ERROR
  | INFO
  | INVITE
  | ISON
  | JOIN
  | KICK
  | KILL
  | LINKS
  | LIST
  | LUSERS
  | MODE
  | MOTD
  | NAMES
  | NICK
  | NOTICE
  | OPER
  | PART
  | PASS
  | PING
  | PONG
  | PRIVMSG
  | QUIT
  | REHASH
  | RESTART
  | SERVICE
  | SERVLIST
  | SQUERY
  | SQUIT
  | STATS
  | SUMMON
  | TIME
  | TOPIC
  | TRACE
  | USER
  | USERHOST
  | USERS
  | VERSION
  | WALLOPS
  | WHO
  | WHOIS
  | WHOWAS
  deriving (Show,Read,Eq,Ord)

data Params = Params [B.ByteString] (Maybe B.ByteString)
  deriving (Eq,Ord,Show,Read)

type Mask = B.ByteString
type Target = [To]
data To = ToChannel Channel
        | ToUserAtServer User Servername
        | ToNick Nick
        | ToMask Mask

type Channel = B.ByteString
type Servername = Host
type Host = B.ByteString
type Nick = B.ByteString

numericMsg :: Int -> NumericReply
numericMsg 001 = RPL_WELCOME
numericMsg 002 = RPL_YOURHOST
numericMsg 003 = RPL_CREATED
numericMsg 004 = RPL_MYINFO
numericMsg 005 = RPL_BOUNCE
numericMsg 200 = RPL_TRACELINK
numericMsg 201 = RPL_TRACECONNECTING
numericMsg 202 = RPL_TRACEHANDSHAKE
numericMsg 203 = RPL_TRACEUNKNOWN
numericMsg 204 = RPL_TRACEOPERATOR
numericMsg 205 = RPL_TRACEUSER
numericMsg 206 = RPL_TRACESERVER
numericMsg 207 = RPL_TRACESERVICE
numericMsg 208 = RPL_TRACENEWTYPE
numericMsg 209 = RPL_TRACECLASS
numericMsg 210 = RPL_TRACERECONNECT
numericMsg 211 = RPL_STATSLINKINFO
numericMsg 212 = RPL_STATSCOMMANDS
numericMsg 213 = RPL_STATSCLINE
numericMsg 214 = RPL_STATSNLINE
numericMsg 215 = RPL_STATSILINE
numericMsg 216 = RPL_STATSKLINE
numericMsg 217 = RPL_STATSQLINE
numericMsg 218 = RPL_STATSYLINE
numericMsg 219 = RPL_ENDOFSTATS
numericMsg 221 = RPL_UMODEIS
numericMsg 231 = RPL_SERVICEINFO
numericMsg 232 = RPL_ENDOFSERVICES
numericMsg 233 = RPL_SERVICE
numericMsg 234 = RPL_SERVLIST
numericMsg 235 = RPL_SERVLISTEND
numericMsg 242 = RPL_STATSUPTIME
numericMsg 243 = RPL_STATSOLINE
numericMsg 251 = RPL_LUSERCLIENT
numericMsg 252 = RPL_LUSEROP
numericMsg 253 = RPL_LUSERUNKNOWN
numericMsg 254 = RPL_LUSERCHANNELS
numericMsg 255 = RPL_LUSERME
numericMsg 256 = RPL_ADMINME
numericMsg 257 = RPL_ADMINLOC1
numericMsg 258 = RPL_ADMINLOC2
numericMsg 259 = RPL_ADMINEMAIL
numericMsg 263 = RPL_TRYAGAIN
numericMsg 261 = RPL_TRACELOG
numericMsg 262 = RPL_TRACEEND
numericMsg 302 = RPL_USERHOST
numericMsg 303 = RPL_ISON
numericMsg 301 = RPL_AWAY
numericMsg 305 = RPL_UNAWAY
numericMsg 306 = RPL_NOWAWAY
numericMsg 311 = RPL_WHOISUSER
numericMsg 312 = RPL_WHOISSERVER
numericMsg 313 = RPL_WHOISOPERATOR
numericMsg 317 = RPL_WHOISIDLE
numericMsg 318 = RPL_ENDOFWHOIS
numericMsg 319 = RPL_WHOISCHANNELS
numericMsg 314 = RPL_WHOWASUSER
numericMsg 369 = RPL_ENDOFWHOWAS
numericMsg 321 = RPL_LISTSTART
numericMsg 322 = RPL_LIST
numericMsg 323 = RPL_LISTEND
numericMsg 325 = RPL_UNIQOPIS
numericMsg 324 = RPL_CHANNELMODEIS
numericMsg 331 = RPL_NOTOPIC
numericMsg 332 = RPL_TOPIC
numericMsg 341 = RPL_INVITING
numericMsg 342 = RPL_SUMMONING
numericMsg 346 = RPL_INVITELIST
numericMsg 347 = RPL_ENDOFINVITELIST
numericMsg 348 = RPL_EXCEPTLIST
numericMsg 349 = RPL_ENDOFEXCEPTLIST
numericMsg 351 = RPL_VERSION
numericMsg 352 = RPL_WHOREPLY
numericMsg 315 = RPL_ENDOFWHO
numericMsg 353 = RPL_NAMREPLY
numericMsg 366 = RPL_ENDOFNAMES
numericMsg 364 = RPL_LINKS
numericMsg 365 = RPL_ENDOFLINKS
numericMsg 367 = RPL_BANLIST
numericMsg 368 = RPL_ENDOFBANLIST
numericMsg 371 = RPL_INFO
numericMsg 374 = RPL_ENDOFINFO
numericMsg 375 = RPL_MOTDSTART
numericMsg 372 = RPL_MOTD
numericMsg 376 = RPL_ENDOFMOTD
numericMsg 381 = RPL_YOUREOPER
numericMsg 382 = RPL_REHASHING
numericMsg 383 = RPL_YOURESERVICE
numericMsg 391 = RPL_TIME
numericMsg 392 = RPL_USERSSTART
numericMsg 393 = RPL_USERS
numericMsg 394 = RPL_ENDOFUSERS
numericMsg 395 = RPL_NOUSERS
numericMsg 300 = RPL_NONE
numericMsg 316 = RPL_WHOISCHANOP
numericMsg 361 = RPL_KILLDONE
numericMsg 362 = RPL_CLOSING
numericMsg 363 = RPL_CLOSEEND
numericMsg 373 = RPL_INFOSTART
numericMsg 384 = RPL_MYPORTIS
numericMsg 240 = RPL_STATSVLINE
numericMsg 241 = RPL_STATSLLINE
numericMsg 244 = RPL_STATSHLINE
numericMsg 244 = RPL_STATSSLINE
numericMsg 246 = RPL_STATSPING
numericMsg 247 = RPL_STATSBLINE
numericMsg 250 = RPL_STATSDLINE
numericMsg 401 = ERR_NOSUCHNICK
numericMsg 402 = ERR_NOSUCHSERVER
numericMsg 403 = ERR_NOSUCHCHANNEL
numericMsg 404 = ERR_CANNOTSENDTOCHAN
numericMsg 405 = ERR_TOOMANYCHANNELS
numericMsg 406 = ERR_WASNOSUCHNICK
numericMsg 407 = ERR_TOOMANYTARGETS
numericMsg 408 = ERR_NOSUCHSERVICE
numericMsg 409 = ERR_NOORIGIN
numericMsg 411 = ERR_NORECIPIENT
numericMsg 412 = ERR_NOTEXTTOSEND
numericMsg 413 = ERR_NOTOPLEVEL
numericMsg 414 = ERR_WILDTOPLEVEL
numericMsg 415 = ERR_BADMASK
numericMsg 421 = ERR_UNKNOWNCOMMAND
numericMsg 422 = ERR_NOMOTD
numericMsg 423 = ERR_NOADMININFO
numericMsg 424 = ERR_FILEERROR
numericMsg 431 = ERR_NONICKNAMEGIVEN
numericMsg 432 = ERR_ERRONEUSNICKNAME
numericMsg 433 = ERR_NICKNAMEINUSE
numericMsg 436 = ERR_NICKCOLLISION
numericMsg 437 = ERR_UNAVAILRESOURCE
numericMsg 441 = ERR_USERNOTINCHANNEL
numericMsg 442 = ERR_NOTONCHANNEL
numericMsg 443 = ERR_USERONCHANNEL
numericMsg 444 = ERR_NOLOGIN
numericMsg 445 = ERR_SUMMONDISABLED
numericMsg 446 = ERR_USERSDISABLED
numericMsg 451 = ERR_NOTREGISTERED
numericMsg 461 = ERR_NEEDMOREPARAMS
numericMsg 462 = ERR_ALREADYREGISTRED
numericMsg 463 = ERR_NOPERMFORHOST
numericMsg 464 = ERR_PASSWDMISMATCH
numericMsg 465 = ERR_YOUREBANNEDCREEP
numericMsg 466 = ERR_YOUWILLBEBANNED
numericMsg 467 = ERR_KEYSET
numericMsg 471 = ERR_CHANNELISFULL
numericMsg 472 = ERR_UNKNOWNMODE
numericMsg 473 = ERR_INVITEONLYCHAN
numericMsg 474 = ERR_BANNEDFROMCHAN
numericMsg 475 = ERR_BADCHANNELKEY
numericMsg 476 = ERR_BADCHANMASK
numericMsg 477 = ERR_NOCHANMODES
numericMsg 478 = ERR_BANLISTFULL
numericMsg 481 = ERR_NOPRIVILEGES
numericMsg 482 = ERR_CHANOPRIVSNEEDED
numericMsg 483 = ERR_CANTKILLSERVER
numericMsg 484 = ERR_RESTRICTED
numericMsg 485 = ERR_UNIQOPPRIVSNEEDED
numericMsg 491 = ERR_NOOPERHOST
numericMsg 492 = ERR_NOSERVICEHOST
numericMsg 501 = ERR_UMODEUNKNOWNFLAG
numericMsg 502 = ERR_USERSDONTMATCH
numericMsg x   = REP_UNKNOWN x

data NumericReply =
    RPL_WELCOME
  | RPL_YOURHOST
  | RPL_CREATED
  | RPL_MYINFO
  | RPL_BOUNCE
  | RPL_TRACELINK
  | RPL_TRACECONNECTING
  | RPL_TRACEHANDSHAKE
  | RPL_TRACEUNKNOWN
  | RPL_TRACEOPERATOR
  | RPL_TRACEUSER
  | RPL_TRACESERVER
  | RPL_TRACESERVICE
  | RPL_TRACENEWTYPE
  | RPL_TRACECLASS
  | RPL_TRACERECONNECT
  | RPL_STATSLINKINFO
  | RPL_STATSCOMMANDS
  | RPL_STATSCLINE
  | RPL_STATSNLINE
  | RPL_STATSILINE
  | RPL_STATSKLINE
  | RPL_STATSQLINE
  | RPL_STATSYLINE
  | RPL_ENDOFSTATS
  | RPL_UMODEIS
  | RPL_SERVICEINFO
  | RPL_ENDOFSERVICES
  | RPL_SERVICE
  | RPL_SERVLIST
  | RPL_SERVLISTEND
  | RPL_STATSUPTIME
  | RPL_STATSOLINE
  | RPL_LUSERCLIENT
  | RPL_LUSEROP
  | RPL_LUSERUNKNOWN
  | RPL_LUSERCHANNELS
  | RPL_LUSERME
  | RPL_ADMINME
  | RPL_ADMINLOC1
  | RPL_ADMINLOC2
  | RPL_ADMINEMAIL
  | RPL_TRYAGAIN
  | RPL_TRACELOG
  | RPL_TRACEEND
  | RPL_USERHOST
  | RPL_ISON
  | RPL_AWAY
  | RPL_UNAWAY
  | RPL_NOWAWAY
  | RPL_WHOISUSER
  | RPL_WHOISSERVER
  | RPL_WHOISOPERATOR
  | RPL_WHOISIDLE
  | RPL_ENDOFWHOIS
  | RPL_WHOISCHANNELS
  | RPL_WHOWASUSER
  | RPL_ENDOFWHOWAS
  | RPL_LISTSTART
  | RPL_LIST
  | RPL_LISTEND
  | RPL_UNIQOPIS
  | RPL_CHANNELMODEIS
  | RPL_NOTOPIC
  | RPL_TOPIC
  | RPL_INVITING
  | RPL_SUMMONING
  | RPL_INVITELIST
  | RPL_ENDOFINVITELIST
  | RPL_EXCEPTLIST
  | RPL_ENDOFEXCEPTLIST
  | RPL_VERSION
  | RPL_WHOREPLY
  | RPL_ENDOFWHO
  | RPL_NAMREPLY
  | RPL_ENDOFNAMES
  | RPL_LINKS
  | RPL_ENDOFLINKS
  | RPL_BANLIST
  | RPL_ENDOFBANLIST
  | RPL_INFO
  | RPL_ENDOFINFO
  | RPL_MOTDSTART
  | RPL_MOTD
  | RPL_ENDOFMOTD
  | RPL_YOUREOPER
  | RPL_REHASHING
  | RPL_YOURESERVICE
  | RPL_TIME
  | RPL_USERSSTART
  | RPL_USERS
  | RPL_ENDOFUSERS
  | RPL_NOUSERS
  | RPL_NONE
  | RPL_WHOISCHANOP
  | RPL_KILLDONE
  | RPL_CLOSING
  | RPL_CLOSEEND
  | RPL_INFOSTART
  | RPL_MYPORTIS
  | RPL_STATSVLINE
  | RPL_STATSLLINE
  | RPL_STATSHLINE
  | RPL_STATSSLINE
  | RPL_STATSPING
  | RPL_STATSBLINE
  | RPL_STATSDLINE
  | ERR_NOSUCHNICK
  | ERR_NOSUCHSERVER
  | ERR_NOSUCHCHANNEL
  | ERR_CANNOTSENDTOCHAN
  | ERR_TOOMANYCHANNELS
  | ERR_WASNOSUCHNICK
  | ERR_TOOMANYTARGETS
  | ERR_NOSUCHSERVICE
  | ERR_NOORIGIN
  | ERR_NORECIPIENT
  | ERR_NOTEXTTOSEND
  | ERR_NOTOPLEVEL
  | ERR_WILDTOPLEVEL
  | ERR_BADMASK
  | ERR_UNKNOWNCOMMAND
  | ERR_NOMOTD
  | ERR_NOADMININFO
  | ERR_FILEERROR
  | ERR_NONICKNAMEGIVEN
  | ERR_ERRONEUSNICKNAME
  | ERR_NICKNAMEINUSE
  | ERR_NICKCOLLISION
  | ERR_UNAVAILRESOURCE
  | ERR_USERNOTINCHANNEL
  | ERR_NOTONCHANNEL
  | ERR_USERONCHANNEL
  | ERR_NOLOGIN
  | ERR_SUMMONDISABLED
  | ERR_USERSDISABLED
  | ERR_NOTREGISTERED
  | ERR_NEEDMOREPARAMS
  | ERR_ALREADYREGISTRED
  | ERR_NOPERMFORHOST
  | ERR_PASSWDMISMATCH
  | ERR_YOUREBANNEDCREEP
  | ERR_YOUWILLBEBANNED
  | ERR_KEYSET
  | ERR_CHANNELISFULL
  | ERR_UNKNOWNMODE
  | ERR_INVITEONLYCHAN
  | ERR_BANNEDFROMCHAN
  | ERR_BADCHANNELKEY
  | ERR_BADCHANMASK
  | ERR_NOCHANMODES
  | ERR_BANLISTFULL
  | ERR_NOPRIVILEGES
  | ERR_CHANOPRIVSNEEDED
  | ERR_CANTKILLSERVER
  | ERR_RESTRICTED
  | ERR_UNIQOPPRIVSNEEDED
  | ERR_NOOPERHOST
  | ERR_NOSERVICEHOST
  | ERR_UMODEUNKNOWNFLAG
  | ERR_USERSDONTMATCH
  | REP_UNKNOWN Int
  deriving (Show, Read, Eq)
{'fraction_non_alphanumeric': 0.07179074446680081, 'fraction_numerical': 0.04096579476861167, 'mean_word_length': 3.829382044306257, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3488337', 'n_tokens_mistral': 5368, 'n_tokens_neox': 4855, 'n_words': 1024}