package calculon
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=4d34a4d99816effb06954ea283be0e5b
sha512=b9ec29bc0fc40774075b528524bd191b4dde013465805499b6f49b9dd070b404b34364c77ef994f0bc01c9213f1f7c0a4aa749f84f8de55de810088499b29cfc
doc/calculon/Calculon/Plugin/index.html
Module Calculon.Plugin
Source
Plugins
A plugin is a bunch of commands, and optionally some disk-backed state. It will register its commands to the core loop
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;
(*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 db_backed = private {
commands : Calculon.DB_utils.DB.db -> Command.t list;
(*Commands parametrized by some (mutable) state, with the ability to trigger a signal
*)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.
*)on_msg : Calculon.DB_utils.DB.db -> (Core.t -> Irc_message.t -> unit Lwt.t) list;
(*Executed on each incoming message
*)stop : Calculon.DB_utils.DB.db -> unit Lwt.t;
(*Stop the plugin. There is no need to close the DB connection.
*)
}
A single plugin
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.