-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from berke/master
Example doesn't compile
- Loading branch information
Showing
7 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
open Irc_client_lwt.Io | ||
module C = Irc_client_lwt.Client | ||
|
||
let host = "totoritoto.gogol.zoooooopt.blah" | ||
let port = 16667 | ||
let realname = "Demo IRC bot" | ||
let nick = "demoirc" | ||
let username = nick | ||
let channel = "#demo_irc" | ||
let message = "Hello, world! This is a test from ocaml-irc-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 ~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) | ||
| Parse_error (raw, error) -> | ||
Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error | ||
|
||
let lwt_main = | ||
Lwt_unix.gethostbyname host | ||
>>= fun he -> C.connect ~addr:(he.Lwt_unix.h_addr_list.(0)) | ||
~port ~username ~mode:0 ~realname ~nick () | ||
>>= 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 | ||
|
||
let _ = Lwt_main.run lwt_main | ||
|
||
(* ocamlfind ocamlopt -package irc-client.lwt -linkpkg code.ml *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module Io : Irc_transport.IO with type 'a t = 'a Lwt.t | ||
|
||
module Client : sig | ||
type connection_t | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters