Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 457 lines (398 sloc) 8.62 KB
#!awk -f
@include "irc.awk"
@include "json.awk"
@include "spades.awk"
@include "email.awk"
@include "remind.awk"
@include "sfvlug.awk"
# Initialization
BEGIN {
json_load("var/login.json", login);
json_load("var/nounicode.json", nounicode);
json_load("var/nocolor.json", nocolor);
OWNER = login["owner"];
connect(login["server"], \
login["nick"], \
login["channel"], \
login["auth"], \
login["pass"])
delete login
if (FIRST) {
join("#rhtest")
join("#rhspades")
join("#sfvlug")
}
PROCINFO["sorted_in"] = "@ind_str_asc";
}
# Admin
AUTH == OWNER && TO == NICK && /^die in a fire/ {
say("Ack, argh, barasdjf..")
quit()
}
AUTH == OWNER && TO == NICK && /^reload/ {
say("Reloading..")
reload()
}
AUTH == OWNER && TO == NICK && /^rejoin/ {
reply("joining..")
join("#rhnoise")
next
}
AUTH == OWNER && TO == NICK && /^(join|part)/ {
if (match(MSG, /(join|part) +(#+\w+)/, arr)) {
if (arr[1] == "join") join(arr[2]);
if (arr[1] == "part") part(arr[2]);
next
}
}
AUTH == OWNER && TO == NICK && /^\.msg/ {
match(MSG, /.*\.msg +(#*\w+) +(.*)/, arr)
send("PRIVMSG " arr[1] " :" arr[2])
}
# Kick handling
CMD == "KICK" && ARG[2] == NICK {
kick_delay = (kick_delay + 2) * 2
system("sleep " kick_delay)
join(DST)
reply("I feel happy!")
}
# Identify bots
FROM ~ /bo+t$|rhnoise/ {
bots[FROM] = 1
}
CMD == "NICK" && FROM in bots {
bots[MSG] = FROM
}
# Fancy output
/[Uu]nicode :-?\(/ {
nounicode[FROM] = 1
json_save("var/nounicode.json", nounicode);
}
/[Uu]nicode :-?\)/ {
delete nounicode[FROM]
json_save("var/nounicode.json", nounicode);
}
/[Cc]olors :-?\(/ {
nocolor[FROM] = 1
json_save("var/nocolor.json", nocolor);
}
/[Cc]olors :-?\)/ {
delete nocolor[FROM]
json_save("var/nocolor.json", nocolor);
}
# Versin/Uptime
function head(cmd, var) {
cmd | getline var
close(cmd)
return var
}
function uptime(time, fmt) {
fmt = "%d:%02d:%02d:%02d"
fmt = "%d days %02d:%02d:%02d"
return sprintf(fmt,
time / (60*60*24),
time / (60*60 ) % 24,
time / (60 ) % 60,
time / (1 ) % 60)
}
BEGIN {
up_version = head("git describe --always")
up_dirty = head("git describe --always --dirty")
up_author = head("git log -n1 --format=format:%an")
up_message = head("git log -n1 --format=format:%s")
up_reload = systime();
}
/^\.(version|rev)/ {
say("version: " up_dirty " - " up_author " - " up_message)
say("http://pileus.org/git/?p=~andy/rhawk;h=" up_version)
}
/^\.uptime/ {
_now = systime();
say("uptime: " uptime(_now - START) ", " \
"reload: " uptime(_now - up_reload))
}
# Auth info
/^\.auth/ {
_who = $2 ? $2 : FROM
if (_who in USERS)
say("nick=" USERS[_who]["nick"] " " \
"user=" USERS[_who]["user"] " " \
"auth=" USERS[_who]["auth"] " " \
"real=" USERS[_who]["real"] " " \
"host=" USERS[_who]["host"])
else
say("no auth info for " _who)
}
# GeoIP Lookup
function geoip(ip, dat, cmd, line, parts) {
dat = "/usr/share/GeoIP/GeoIPCity.dat"
cmd = "geoiplookup -f " dat " " ip
cmd | getline line
close(cmd)
if (split(line, parts, /[:,] /) >= 9)
return parts[8] "," parts[9] " -- " \
parts[6] ", " parts[4] ", " parts[3]
else
return "not found"
}
/^\.geoip (([0-9a-zA-Z_.-]+) *)*$/ {
for (_i=2; _i<=NF; _i++) {
if ($_i in USERS)
say(geoip(USERS[$_i]["host"]) " -- " \
$_i " -> " USERS[$_i]["host"])
else
say(geoip($_i) " -- " $_i)
}
}
# Fortune
TO == NICK && /^/ { extra = "" }
TO == NICK && /^\.?fortune.*-o/ { extra = "-o" }
TO == NICK && /^\.?fortune/ {
gsub(/.*\.?fortune *|-[a-z]* *|[^a-zA-Z0-9 ]/, "", MSG)
cmd = "fortune " extra " " (MSG ? "-m '" MSG "'" : "-s")
_lines = 0
while (cmd | getline _fortune && _lines < 5) {
say(_fortune)
_lines++
}
close(cmd)
next
}
/\<[Bb][Oo][Ff][Hh]\>/ {
_cmd = "fortune bofh-excuses"
_cmd | getline _fortune
_cmd | getline _fortune
_cmd | getline _fortune
close(_cmd)
say(_fortune)
next
}
# Morse code
BEGIN {
morse["/" ] = " "
morse[".-.-.-" ] = "."
morse["--..--" ] = ","
morse["..--.." ] = "?"
morse[".----." ] = "'"
morse["-.-.--" ] = "!"
morse["-..-." ] = "/"
morse["-.--." ] = "("
morse["-.--.-" ] = ")"
morse[".-..." ] = "&"
morse["---..." ] = ":"
morse["-.-.-." ] = ";"
morse["-...-" ] = "="
morse[".-.-." ] = "+"
morse["-....-" ] = "-"
morse["..--.-" ] = "_"
morse[".-..-." ] = "\""
morse["...-..-"] = "$"
morse[".--.-." ] = "@"
morse[".-" ] = "a"
morse["-..." ] = "b"
morse["-.-." ] = "c"
morse["-.." ] = "d"
morse["." ] = "e"
morse["..-." ] = "f"
morse["--." ] = "g"
morse["...." ] = "h"
morse[".." ] = "i"
morse[".---" ] = "j"
morse["-.-" ] = "k"
morse[".-.." ] = "l"
morse["--" ] = "m"
morse["-." ] = "n"
morse["---" ] = "o"
morse[".--." ] = "p"
morse["--.-" ] = "q"
morse[".-." ] = "r"
morse["..." ] = "s"
morse["-" ] = "t"
morse["..-" ] = "u"
morse["...-" ] = "v"
morse[".--" ] = "w"
morse["-..-" ] = "x"
morse["-.--" ] = "y"
morse["--.." ] = "z"
morse["-----" ] = "0"
morse[".----" ] = "1"
morse["..---" ] = "2"
morse["...--" ] = "3"
morse["....-" ] = "4"
morse["....." ] = "5"
morse["-...." ] = "6"
morse["--..." ] = "7"
morse["---.." ] = "8"
morse["----." ] = "9"
}
/^\.morse/ {
gsub(/[^.\-\/]/, " ")
_str = ""
for (i=2; i<=NF; i++)
if ($i in morse)
_str = _str morse[$i]
if (_str)
reply(_str)
else
reply("hush it, you pile of bologna")
}
# Noise
AUTH == OWNER && /^go go gadget woop/ {
for (i=20; i>0; i--)
say(".delay " i " seconds; .woop " i)
}
function woop(msg) {
gsub(/[^Oo]/, "", $1)
_len = length($1)
if (_len == 2)
_len = 10
if ($2)
_len = $2
_woop = msg
for (i=1; i<_len; i++)
_woop = _woop " " msg
say(_woop)
}
TO == NICK && /^[Ww][Oo]+[Pp] *([0-9]*)/ {
woop("WOOP")
}
/^~WOOP *([0-9]*)/ {
woop("(00/")
}
/^~woop *([0-9]*)/ {
woop("^H^P^P^O")
}
TO == NICK && DST ~ /^#/ {
#say("Hello, " FROM)
}
/^\.nestroyeti/ {
say(sprintf("Temperature: %4.1f F Humidity: %2d%%",
rand()*20+65, rand()*20+40))
}
#DST != "#sfvlug" &&
!(FROM in bots) &&
CMD == "PRIVMSG" &&
MSG !~ /^\./ &&
/awk/ {
say("Awk, awk, awk! I'm a bird!")
}
/(\<[Hh][Oo]\>.*){3}/ {
say("\00309Merry \00304Christmas!")
}
!(FROM in bots) &&
tolower($0) ~ /\<cloud\>/ {
_cmd = "shuf clouds.txt"
_cmd | getline _cloud
close(_cmd)
say(_cloud)
}
/^headshot [Cc]hristmas/ {
say(".load Christmas")
say(".jingle")
say(".unload Christmas")
}
FROM == "rhnoise" && $2 == "slaps" && $3 == NICK {
say(".spin")
}
/^[Aa]nd now[.,]/ {
say("And now...");
say("THE LARCH");
}
/(for what|that for)\?$/ {
say("For great justice!");
}
/\<nazi/ {
say("And now it's...");
say("Springtime for Hitler and Germany!");
}
/^.drank mauchter/ {
if (!drank) {
system("sleep " 2)
say("\x02MD 20/20\x0f - \x02Morgen David\x0f - \x02Under an overpass\x0f - ***** (3 minutes ago)");
}
drank=1
}
# God damn commands
FROM == "rhnoise" && load_mod {
say(".load " load_mod)
say("rhnoise: You slag!")
}
// {
load_mod = ""
}
(TO == "rhnoise" && /^load \w+/) ||
(DST == "#rhniose" && /^\.load [a-z]\w+/) {
gsub(/[^a-zA-Z0-9_]/, " ")
load_mod = toupper(substr($2,1,1)) substr($2,2);
}
(DST == "#rhnoise" && /^\.line /) {
sub(/\./, "!");
say($0);
say("scalawag: You slag!")
}
(DST == "#rhnoise" && /^\.qdb 268$/) {
say(".diediedie");
next
}
(DST == "#rhnoise" && /\.qdb *268/) {
say(".slap " FROM);
next
}
# Decrementer
BEGIN {
user_scores[0] = 1;
delete user_scores
}
/^\.(scores|scoreboard)$/ {
delete user_scores
}
FROM == "rhnoise" && !length(user_scores) {
if (split(MSG, _parts, /, /)) {
for (_i=1; _i<=length(_parts); _i++) {
split(_parts[_i], _tmp, ": ");
user_scores[_i]["user"] = _tmp[1];
user_scores[_i]["score"] = _tmp[2];
}
}
}
length(user_scores) &&
tolower($0) ~ /\<nuclear launch detected\>/ {
_count = 0;
for (_i=1; _i<=length(user_scores); _i++) {
_user = user_scores[_i]["user"];
_score = user_scores[_i]["score"];
if (_user in USERS) continue
if (_score == 1) { say(_user "--"); _count++; }
if (_score == -1) { say(_user "++"); _count++; }
}
if (_count) {
delete user_scores;
say(".scores");
} else {
say("looks like you're safe.. for now..");
}
}
# Vote relay
DST != "#rhnoise" && DST != NICK &&
/\<[a-zA-Z0-9_]{3,16}(\+\+|--)/ {
say("#rhnoise", "(" DST ") " FROM ": " MSG);
}
# Fun operators
function bang(a, b) {
if (a=="nan") return "nan";
if (b=="nan") return "nan";
if (a==b) return "nan";
if (a==0) return "+0";
if (b==0) return "-0";
return 1/(1/a - 1/b);
}
/^ *[+-]?[0-9]*\.?[0-9]+( *\? *[+-]?[0-9]*\.?[0-9]+)+ *$/ {
gsub(/?/, " ");
_num = $1+0;
for (_i=2; _i<=NF; _i++)
_num = bang(_num, $_i+0);
reply(_num);
}
# Misc
{ fflush("") }
# vim: ft=awk
Something went wrong with that request. Please try again.