respond to the rollcall
This commit is contained in:
parent
a46944e62f
commit
6dcec6758c
2
store.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
|
module Rwdb = Dokeysto.Db.RW
|
||||||
|
|
||||||
let get_db (db : string) : Rwdb.t =
|
let get_db (db : string) : Rwdb.t =
|
||||||
|
|
52
vantabot.ml
52
vantabot.ml
|
@ -12,9 +12,9 @@ let formatf = Printf.sprintf
|
||||||
let host = ref "localhost"
|
let host = ref "localhost"
|
||||||
let port = ref 6697
|
let port = ref 6697
|
||||||
let realname = ":3"
|
let realname = ":3"
|
||||||
let nick = ref "vantabot"
|
let botnick = ref "vantabot"
|
||||||
let channel = ref "#bots"
|
let channel = ref "#bots"
|
||||||
let username = nick
|
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 = ref "toke.db"
|
||||||
|
@ -23,7 +23,7 @@ let options = Arg.align
|
||||||
[ "-host", Arg.Set_string host, " server host name (default: " ^ !host ^ ")"
|
[ "-host", Arg.Set_string host, " server host name (default: " ^ !host ^ ")"
|
||||||
; "-port", Arg.Set_int port, " server port (default: " ^ string_of_int !port ^ ")"
|
; "-port", Arg.Set_int port, " server port (default: " ^ string_of_int !port ^ ")"
|
||||||
; "-chan", Arg.Set_string channel, " target channel (default: " ^ !channel ^ ")"
|
; "-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 ^ ")"
|
; "-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, " database file, will be created if does not exist (default: " ^ !db ^ ")"
|
||||||
|
@ -105,32 +105,30 @@ let handle_toke who conn =
|
||||||
else return ()
|
else return ()
|
||||||
else start_toke conn
|
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 *)
|
(** * 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 =
|
let new_channel ~connection ~channel =
|
||||||
C.send_join ~connection ~channel
|
C.send_join ~connection ~channel
|
||||||
>>= fun () -> C.send_privmsg ~connection ~target:channel
|
>>= fun () -> C.send_privmsg ~connection ~target:channel
|
||||||
~message:(bold_text (color_text ~fg:Green ~bg:Black ".420."))
|
~message:(bold_text (color_text ~fg:Green ~bg:Black ".420."))
|
||||||
|
|
||||||
let nick_of_prefix s =
|
let nick_of_irc_message imsg =
|
||||||
List.hd (String.split_on_char '!' s)
|
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 callback connection result =
|
||||||
let open Irc_message in
|
let open Irc_message in
|
||||||
|
@ -141,10 +139,18 @@ let callback connection result =
|
||||||
(match imsg.command with
|
(match imsg.command with
|
||||||
| PRIVMSG (target, msg) ->
|
| PRIVMSG (target, msg) ->
|
||||||
if target = !channel && String.length msg > 4 then
|
if target = !channel && String.length msg > 4 then
|
||||||
|
(* INITIATE OR JOIN THE TOKE *)
|
||||||
if String.sub msg 0 5 = "!toke" then
|
if String.sub msg 0 5 = "!toke" then
|
||||||
match imsg.prefix with
|
match nick_of_irc_message imsg with
|
||||||
| None -> return ()
|
| None -> return ()
|
||||||
| Some wh -> handle_toke (nick_of_prefix wh) connection
|
| 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 -> rollcall ~who:wh connection
|
||||||
|
else if msg = "!rollcall" then
|
||||||
|
rollcall connection
|
||||||
else return ()
|
else return ()
|
||||||
else return ()
|
else return ()
|
||||||
| _ -> return ())
|
| _ -> return ())
|
||||||
|
@ -156,7 +162,7 @@ let lwt_main () =
|
||||||
~after:30
|
~after:30
|
||||||
~connect:(fun () ->
|
~connect:(fun () ->
|
||||||
logf "Connecting..."
|
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 ->
|
~f:(fun connection ->
|
||||||
logf "Connected"
|
logf "Connected"
|
||||||
|
|
Loading…
Reference in New Issue