a help command that doesn't suck
This commit is contained in:
parent
6dcec6758c
commit
c69e245edf
8
README
8
README
|
@ -2,13 +2,15 @@ a bot for synchronized tokin'
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
|
||||||
Run the program with `-help` to see the parameters.
|
|
||||||
|
|
||||||
When on IRC, use `!toke` to start a new toking process or join an existing one.
|
When on IRC, use `!toke` to start a new toking process or join an existing one.
|
||||||
|
|
||||||
|
Right now the bot also records statistics into a file, but it doesn't do anything useful with it.
|
||||||
|
|
||||||
BUILDING
|
BUILDING
|
||||||
|
|
||||||
Install the following packages (either from opam or from your distribution):
|
Install the following packages (either from opam or from your distribution):
|
||||||
irc-client-tls, irc-client-lwt, dokeysto
|
irc-client-tls, irc-client-lwt, dokeysto
|
||||||
|
|
||||||
Compile with `make`
|
Compile with `make`.
|
||||||
|
|
||||||
|
Run the program with `-help` to see the parameters.
|
||||||
|
|
19
store.ml
19
store.ml
|
@ -1,7 +1,10 @@
|
||||||
(** main entry top-level function: `register_nick` *)
|
(** main entry top-level function: `register_nick` *)
|
||||||
|
(** TODO: consider storing the Rwdb.t in memory? *)
|
||||||
module Rwdb = Dokeysto.Db.RW
|
module Rwdb = Dokeysto.Db.RW
|
||||||
|
|
||||||
let get_db (db : string) : Rwdb.t =
|
type t = DB of string
|
||||||
|
|
||||||
|
let get_db (DB db : t) : Rwdb.t =
|
||||||
let open Unix in
|
let open Unix in
|
||||||
let already_exists =
|
let already_exists =
|
||||||
try access db [F_OK]; true
|
try access db [F_OK]; true
|
||||||
|
@ -14,15 +17,17 @@ let release_db (h : Rwdb.t) : unit = Rwdb.sync h; Rwdb.close h
|
||||||
|
|
||||||
let try_finalize f x finally y = let res = try f x with exn -> finally y; raise exn in finally y; res
|
let try_finalize f x finally y = let res = try f x with exn -> finally y; raise exn in finally y; res
|
||||||
|
|
||||||
let inc_nick_value (h : Rwdb.t) (nick : string) : unit =
|
let with_db f (db : t) =
|
||||||
|
let h = get_db db in
|
||||||
|
try_finalize f h
|
||||||
|
release_db h
|
||||||
|
|
||||||
|
let inc_nick_value (nick : string) (h : Rwdb.t) : unit =
|
||||||
if Rwdb.mem h nick
|
if Rwdb.mem h nick
|
||||||
then let n = int_of_string (Rwdb.find h nick) in
|
then let n = int_of_string (Rwdb.find h nick) in
|
||||||
Rwdb.replace h nick (string_of_int (n+1))
|
Rwdb.replace h nick (string_of_int (n+1))
|
||||||
else Rwdb.add h nick "1"
|
else Rwdb.add h nick "1"
|
||||||
|
|
||||||
|
let register_nick (nick : string) (db : t) =
|
||||||
let register_nick (db : string) (nick : string) =
|
with_db (inc_nick_value nick) db
|
||||||
let h = get_db db in
|
|
||||||
try_finalize (inc_nick_value h) nick
|
|
||||||
release_db h
|
|
||||||
|
|
||||||
|
|
12
vantabot.ml
12
vantabot.ml
|
@ -1,7 +1,7 @@
|
||||||
(* for tls support replace [Irc_client_lwt] with [Irc_client_tls] *)
|
(* for tls support replace [Irc_client_lwt] with [Irc_client_tls] *)
|
||||||
open Lwt
|
open Lwt
|
||||||
open Irccolors
|
open Irccolors
|
||||||
module C = Irc_client_tls
|
module C = Irc_client_lwt
|
||||||
|
|
||||||
let logf : string -> unit Lwt.t = Lwt_io.printl
|
let logf : string -> unit Lwt.t = Lwt_io.printl
|
||||||
let formatf = Printf.sprintf
|
let formatf = Printf.sprintf
|
||||||
|
@ -10,14 +10,14 @@ let formatf = Printf.sprintf
|
||||||
(** * Options *)
|
(** * Options *)
|
||||||
|
|
||||||
let host = ref "localhost"
|
let host = ref "localhost"
|
||||||
let port = ref 6697
|
let port = ref 6667
|
||||||
let realname = ":3"
|
let realname = ":3"
|
||||||
let botnick = ref "vantabot"
|
let botnick = ref "vantabot"
|
||||||
let channel = ref "#bots"
|
let channel = ref "#bots"
|
||||||
let username = botnick
|
let username = botnick
|
||||||
let sleeptime = ref 30.
|
let sleeptime = ref 30.
|
||||||
let countdown = ref 5
|
let countdown = ref 5
|
||||||
let db = ref "toke.db"
|
let db_file = ref "toke.db"
|
||||||
|
|
||||||
let options = Arg.align
|
let options = Arg.align
|
||||||
[ "-host", Arg.Set_string host, " server host name (default: " ^ !host ^ ")"
|
[ "-host", Arg.Set_string host, " server host name (default: " ^ !host ^ ")"
|
||||||
|
@ -26,7 +26,7 @@ let options = Arg.align
|
||||||
; "-nick", Arg.Set_string botnick, " nick prefix (default: " ^ !botnick ^ ")"
|
; "-nick", Arg.Set_string botnick, " nick prefix (default: " ^ !botnick ^ ")"
|
||||||
; "-sleeptime", Arg.Set_float sleeptime, " time period for joining the toke call, in seconds (default: " ^ string_of_float !sleeptime ^ ")"
|
; "-sleeptime", Arg.Set_float sleeptime, " time period for joining the toke call, in seconds (default: " ^ string_of_float !sleeptime ^ ")"
|
||||||
; "-countdown", Arg.Set_int countdown, " countdown, in seconds (default: " ^ string_of_int !countdown ^ ")"
|
; "-countdown", Arg.Set_int countdown, " countdown, in seconds (default: " ^ string_of_int !countdown ^ ")"
|
||||||
; "-db", Arg.Set_string db, " database file, will be created if does not exist (default: " ^ !db ^ ")"
|
; "-db", Arg.Set_string db_file, " database file, will be created if does not exist (default: " ^ !db_file ^ ")"
|
||||||
]
|
]
|
||||||
|
|
||||||
let sendmsg connection m = C.send_privmsg ~connection ~target:!channel ~message:(color_text ~fg:Green ~bg:Black m)
|
let sendmsg connection m = C.send_privmsg ~connection ~target:!channel ~message:(color_text ~fg:Green ~bg:Black m)
|
||||||
|
@ -47,7 +47,7 @@ let tokeplz () =
|
||||||
"SMOKE NOW " ^ r
|
"SMOKE NOW " ^ r
|
||||||
|
|
||||||
let inc_tokers_count () =
|
let inc_tokers_count () =
|
||||||
List.iter (Store.register_nick !db) !tokers
|
List.iter (fun n -> Store.register_nick n (Store.DB !db_file)) !tokers
|
||||||
|
|
||||||
|
|
||||||
let leaf = [
|
let leaf = [
|
||||||
|
@ -109,7 +109,7 @@ let rollcall ?who conn =
|
||||||
let pref = match who with
|
let pref = match who with
|
||||||
None -> ""
|
None -> ""
|
||||||
| Some n -> n ^ ": " in
|
| Some n -> n ^ ": " in
|
||||||
sendmsg conn (pref ^ "vantabot is a bot for synchronized toking. See <https://tildegit.org/epicmorphism/vantabot>")
|
sendmsg conn (pref ^ "vantabot is a bot for synchronized toking. See <https://tildegit.org/epicmorphism/vantabot>. TL;DR: the only command is !toke")
|
||||||
|
|
||||||
(***********************************)
|
(***********************************)
|
||||||
(** * IRC connection handling code *)
|
(** * IRC connection handling code *)
|
||||||
|
|
Loading…
Reference in New Issue