~sircmpwn/harebot

6e5aebf9e932e00abd32215280f1280c5a1713be — Drew DeVault 6 months ago 61ba1a7
Add logging
1 files changed, 15 insertions(+), 0 deletions(-)

M main.ha
M main.ha => main.ha +15 -0
@@ 21,6 21,7 @@ export fn main() void = {
		nick = "harebot",
		user = "harebot",
		realname = "Hare IRC bot",
		logfn = &logmsg,
		...
	};



@@ 46,6 47,20 @@ export fn main() void = {
	for (!(irc::dispatch(conn)! is io::EOF)) void;
};

fn logmsg(state: nullable *void, party: irc::party, msg: *irc::message) void = {
	switch (party) {
	case irc::party::SERVER =>
		fmt::print("<= ")!;
	case irc::party::CLIENT =>
		fmt::print("-> ")!;
	};
	if (msg.command == "PASS") {
		fmt::println("PASS <redacted>")!;
	} else {
		irc::serialize(os::stdout, msg)!;
	};
};

fn handle_privmsg(
	user: nullable *void,
	msg: const *irc::message,