Browse Source

respond to the rollcall

master
epic morphism 2 years ago
parent
commit
6dcec6758c
  1. 2
      store.ml
  2. 52
      vantabot.ml

2
store.ml

@ -1,4 +1,4 @@
(** top-level function: `register_nick` *)
(** main entry top-level function: `register_nick` *)
module Rwdb = Dokeysto.Db.RW
let get_db (db : string) : Rwdb.t =

52
vantabot.ml

@ -12,9 +12,9 @@ let formatf = Printf.sprintf
let host = ref "localhost"
let port = ref 6697
let realname = ":3"
let nick = ref "vantabot"
let botnick = ref "vantabot"
let channel = ref "#bots"
let username = nick
let username = botnick
let sleeptime = ref 30.
let countdown = ref 5
let db = ref "toke.db"
@ -23,7 +23,7 @@ let options = Arg.align
[ "-host", Arg.Set_string host, " server host name (default: " ^ !host ^ ")"
; "-port", Arg.Set_int port, " server port (default: " ^ string_of_int !port ^ ")"
; "-chan", Arg.Set_string channel, " target channel (default: " ^ !channel ^ ")"
; "-nick", Arg.Set_string nick, " nick prefix (default: " ^ !nick ^ ")"
; "-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 ^ ")"
@ -105,32 +105,30 @@ let handle_toke who conn =
else return ()
else start_toke conn
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>")
(***********************************)
(** * IRC connection handling code *)
(* (\** Join a channel, synchronously *\)
* let wait_for_join conn chan =
* let open Irc_message in
* let m = Lwt_condition.create () in
* let callback _ = function
* | Result.Error e -> logf (formatf "[wait_for_join] Error parsing a message: %s" e)
* | Result.Ok msg ->
* match msg.command with
* | JOIN (_,_) -> Lwt_condition.signal m (); return ()
* | _ -> return ()
* in
* Lwt.async (fun () -> C.listen ~connection:conn ~callback ());
* C.send_join ~connection:conn ~channel:chan
* >>= fun () -> Lwt_condition.wait m *)
let new_channel ~connection ~channel =
C.send_join ~connection ~channel
>>= fun () -> C.send_privmsg ~connection ~target:channel
~message:(bold_text (color_text ~fg:Green ~bg:Black ".420."))
let nick_of_prefix s =
List.hd (String.split_on_char '!' s)
let nick_of_irc_message imsg =
let open Irc_message in
match imsg.prefix with
| None -> None
| Some wh ->
match String.split_on_char '!' wh with
| a::_ -> Some a
| [] -> None
let callback connection result =
let open Irc_message in
@ -141,10 +139,18 @@ let callback connection result =
(match imsg.command with
| PRIVMSG (target, msg) ->
if target = !channel && String.length msg > 4 then
(* INITIATE OR JOIN THE TOKE *)
if String.sub msg 0 5 = "!toke" then
match imsg.prefix with
match nick_of_irc_message imsg with
| None -> return ()
| Some wh -> handle_toke wh connection
(* RESPOND TO ROLLCALL *)
else if msg = (!botnick) ^ ": rollcall" then
match nick_of_irc_message imsg with
| None -> return ()
| Some wh -> handle_toke (nick_of_prefix wh) connection
| Some wh -> rollcall ~who:wh connection
else if msg = "!rollcall" then
rollcall connection
else return ()
else return ()
| _ -> return ())
@ -156,7 +162,7 @@ let lwt_main () =
~after:30
~connect:(fun () ->
logf "Connecting..."
>>= fun () -> C.connect_by_name ~realname:realname ~username:!username ~server:!host ~port:!port ~nick:!nick ()
>>= fun () -> C.connect_by_name ~realname:realname ~username:!username ~server:!host ~port:!port ~nick:!botnick ()
)
~f:(fun connection ->
logf "Connected"

Loading…
Cancel
Save