diff --git a/HxBot.hx b/HxBot.hx index e067c6f..096519e 100644 --- a/HxBot.hx +++ b/HxBot.hx @@ -1,11 +1,9 @@ -// Haxe RawBot v1.0 -// Connects to IRC and joins #lobby -// -// Issues: -// - Does not detect connection loss +// Haxe RawBot v1.1 +// Attempts to catch connection loss import sys.net.Host; import sys.net.Socket; +using StringTools; class HxBot { public static function main() { @@ -19,6 +17,7 @@ class HxBot { Sys.println(""); var irc = new Socket(); + // Need to put a try-catch in here probably irc.connect(server, port); irc.write('NICK ${Std.string(botnick)}\n'); @@ -32,31 +31,28 @@ class HxBot { // Main program loop while (true) { - data = Std.string(irc.input.readLine()); - - // Detect connection loss (from PyBot, not working in Haxe) - //if (dataReceived == "b''") {break;} + data = irc.input.readLine(); // The good one Sys.println(data); - + // Respond to server pings if (data.indexOf("PING") == 0) { irc.write('PONG ${data.substring(data.indexOf(" ")+1)}\r\n'); } - + // Auto-Rejoin when kicked + // TODO: Make sure this only happens when THIS BOT is kicked! if (data.indexOf("KICK #") == data.indexOf(" ")+1) { - source = data.substring(data.indexOf("#"), data.indexOf(" ", data.indexOf("#"))); - irc.write('JOIN ${source}\r\n'); + source = data.substring(data.indexOf("#"), data.indexOf(" ", data.indexOf("#"))); + irc.write('JOIN ${source}\r\n'); } - + // Shutdown command if (data.toLowerCase().indexOf("!quit") != -1) { irc.write('QUIT :Shutdown\r\n'); } } - // End of program Sys.println(""); - Sys.println('Connection terminated.'); + Sys.println("Connection terminated."); } } \ No newline at end of file