diff --git a/ocaml/_tags b/ocaml/_tags index 1e23598..33eb860 100644 --- a/ocaml/_tags +++ b/ocaml/_tags @@ -1,2 +1,3 @@ true: package(ssl,netclient,netstring,equeue-ssl) : package(oUnit) +: package(irc-client.lwt) diff --git a/ocaml/irc.ml b/ocaml/irc.ml new file mode 100644 index 0000000..07fd464 --- /dev/null +++ b/ocaml/irc.ml @@ -0,0 +1,40 @@ +open Irc_client_lwt.Io +module C = Irc_client_lwt.Client + + +let string_opt_to_string = function + | None -> "None" + | Some s -> Printf.sprintf "Some %s" s + +let string_list_to_string string_list = + Printf.sprintf "[%s]" (String.concat "; " string_list) + +let callback input = + let open Irc_message in + match input 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) + ) + | Parse_error (raw, error) -> + Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error + +let lwt_main = + let server = "193.219.128.49" in (* "chat.freenode.net" *) + let chan = "#cheeseburger" in + + C.connect ~server ~port:6667 ~username:"cheesebot" + ~mode:0 ~realname:"CheeseBot" ~nick:"cheesebot" ~password:"cheese" + >>= (fun connection -> + Lwt_io.printl "Connected" + >>= (fun () -> C.send_join ~connection ~channel:chan) + >>= (fun () -> C.send_privmsg ~connection ~target:chan ~message:"hi") + >>= (fun () -> C.listen ~connection ~callback) + >>= (fun () -> C.send_quit ~connection)) + +let () = + Lwt_main.run lwt_main