calculon

Library for writing IRC bots in OCaml and a collection of plugins
IN THIS PACKAGE
Module Calculon . Plugin

Plugins

A plugin is a bunch of commands, and optionally some disk-backed state. It will register its commands to the core loop

type json = Yojson.Safe.json
type action =
| Require_reload(*

Require that we reload everything from on-disk state

*)
| Require_save(*

Require that the state be saved

*)
type action_callback = action Signal.Send_ref.t
type stateful =
| St : 'st stateful_ -> stateful

A stateful plugin, using a persistent state 'st

and 'st stateful_ = private {
name : string;(*

Namespace for storing state. Must be distinct for every plugin.

*)
commands : 'st -> Command.t list;(*

Commands parametrized by some (mutable) state, with the ability to trigger a signal

*)
on_msg : 'st -> ( Core.t -> Irc_message.t -> unit Lwt.t ) list;(*

Executed on each incoming message

*)
to_json : 'st -> json option;(*

How to serialize (part of) the state into JSON, if need be.

*)
of_json : action_callback -> json option -> ( 'st, string ) Result.result Lwt.t;(*

How to deserialize the state. None is passed for a fresh initialization.

*)
stop : 'st -> unit Lwt.t;(*

Stop the plugin. It is NOT the responsibility of this command to save the state, as the core engine will have called to_json before.

*)
}
type t =
| Stateful of stateful
| Stateless of Command.t list

A single plugin

type plugin = t
val of_cmd : Command.t -> t

Stateless plugin with 1 command.

val of_cmds : Command.t list -> t

Stateless plugin with several commands.

  • raises Invalid_argument

    if the list is empty

val stateful : name:string -> commands:( 'st -> Command.t list ) -> ?on_msg:( 'st -> ( Core.t -> Irc_message.t -> unit Lwt.t ) list ) -> to_json:( 'st -> json option ) -> of_json: ( action_callback -> json option -> ( 'st, string ) Result.result Lwt.t ) -> ?stop:( 'st -> unit Lwt.t ) -> unit -> t

Make a stateful plugin using the given name (for prefixing its storage; this should be unique) and ways to serialize state to Json, deserialize state from Json, and building commands from the state. See stateful_ for more details on each field.

module Set : sig ... end