Initial commit

This commit is contained in:
Izwzyzx 2025-02-10 20:54:51 -06:00
commit a3d34fbec2
3 changed files with 69 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
export/
exclude/
settings.json

62
HxBot.hx Normal file
View File

@ -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.');
}
}

3
hxbuild.hxml Executable file
View File

@ -0,0 +1,3 @@
-m HxBot
--hl export/HxBot.hl
--cmd hl export/HxBot.hl