package calculon

  1. Overview
  2. Docs

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.t
type action =
  1. | Require_reload
    (*

    Require that we reload everything from on-disk state

    *)
  2. | Require_save
    (*

    Require that the state be saved

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

A stateful plugin, using a persistent state 'st

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

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

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

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

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

    Executed on each incoming message

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

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

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

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

    *)
  6. 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 db_backed = private {
  1. commands : Calculon.DB_utils.DB.db -> Command.t list;
    (*

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

    *)
  2. prepare_db : Calculon.DB_utils.DB.db -> unit;
    (*

    Prepare database (create tables, etc.). Must be idempotent as it'll be called every time the plugin is initialized.

    *)
  3. on_msg : Calculon.DB_utils.DB.db -> (Core.t -> Irc_message.t -> unit Lwt.t) list;
    (*

    Executed on each incoming message

    *)
  4. stop : Calculon.DB_utils.DB.db -> unit Lwt.t;
    (*

    Stop the plugin. There is no need to close the DB connection.

    *)
}
type t = private
  1. | Stateful of stateful
  2. | Stateless of Command.t list
  3. | DB_backed of db_backed

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.

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) -> ?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.

val db_backed : commands:(Calculon.DB_utils.DB.db -> Command.t list) -> prepare_db:(Calculon.DB_utils.DB.db -> unit) -> ?on_msg: (Calculon.DB_utils.DB.db -> (Core.t -> Irc_message.t -> unit Lwt.t) list) -> ?stop:(Calculon.DB_utils.DB.db -> unit Lwt.t) -> unit -> t

Make a stateful plugin that is backed by some tables in the database. See db_backed for more details.

  • since NEXT_RELEASE
module Set : sig ... end
OCaml

Innovation. Community. Security.