Browse Source

a help command that doesn't suck

master
epic morphism 2 years ago
parent
commit
c69e245edf
  1. 8
      README
  2. 19
      store.ml
  3. 12
      vantabot.ml

8
README

@ -2,13 +2,15 @@ a bot for synchronized tokin'
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.
Right now the bot also records statistics into a file, but it doesn't do anything useful with it.
BUILDING
Install the following packages (either from opam or from your distribution):
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

@ -1,7 +1,10 @@
(** main entry top-level function: `register_nick` *)
(** TODO: consider storing the Rwdb.t in memory? *)
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 already_exists =
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 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
then let n = int_of_string (Rwdb.find h nick) in
Rwdb.replace h nick (string_of_int (n+1))
else Rwdb.add h nick "1"
let register_nick (db : string) (nick : string) =
let h = get_db db in
try_finalize (inc_nick_value h) nick
release_db h
let register_nick (nick : string) (db : t) =
with_db (inc_nick_value nick) db

12
vantabot.ml

@ -1,7 +1,7 @@
(* for tls support replace [Irc_client_lwt] with [Irc_client_tls] *)
open Lwt
open Irccolors
module C = Irc_client_tls
module C = Irc_client_lwt
let logf : string -> unit Lwt.t = Lwt_io.printl
let formatf = Printf.sprintf
@ -10,14 +10,14 @@ let formatf = Printf.sprintf
(** * Options *)
let host = ref "localhost"
let port = ref 6697
let port = ref 6667
let realname = ":3"
let botnick = ref "vantabot"
let channel = ref "#bots"
let username = botnick
let sleeptime = ref 30.
let countdown = ref 5
let db = ref "toke.db"
let db_file = ref "toke.db"
let options = Arg.align
[ "-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 ^ ")"
; "-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 ^ ")"
; "-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)
@ -47,7 +47,7 @@ let tokeplz () =
"SMOKE NOW " ^ r
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 = [
@ -109,7 +109,7 @@ let rollcall ?who conn =
let pref = match who with
None -> ""
| 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 *)

Loading…
Cancel
Save