-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirc_handlers.sh
89 lines (71 loc) · 2.11 KB
/
irc_handlers.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Associative arrays defining which commands to call depending
# on a regex-based match of the IRC event with egrep.
# ..._REGEX is an array of regular expressions to match against.
# ..._HANDLER is an array of commands to call if regex with same
# index is matched
#
# For join events, we match against the nickname that joined.
JOIN_REGEX=("")
JOIN_HANDLER=("join_default")
# For message events, we match against the message that was said.
MSG_REGEX=("" '^\+')
MSG_HANDLER=("msg_default" "msg_command")
#######################################################################
MICROBLOG_UPDATE=./microblog.py
MICROBLOG_MAXLEN=140
SOURCECODE_URL=https://github.com/TelecomixSyria/ii-bot
join_default () {
local NICK="$1"
}
msg_default () {
local NICK="$1"
local MSG="$2"
}
msg_command () {
local NICK="$1"
local MSG="$2"
local CMDCH=${MSG:0:1}
local CMD=$(echo "$MSG" | cut -c 2- | cut -d' ' -f1)
local ARGS=$(echo "$MSG" | cut -d' ' -f 2-)
case $CMD in
cookie)
echo 'nomnomnomcrunch!! \o/'
;;
moo|fart|o\<)
MSGLEN=$(echo "$ARGS" | wc -m)
if [ $MSGLEN -gt $MICROBLOG_MAXLEN ]; then
echo You message is too long, "$NICK". Maximum $MICROBLOG_MAXLEN but you typed $MSGLEN.
else
$MICROBLOG_UPDATE "$ARGS"
fi
;;
\<3)
local TID=$(cut -d' ' -f 1 <<<"$ARGS")
$MICROBLOG_UPDATE RT $TID
;;
re)
local TID=$(cut -d' ' -f 1 <<<"$ARGS")
local TEXT="$(cut -d' ' -f 2- <<<"$ARGS")"
if [ ${#TEXT} -gt $MICROBLOG_MAXLEN ]; then
echo "Message too long, $NICK". Maximum $MICROBLOG_MAXLEN but you typed ${#TEXT}.
else
$MICROBLOG_UPDATE RP $TID "$TEXT"
fi
;;
ur1)
local URL=$(cut -d' ' -f1 <<<"$ARGS")
curl -so - --data-urlencode longurl="$URL" --data-urlencode submit='Make it an ur1!' http://ur1.ca \
| grep 'p class="success"' | html2text -nobs | head -n 1
;;
striptease)
echo Find me naked at $SOURCECODE_URL '!'
;;
help)
echo 'cookie moo fart o< <3 re ur1 striptease'
;;
*)
echo 'wat?'
;;
esac
}