-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 467f232
Showing
9 changed files
with
897 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Connect with: | ||
# socat 'TCP:localhost:12345' 'EXEC:awk -f $0' | ||
# | ||
# Pre-defined variables: | ||
# | ||
# When connected: | ||
# SERVER: IRC Server that is connected to | ||
# NICK: Nickname given by the bot | ||
# CHANNEL: Channel the bot is currently in | ||
# | ||
# When a messages is recieved: | ||
# CMD: Message, e.g. PRIVMSG | ||
# SRC: Source of the message | ||
# DST: Destination of the message, e.g. the channel | ||
# TO: Nickname the message was addressed to | ||
# FROM: Nickname of the user who sent the message | ||
# MSG: Message sent | ||
# $0: Message sans TO | ||
|
||
# Debugging | ||
function send(msg) { | ||
#print " > " msg > "/dev/stderr" | ||
print msg | ||
#system("sleep 1") | ||
fflush() | ||
} | ||
|
||
// { | ||
#print "" > "/dev/stderr" | ||
#print " < " $0 > "/dev/stderr" | ||
} | ||
|
||
function debug(msg) { | ||
print " # " msg > "/dev/stderr" | ||
fflush() | ||
} | ||
|
||
function set() { | ||
debug("CMD: " CMD) | ||
debug("SRC: " SRC) | ||
debug("DST: " DST) | ||
debug("FROM: " FROM) | ||
debug("TO: " TO) | ||
debug("MSG: " MSG) | ||
} | ||
|
||
# Functions | ||
function connect(server, nick, channel) { | ||
SERVER = server | ||
NICK = nick | ||
CHANNEL = channel | ||
if (FIRST) { | ||
"whoami" | getline _name | ||
"hostname" | getline _host | ||
send("USER " _name " " _host " " server " :" nick) | ||
send("NICK " nick) | ||
} | ||
} | ||
function privmsg(to, msg) { | ||
send("PRIVMSG " to " :" msg) | ||
} | ||
function say(msg) { | ||
if (DST ~ "^#") | ||
privmsg(DST, msg) | ||
else if (DST == NICK && FROM) | ||
privmsg(FROM, msg) | ||
else | ||
privmsg(CHANNEL, msg) | ||
} | ||
|
||
function reply(msg) { | ||
say(FROM ": " msg) | ||
} | ||
|
||
function join(chan) { | ||
send("JOIN " chan) | ||
} | ||
|
||
function part(chan) { | ||
send("PART " chan) | ||
} | ||
|
||
# Reloading | ||
BEGIN { | ||
if (CHILD == "") { | ||
debug("Starting server"); | ||
status = system("awk -f rhawk -v CHILD=1 -v FIRST=1"); | ||
while (status) | ||
status = system("awk -f rhawk -v CHILD=1"); | ||
exit(0); | ||
} else { | ||
debug("Starting child: CHILD=" CHILD " FIRST=" FIRST); | ||
} | ||
} | ||
|
||
function quit() { | ||
exit(0) | ||
} | ||
|
||
function reload() { | ||
exit(1) | ||
} | ||
|
||
# Input parsing | ||
// { | ||
match($0, /(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+) +)?([^:]*:(.*))/, arr); | ||
gsub(/\s+/, " ", arr[8]) | ||
gsub(/^ | $/, "", arr[8]) | ||
gsub(/\3[0-9]*/, "", arr[8]) | ||
SRC = arr[2] | ||
CMD = arr[4] | ||
DST = arr[6] | ||
MSG = arr[8] | ||
|
||
match(SRC, /([^! ]+)!/, arr); | ||
FROM = arr[1] | ||
|
||
match(MSG, /(([^ :,]*)[:,] *)?(.*)/, arr); | ||
TO = arr[2] | ||
$0 = TO == NICK ? arr[3] : MSG | ||
|
||
if (CMD == "PRIVMSG" && DST == NICK && FROM) | ||
TO = DST | ||
} | ||
|
||
# IRC client | ||
CMD == "001" && MSG ~ /Welcome/ { | ||
join(CHANNEL) | ||
} | ||
|
||
CMD == "PING" { | ||
send("PING " MSG) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test:Q: | ||
awk -f rhawk < testirc.txt | ||
#awk -f rhawk < testirc.txt | ||
#awk -f test.awk test.txt | awk -f rhawk #| grep 'points\|bid\|took' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!awk -f | ||
|
||
@include "irc.awk" | ||
@include "spades.awk" | ||
|
||
# Initialization | ||
BEGIN { | ||
OWNER = "andy753421" | ||
connect("localhost", "rhawk", "#rhtest"); | ||
} | ||
|
||
# Admin | ||
FROM == OWNER && TO == NICK && /^die in a fire/ { | ||
say("Ack, argh, barasdjf..") | ||
quit() | ||
} | ||
|
||
FROM == OWNER && TO == NICK && /^reload/ { | ||
say("Reloading..") | ||
reload() | ||
} | ||
|
||
FROM == OWNER && TO == NICK && /^rejoin/ { | ||
reply("joining..") | ||
join("#rhnoise") | ||
next | ||
} | ||
|
||
FROM == OWNER && TO == NICK && /^(join|part)/ { | ||
match(MSG, /(join|part) +(#+\w+)/, arr) | ||
if (arr[1] && arr[2]) { | ||
send(toupper(arr[1]) " " arr[2]); | ||
next | ||
} | ||
} | ||
|
||
FROM == OWNER && TO == NICK && /^\.msg/ { | ||
match(MSG, /.*\.msg +(#*\w+) +(.*)/, arr) | ||
send("PRIVMSG " arr[1] " :" arr[2]) | ||
} | ||
|
||
# Kick handling | ||
CMD == "KICK" { | ||
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 | ||
} | ||
|
||
|
||
# Unicode | ||
/[Uu]nicode :-?\(/ { | ||
plain[FROM] = 1 | ||
} | ||
|
||
/[Uu]nicode :-?\)/ { | ||
plain[FROM] = 0 | ||
} | ||
|
||
# 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") | ||
while (cmd | getline _fortune && lines < 5) { | ||
say(_fortune) | ||
lines++ | ||
} | ||
close(cmd) | ||
next | ||
} | ||
|
||
# Noise | ||
FROM ~ OWNER && /^go go gadget woop/ { | ||
for (i=20; i>0; i--) | ||
say(".delay " i " seconds; .woop " i) | ||
} | ||
|
||
TO == NICK && DST ~ /^#/ { | ||
#say("Hello, " FROM) | ||
} | ||
|
||
!(FROM in bots) && | ||
MSG !~ /^\./ && | ||
/\<awk\>/ { | ||
say("Awk, awk, awk! I'm a bird!") | ||
} | ||
|
||
/^\.help/ { | ||
reply("Nothing can help you now..") | ||
} | ||
|
||
/Ho.*Ho.*Ho/ { | ||
say("\00309Merry \00304Christmas!") | ||
} | ||
|
||
{ fflush("") } | ||
|
||
# vim: ft=awk |
Oops, something went wrong.