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