package irc-client

  1. Overview
  2. Docs

IRC message parsing.

type command =
  1. | PASS of string
  2. | NICK of string
  3. | USER of string list
    (*

    see rfc

    *)
  4. | OPER of string * string
    (*

    name * password

    *)
  5. | MODE of string * string
    (*

    nick * mode string

    *)
  6. | QUIT of string
    (*

    quit message

    *)
  7. | SQUIT of string * string
    (*

    server * comment

    *)
  8. | JOIN of string list * string list
    (*

    channels * key list

    *)
  9. | JOIN0
    (*

    join 0 (parts all channels)

    *)
  10. | PART of string list * string
    (*

    channels * comment

    *)
  11. | TOPIC of string * string
    (*

    chan * topic

    *)
  12. | NAMES of string list
    (*

    channels

    *)
  13. | LIST of string list
    (*

    channels

    *)
  14. | INVITE of string * string
    (*

    nick * chan

    *)
  15. | KICK of string list * string * string
    (*

    channels * nick * comment

    *)
  16. | PRIVMSG of string * string
    (*

    target * message

    *)
  17. | NOTICE of string * string
    (*

    target * message

    *)
  18. | PING of string
  19. | PONG of string * string
  20. | Other of string * string list
    (*

    other cases

    *)

A type representing an IRC command, following RFC 2812

type t = {
  1. prefix : string option;
  2. command : command;
}

Constructors

val pass : string -> t
val nick : string -> t
val user : username:string -> mode:int -> realname:string -> t
val oper : name:string -> pass:string -> t
val mode : nick:string -> mode:string -> t
val quit : msg:string option -> t
val join : chans:string list -> keys:string list option -> t
val join0 : t
val part : chans:string list -> comment:string option -> t
val topic : chan:string -> topic:string option -> t
val names : chans:string list -> t
val list : chans:string list -> t
val invite : nick:string -> chan:string -> t
val kick : chans:string list -> nick:string -> comment:string option -> t
val privmsg : target:string -> string -> t
val notice : target:string -> string -> t
val ping : string -> t
val pong : middle:string -> trailer:string -> t
val other : cmd:string -> params:string list -> t

Printing

val to_string : t -> string

Format the message into a string that can be sent on IRC

val output : out_channel -> t -> unit
val write_buf : Buffer.t -> t -> unit

Parsing

type 'a or_error = ('a, string) Result.result
type parse_result = t or_error
exception ParseError of string * string
val parse : string -> t or_error

Attempt to parse an IRC message.

val parse_exn : string -> t

parse_exn s returns the parsed message

  • raises ParseError

    if the string is not a proper message

Low level Functions -- testing

val extract_prefix : string -> string option * string

Exposed for testing - not intended for use.

val extract_trail : string -> string * string option

Exposed for testing - not intended for use.

OCaml

Innovation. Community. Security.