]> Pileus Git - ~andy/rhawk/blob - rhsed
4949caf3ff4d0130240d253fcb4a3be6ff33e2e8
[~andy/rhawk] / rhsed
1 # Clear hold space
2 x; s/.*//; x
3
4 # Debug input
5 s/^/< /
6 w /dev/stderr
7 s/^< //
8
9 # Setup variables:
10 s/[$=]/&\\/g
11 s/\(:\([^ ]*\) \)\?\(\([^ ]*\) \)\(\([^ ]*\) \)\?\(:\(.*\)\)/AUTH= SERVER= NICK= CHANNEL= CMD=\4 SRC=\2 DST=\6 TO= FROM= MSG=\8/
12 s/\(TO=\)\(.*MSG=\([^:,]\+\)[:,]\)/\1\3\2/
13 s/\(SRC=\([^!]\+\)!.*\)\(FROM=\)/\1\3\2/
14 s/CHANNEL=/&#rhnoise/
15 s/NICK=/&rhsed/
16 s/SERVER=/&irc.freenode.net/
17 s/\(AUTH=\)\(.*TO=rhsed.*FROM=andy753421\)/\1yes\2/
18
19 # IRC library commands
20 1                         { x; s/$/\nUSER andy c $SERVER :$NICK/; x; }
21 1                         { x; s/$/\nNICK rhsed/; x; }
22 /CMD=PING/                { x; s/$/\nPING :$MSG/; x; }
23 /CMD=001.*MSG=.*Welcome/  { x; s/$/\nJOIN $CHANNEL/; x; }
24
25 # Bot commands
26 /MSG=.*\<sed\>/           { x; s/$/\n.say Sed!/; x; }
27 /NICK=\([^ ]*\).*MSG=\1:/ { x; s/$/\n.say Hello, $FROM/; x; }
28 /MSG=.dup/                { x; s/$/\n.say Dup! $MSG/; x; }
29 /MSG=.ping/               { x; s/$/\n.reply Pong!/; x; }
30 /AUTH=yes.*MSG=.*die in a fire/Q
31
32 # Helper functions
33 x
34 s/\n.reply /\n.say $FROM: /g
35 s/\n.say *\([^\n]*\)/\nPRIVMSG #rhnoise :\1/g
36 x
37
38 # Replace variables
39 G
40 :vars
41 s/\(.*SERVER=\([^ ]*\).*\n.*\)\$SERVER/\1\2/
42 s/\(.*NICK=\([^ ]*\).*\n.*\)\$NICK/\1\2/
43 s/\(.*CHANNEL=\([^ ]*\).*\n.*\)\$CHANNEL/\1\2/
44 s/\(.*CMD=\([^ ]*\).*\n.*\)\$CMD/\1\2/
45 s/\(.*SRC=\([^ ]*\).*\n.*\)\$SRC/\1\2/
46 s/\(.*DST=\([^ ]*\).*\n.*\)\$DST/\1\2/
47 s/\(.*TO=\([^ ]*\).*\n.*\)\$TO/\1\2/
48 s/\(.*FROM=\([^ ]*\).*\n.*\)\$FROM/\1\2/
49 s/\(.*MSG=\([^\n]*\)\n.*\)\$MSG/\1\2/
50 t vars
51
52 ## Output
53 s/^[^\n]*\n*//
54 s/\([$=]\)\\/\1/g
55 /./ {
56         w /dev/stdout
57         s/\(^\|\n\)/\1> /g
58         w /dev/stderr
59 }
60 d
61
62 # vim: ft=sed