2010-12-08 17:18:07 -07:00
|
|
|
type bot = {
|
|
|
|
store: Infobot.t;
|
|
|
|
}
|
|
|
|
|
2009-02-08 20:25:27 -07:00
|
|
|
let write iobuf command args text =
|
|
|
|
let cmd = Command.create None command args text in
|
|
|
|
print_endline ("--> " ^ (Command.as_string cmd));
|
|
|
|
Iobuf.write iobuf cmd
|
|
|
|
|
2010-12-08 17:18:07 -07:00
|
|
|
let handle_command bot iobuf cmd =
|
2009-02-08 20:25:27 -07:00
|
|
|
print_endline ("<-- " ^ (Command.as_string cmd));
|
2010-12-08 17:18:07 -07:00
|
|
|
Infobot.handle_command bot.store iobuf cmd;
|
2009-02-08 20:25:27 -07:00
|
|
|
match Command.as_tuple cmd with
|
|
|
|
| (_, "PING", _, text) ->
|
|
|
|
write iobuf "PONG" [] text
|
|
|
|
| (_, "001", _, _) ->
|
2009-03-03 19:48:22 -07:00
|
|
|
write iobuf "JOIN" ["#bot"] None
|
2009-03-02 23:26:04 -07:00
|
|
|
| (Some sender, "JOIN", [], Some chan) ->
|
2009-02-08 20:25:27 -07:00
|
|
|
write iobuf "PRIVMSG" [chan] (Some "hi asl")
|
|
|
|
| _ ->
|
|
|
|
()
|
|
|
|
|
|
|
|
let handle_error iobuf str =
|
|
|
|
print_endline str
|
|
|
|
|
|
|
|
let main () =
|
|
|
|
let host = Unix.gethostbyname "woozle.org" in
|
|
|
|
let dispatcher = Dispatch.create 5 in
|
|
|
|
let conn = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
|
2010-12-08 17:18:07 -07:00
|
|
|
let bot = {store = Infobot.create "info.cdb"} in
|
2009-02-08 20:25:27 -07:00
|
|
|
let _ = Unix.connect conn (Unix.ADDR_INET (host.Unix.h_addr_list.(0), 6667)) in
|
2010-12-08 17:18:07 -07:00
|
|
|
let iobuf = Iobuf.create dispatcher conn "woozle"
|
|
|
|
(handle_command bot)
|
|
|
|
handle_error
|
|
|
|
in
|
2009-02-08 20:25:27 -07:00
|
|
|
write iobuf "NICK" ["bot"] None;
|
2009-03-03 19:48:22 -07:00
|
|
|
write iobuf "USER" ["bot"; "bot"; "bot"] (Some "A Bot");
|
2009-02-08 20:25:27 -07:00
|
|
|
Dispatch.run dispatcher
|
|
|
|
|
|
|
|
|
|
|
|
let _ =
|
|
|
|
main ()
|