fix a stupid `get_command` bug

This commit is contained in:
epic morphism 2019-05-19 12:24:14 +02:00
parent 33974047be
commit 7c18bfb7a2
2 changed files with 9 additions and 3 deletions

View File

@ -41,8 +41,13 @@ module Conn (C: CLIENT with type 'a Io.t = 'a Lwt.t) = struct
match String.split_on_char '!' wh with
| a::_ -> a
| [] -> ""
let register_callback ~prefix ~callback =
callbacks := (prefix,callback)::!callbacks
if List.mem_assoc prefix !callbacks
then
callbacks := (prefix,callback)::List.remove_assoc prefix !callbacks
else
callbacks := (prefix,callback)::!callbacks
let get_command botnick msg pref =
let nl = String.length botnick in
@ -51,7 +56,8 @@ module Conn (C: CLIENT with type 'a Io.t = 'a Lwt.t) = struct
if String.get msg 0 = '!' then
(* If it's a command starting with "!" *)
let msg = String.sub msg 1 (String.length msg - 1) in
if String.length msg >= n then
if String.length msg >= n &&
String.sub msg 0 n = pref then
Some (String.sub msg n (String.length msg - n))
else None
else if String.length msg >= k &&

View File

@ -21,7 +21,7 @@ let countdown = ref 5
let db_file = ref "toke.db"
let smolchannels = ["#tildetown"]
let bigchannels = ["#bots";"#aaa"]
let bigchannels = ["#bots"]
let options = Arg.align
[ "-host", Arg.Set_string host, " server host name (default: " ^ !host ^ ")"