Make irc work.
With the new irc-client 0.2.0, everything works fine.
This commit is contained in:
parent
a80e014c7e
commit
610ccbb27d
|
@ -1,3 +1,3 @@
|
||||||
true: package(ssl,netclient,netstring,equeue-ssl)
|
true: package(ssl), package(netclient), package(netstring), package(equeue-ssl)
|
||||||
<test.*>: package(oUnit)
|
<test.*>: package(oUnit)
|
||||||
<irc.*>: package(irc-client.lwt)
|
<irc.*>: package(irc-client.lwt)
|
||||||
|
|
43
ocaml/irc.ml
43
ocaml/irc.ml
|
@ -1,6 +1,13 @@
|
||||||
open Irc_client_lwt.Io
|
open Lwt
|
||||||
module C = Irc_client_lwt.Client
|
module C = Irc_client_lwt.Client
|
||||||
|
|
||||||
|
let host = "irc.freenode.net"
|
||||||
|
let port = 6667
|
||||||
|
let realname = "CheeseBot"
|
||||||
|
let nick = "cheesebot"
|
||||||
|
let username = nick
|
||||||
|
let channel = "#cheeseburger"
|
||||||
|
let message = "Hello, world! This is a test from chesebot"
|
||||||
|
|
||||||
let string_opt_to_string = function
|
let string_opt_to_string = function
|
||||||
| None -> "None"
|
| None -> "None"
|
||||||
|
@ -9,32 +16,28 @@ let string_opt_to_string = function
|
||||||
let string_list_to_string string_list =
|
let string_list_to_string string_list =
|
||||||
Printf.sprintf "[%s]" (String.concat "; " string_list)
|
Printf.sprintf "[%s]" (String.concat "; " string_list)
|
||||||
|
|
||||||
let callback input =
|
let callback ~connection ~result =
|
||||||
let open Irc_message in
|
let open Irc_message in
|
||||||
match input with
|
match result with
|
||||||
| Message {prefix=prefix; command=command; params=params; trail=trail} ->
|
| Message {prefix=prefix; command=command; params=params; trail=trail} ->
|
||||||
(
|
Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n"
|
||||||
Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n"
|
(string_opt_to_string prefix)
|
||||||
(string_opt_to_string prefix)
|
command
|
||||||
command
|
(string_list_to_string params)
|
||||||
(string_list_to_string params)
|
(string_opt_to_string trail)
|
||||||
(string_opt_to_string trail)
|
|
||||||
)
|
|
||||||
| Parse_error (raw, error) ->
|
| Parse_error (raw, error) ->
|
||||||
Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error
|
Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error
|
||||||
|
|
||||||
let lwt_main =
|
let lwt_main =
|
||||||
let server = "193.219.128.49" in (* "chat.freenode.net" *)
|
Lwt_unix.gethostbyname host
|
||||||
let chan = "#cheeseburger" in
|
>>= fun he -> C.connect ~addr:(he.Lwt_unix.h_addr_list.(0))
|
||||||
|
~port ~username ~mode:0 ~realname ~nick ~password:"cheese" ()
|
||||||
|
>>= fun connection -> Lwt_io.printl "Connected"
|
||||||
|
>>= fun () -> C.send_join ~connection ~channel
|
||||||
|
>>= fun () -> C.send_privmsg ~connection ~target:channel ~message
|
||||||
|
>>= fun () -> C.listen ~connection ~callback
|
||||||
|
>>= fun () -> C.send_quit ~connection
|
||||||
|
|
||||||
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 () =
|
let () =
|
||||||
Lwt_main.run lwt_main
|
Lwt_main.run lwt_main
|
||||||
|
|
Loading…
Reference in a new issue