package calculon

  1. Overview
  2. Docs
Library for writing IRC bots in OCaml and a collection of plugins

Install

Dune Dependency

Authors

Maintainers

Sources

v0.6.tar.gz
md5=16ad257c16f82a2acfab5e10c7c8ef8a
sha512=c460994c0ffabf0d756cdbb0cdd77b99d3b4844f597c894bb2c8ed22d1038b44f1be4d76721a956a76cc953d915fb76324f0fdb385e6a2e531da7fd4cc832836

Description

Tags

irc bot factoids

Published: 17 Dec 2019

README

Calculon

Library for writing IRC bots in OCaml, a collection of plugins, and a dramatic robotic actor. The core library is called calculon.

Build

make build

Introduction to the Code

Let's assume calculon is loaded, via:

# #require "calculon";;

Main

The typical main entry point would look like this. Calculon works by gathering a list of plugins (see the module Plugin), some configuration (see Config) and running the package in a loop using irc-client.


module C = Calculon

let plugins : C.Plugin.t list = [
  C.Plugin_social.plugin;
  C.Plugin_factoids.plugin;
  (* etc. *)
]

let () =
  let conf = C.Config.of_argv () in
  C.Run_main.main conf plugins |> Lwt_main.run

Plugins

A plugin contains a set of commands. A command is is a rule that matches a IRC message with some regex, and decides whether or not to fire with a reply. They are defined in the module Command.

For instance, the following module will reply to messages starting with !hello by replying "hello <sender>". This is a simple command, as the function Command.make_simple indicates: it returns a string option to indicate whether or not to respond to any line starting with !prefix. More elaborate commands are possible using Command.make.


open Calculon

let cmd_hello : Command.t =
  Command.make_simple ~descr:"hello world" ~cmd:"hello" ~prio:10
    (fun (input_msg:Core.privmsg) _ ->
       let who = input_msg.Core.nick in
       Lwt.return (Some ("hello " ^ who))
    )

let plugin_hello : Plugin.t = Plugin.of_cmd cmd_hello

Basic plugins are stateless, built from one or more commands with Plugin.of_cmd and Plugin.of_cmds. Other plugins can be stateful (typically, they can have some persistent state, or more "custom" schemes). The constructor Plugin.stateful is used to make such plugins. All the persistent state is stored in a single json file.

See for instance the existing plugins Plugin_factoids and Plugin_movie to see how to use Plugin.stateful.

Dependencies (13)

  1. ocaml >= "4.03.0"
  2. re >= "1.7.2"
  3. stringext
  4. ISO8601
  5. containers >= "1.2" & < "3.0"
  6. yojson >= "1.6"
  7. logs >= "0.5.0"
  8. irc-client-lwt-ssl
  9. irc-client-lwt
  10. irc-client >= "0.6.0" & < "0.7.0"
  11. lwt
  12. base-unix
  13. dune >= "1.1"

Dev Dependencies (1)

  1. odoc with-doc

Used by (3)

  1. calculon-redis >= "0.6"
  2. calculon-redis-lib >= "0.6"
  3. calculon-web = "0.6"

Conflicts

None

OCaml

Innovation. Community. Security.