commit a3d34fbec2009fdf13a0f50b30d294239cb3596a Author: Izwzyzx <184772711+Izwzyzx@users.noreply.github.com> Date: Mon Feb 10 20:54:51 2025 -0600 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..924a883 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +export/ +exclude/ + +settings.json \ No newline at end of file diff --git a/HxBot.hx b/HxBot.hx new file mode 100644 index 0000000..e067c6f --- /dev/null +++ b/HxBot.hx @@ -0,0 +1,62 @@ +// Haxe RawBot v1.0 +// Connects to IRC and joins #lobby +// +// Issues: +// - Does not detect connection loss + +import sys.net.Host; +import sys.net.Socket; + +class HxBot { + public static function main() { + var server = new Host('127.0.0.1'); + var port = 6667; + var channel = '#lobby'; + var botnick = 'HxRawBot'; + + // Program begins + Sys.println('Connecting to ${Std.string(server)}:${Std.string(port)}...'); + Sys.println(""); + + var irc = new Socket(); + irc.connect(server, port); + + irc.write('NICK ${Std.string(botnick)}\n'); + irc.write('USER ${Std.string(botnick)} ${Std.string(botnick)} ${Std.string(botnick)} :Haxe IRC bot\r\n'); + + irc.write('JOIN :${Std.string(channel)}\r\n'); + + // Initialize our data vars + var data; + var source; + + // Main program loop + while (true) { + data = Std.string(irc.input.readLine()); + + // Detect connection loss (from PyBot, not working in Haxe) + //if (dataReceived == "b''") {break;} + + 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 + if (data.indexOf("KICK #") == data.indexOf(" ")+1) { + 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.'); + } +} \ No newline at end of file diff --git a/hxbuild.hxml b/hxbuild.hxml new file mode 100755 index 0000000..a8fa7a2 --- /dev/null +++ b/hxbuild.hxml @@ -0,0 +1,3 @@ +-m HxBot +--hl export/HxBot.hl +--cmd hl export/HxBot.hl \ No newline at end of file