diff --git a/ocaml/irc.ml b/ocaml/irc.ml index 3a92822..e6ff5b7 100644 --- a/ocaml/irc.ml +++ b/ocaml/irc.ml @@ -4,7 +4,7 @@ module C = Irc_client_lwt.Client let host = "irc.freenode.net" let port = 6667 let realname = "CheeseBot" -let nick = "cheesebot" +let nick = "cheesebot2" let username = nick let channel = "#cheeseburger" let message = "Hello, world! This is a test from chesebot" @@ -16,15 +16,31 @@ let string_opt_to_string = function let string_list_to_string string_list = Printf.sprintf "[%s]" (String.concat "; " string_list) +let evaluate_string_opt = function + | None -> None + | Some s -> Evaluate.evaluate s + let callback ~connection ~result = let open Irc_message in match result with | Message {prefix=prefix; command=command; params=params; trail=trail} -> - Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n" - (string_opt_to_string prefix) - command - (string_list_to_string params) - (string_opt_to_string trail) + begin + Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n" + (string_opt_to_string prefix) + command + (string_list_to_string params) + (string_opt_to_string trail); + match command with + | "PRIVMSG" -> + begin + let response = evaluate_string_opt trail in + match response with + | None -> Lwt.return_unit + | Some s -> + C.send_privmsg ~connection ~target:channel ~message:s + end + | _ -> Lwt.return_unit + end | Parse_error (raw, error) -> Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error