https://github.com/johnelse/ocaml-irc-client
OCaml IRC client library
https://github.com/johnelse/ocaml-irc-client
Last synced: 3 months ago
JSON representation
OCaml IRC client library
- Host: GitHub
- URL: https://github.com/johnelse/ocaml-irc-client
- Owner: johnelse
- License: mit
- Created: 2013-03-30T10:12:59.000Z (almost 13 years ago)
- Default Branch: main
- Last Pushed: 2023-06-30T21:18:20.000Z (over 2 years ago)
- Last Synced: 2025-05-07T17:05:25.784Z (8 months ago)
- Language: OCaml
- Size: 333 KB
- Stars: 51
- Watchers: 5
- Forks: 15
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
- awesome-list - ocaml-irc-client
README
IRC client library, supporting Lwt and Unix blocking IO.
[](https://github.com/johnelse/ocaml-irc-client/actions)
[](https://coveralls.io/r/johnelse/ocaml-irc-client?branch=master)
[](https://johnelse.github.io/ocaml-irc-client)
Build dependencies
------------------
* [lwt](http://ocsigen.org/lwt/) (optional)
* [dune](https://github.com/ocaml/dune)
* [logs](https://github.com/dbuenzli/logs)
To run tests:
* [ounit](http://ounit.forge.ocamlcore.org/)
The latest tagged version is available via [opam](http://opam.ocaml.org): `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:
```ocaml
open Lwt
module C = Irc_client_lwt
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 callback _connection result =
let open Irc_message in
match result with
| Result.Ok msg ->
Lwt_io.printf "Got message: %s\n" (to_string msg)
| Result.Error e ->
Lwt_io.printl e
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 at `examples/example1.ml`; enable its compilation
with `./configure --enable-examples --enable-lwt`.