Skip to content

Instantly share code, notes, and snippets.

@ilmoeuro
Last active May 13, 2022 23:43
Show Gist options
  • Save ilmoeuro/78933ad47c947fde83c6f78a2e24dbc3 to your computer and use it in GitHub Desktop.
Save ilmoeuro/78933ad47c947fde83c6f78a2e24dbc3 to your computer and use it in GitHub Desktop.
AWK ircbot, usage: `ncat -c 'awk -v nick=nick -v serv=serv -v chan=chan -f ircbot.awk' <host> <port>`
function message(str) {
system("sleep 0.1");
printf("%s\r\n", str);
printf(">>> %s\n", str) > "/dev/stderr";
system("sleep 0.1");
}
{
printf("<<< %s", $0) > "/dev/stderr";
if (! initialized) {
message(sprintf("USER %s %s %s :%s", nick, nick, serv, nick));
message(sprintf("NICK %s", nick));
message(sprintf("JOIN #%s", chan));
initialized = 1;
}
}
$2 == "PRIVMSG" && $4 ~ /^:!uptime.*/ {
"uptime" | getline uptime;
message(sprintf("PRIVMSG %s :%s", $3, uptime));
message("");
close("uptime");
}
$2 == "PING" {
message("PONG");
message("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment