Giter Site home page Giter Site logo

ocaml-irc-client's Introduction

IRC client library, supporting Lwt and Unix blocking IO.

Build status Coverage Status API reference

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

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.

ocaml-irc-client's People

Contributors

artob avatar berke avatar c-cube avatar diethylamine avatar fardalem avatar g2p avatar gchelfi avatar johnelse avatar kit-ty-kate avatar lyokovic avatar reynir avatar simonjbeaumont avatar whitequark avatar zapashcanon avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.