Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
OCaml IRC client library
OCaml
branch: master
Failed to load latest commit information.
doc Add docs generation
examples Open Lwt rather than Io in the example code
lib Minor code simplification in connect_by_name
lwt Implement send_notice.
test Add parser tests
unix Add send_notice to irc_client_unix.mli
.gitignore Update .gitignore
.merlin Update .merlin
.ocamlinit .ocamlinit file
.travis-ci.sh Add docs build to travis script
.travis.yml
ChangeLog Update ChangeLog
LICENSE Add MIT license
MAINTAINERS Add MAINTAINERS file
Makefile Build examples as part of default make target
README.md Update README.md
_oasis Example 1 depends on Lwt
_tags Update to OASIS 0.4.4
myocamlbuild.ml Update to OASIS 0.4.4
setup.ml Example 1 depends on Lwt

README.md

IRC client library, supporting Lwt and Unix blocking IO.

Build status

Build dependencies

The latest tagged version is available via opam: opam install irc-client

Usage

Simple bot which connects to a channel, sends a message, and then logs all messages in that channel to stdout:

open Lwt
module C = Irc_client_lwt.Client

let host = "localhost"
let port = 6667
let realname = "Demo IRC bot"
let nick = "demoirc"
let username = nick
let channel = "#demo_irc"
let message = "Hello, world!  This is a test from ocaml-irc-client"

let string_opt_to_string = function
  | None -> "None"
  | Some s -> Printf.sprintf "Some %s" s

let string_list_to_string string_list =
  Printf.sprintf "[%s]" (String.concat "; " string_list)

let callback ~connection ~result =
  let open Irc_message in
  match result with
  | Message {prefix=prefix; command=command; params=params; trail=trail} ->
    Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n"
      (string_opt_to_string prefix)
      command
      (string_list_to_string params)
      (string_opt_to_string trail)
  | Parse_error (raw, error) ->
    Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error

let lwt_main =
  Lwt_unix.gethostbyname host
  >>= fun he -> C.connect ~addr:(he.Lwt_unix.h_addr_list.(0))
                  ~port ~username ~mode:0 ~realname ~nick ()
  >>= fun connection -> Lwt_io.printl "Connected"
  >>= fun () -> C.send_join ~connection ~channel
  >>= fun () -> C.send_privmsg ~connection ~target:channel ~message
  >>= fun () -> C.listen ~connection ~callback
  >>= fun () -> C.send_quit ~connection

let _ = Lwt_main.run lwt_main

Compile the above with:

ocamlfind ocamlopt -package irc-client.lwt -linkpkg code.ml

Alternatively, you can find it under the examples/ directory as exampel1.ml; enable its compilation during config time with --enable-examples.

Something went wrong with that request. Please try again.