package calculon

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

Install

Dune Dependency

Authors

Maintainers

Sources

0.2.tar.gz
sha256=c41f1fc7e90a140627c1bc1cb268976fc11ce43fad3725de34096843e83406b8
md5=df6692d28d27ae6f87c773739b758fb8

Description

The core library is called calculon and revolves around the concept of commands that react to user messages. See the README for a small tutorial on how to write your own plugins.

Tags

irc bot factoids

Published: 26 Mar 2018

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

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;
  my_own_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.


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

let plugin_hello = 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. re
  2. stringext
  3. ISO8601
  4. containers >= "1.0" & < "2.1"
  5. yojson
  6. tls < "1.0.0"
  7. irc-client >= "0.4.0" & < "0.6.0"
  8. lwt
  9. result
  10. base-unix
  11. base-bytes
  12. jbuilder >= "1.0+beta7"
  13. ocaml >= "4.02.0"

Dev Dependencies

None

Used by (1)

  1. calculon-web < "0.4"

Conflicts

None

OCaml

Innovation. Community. Security.