Browse files

Fix bug when irc server had no welcome message, and add a function to…

… handle message
  • Loading branch information...
1 parent f4b7752 commit de3827167824861947b028f494716385bb83af70 @mattgu74 mattgu74 committed Oct 1, 2011
Showing with 11 additions and 4 deletions.
  1. +3 −2 libirc/ircBot.ml
  2. +6 −1 libirc/ircBotCore.proto
  3. +2 −1 opabsl/mlbsl/bslIrc.ml
View
5 libirc/ircBot.ml
@@ -33,15 +33,16 @@ let insert_bot (irc: IBC.irc) sched server port =
* @param server The server to which the bot will connect.
* @param port The port on which to connect.
*)
-let create_bot username realname nickname password server channel port callback =
+let create_bot username realname nickname password server channel port callback onreceive =
let parameters = {
IBC.username = username;
realname = realname;
nickname = nickname;
password = password;
server = server;
channel = channel;
- callback = callback
+ callback = callback;
+ onreceive = onreceive
} in
let sched = Scheduler.default in
insert_bot parameters sched server port
View
7 libirc/ircBotCore.proto
@@ -30,7 +30,8 @@
password:string;
server:string;
channel:string;
- callback: Scheduler.connection_info -> unit
+ callback: Scheduler.connection_info -> unit;
+ onreceive: Scheduler.connection_info -> string -> string -> string -> unit
}
-type payload = unit
@@ -51,6 +52,7 @@
read_welcome_messages(irc):
receive
| Sns (_, "376", _) -> join_channels(irc)
+ | Sns (_, "422", _) -> join_channels(irc)
| _ -> read_welcome_messages(irc)
join_channels(irc):
@@ -70,6 +72,9 @@ read_channels(irc):
% the outer application has no (clean) means of knowing
% whether the connection is still alive.
quit()
+ | SrvPrivmsg (header, dest, msg) ->
+ {{ Scheduler.push sched (fun () -> (irc.onreceive conn header dest msg)) }}
+ read_channels(irc)
| Ping msg ->
send (Pong msg);
read_channels(irc)
View
3 opabsl/mlbsl/bslIrc.ml
@@ -24,6 +24,7 @@ let write_msg conn msg = write_raw conn (IrcBotCore.string_of_msg msg)
##extern-type Irc.msg = IrcBotCore.msg
##register create_bot: string, string, string, string, string, string, int,\
- (Irc.connection -> void) -> void
+ (Irc.connection -> void),\
+ (Irc.connection, string, string, string -> void) -> void
##register write_raw: Irc.connection, string -> void
##register write_msg: Irc.connection, Irc.msg -> void

0 comments on commit de38271

Please sign in to comment.