-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathidle.bmod
183 lines (165 loc) · 4.63 KB
/
idle.bmod
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, June 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>,
# or in pdf format at <http://www.dhampir.no/stuff/private/gpl-2.0.pdf>
# Copyright 2014 - Øyvind 'bolt' Hvidsten <[email protected]>
! ${GHOST:-false} || return 0
isset idle_wants || declare -a idle_wants=()
isset idle_probe_wants || declare -a idle_probe_wants=()
function idle_do
{
local nick junk
read -r nick junk <<<"$@"
if [[ -n "$junk" ]]; then
reply "Usage: idle <username>"
return
fi
local found=false
local i j
for i in "${!channel_names[@]}"; do
IFS=" " read -ra list <<<"${channel_names["$i"]}"
for j in "${!list[@]}"; do
if [[ "${list[$j],,}" = "$nick" ]]; then
found=true
break 2
fi
done
done
if ! $found && ! admin_has "$(src_host)"; then
reply "I don't see $nick in any of the channels I'm in, and you are not an admin. Sorry."
return
fi
local a b c d
for i in "${!idle_wants[@]}"; do
line=${idle_wants[i]}
IFS=" " read -r a b c d <<<"$line"
if [[ "$(src_nick)" = "$c" ]] && [[ "$nick" = "$d" ]]; then
reply "Be patient!"
return
fi
done
reply "Checking..."
idle_wants+=( "$(sf_unixtime) ${reply} $(src_nick) ${nick}" )
tx "PRIVMSG $nick :"$'\x01'"FINGER"$'\x01'
}
function probe_do
{
local nick junk
read -r nick junk <<<"$@"
if [[ -n "$junk" ]]; then
reply "Usage: probe <username>"
return
fi
local a b c d
for i in "${!idle_probe_wants[@]}"; do
line=${idle_probe_wants[i]}
IFS=" " read -r a b c d <<<"$line"
if [[ "$(src_nick)" = "$c" ]] && [[ "$nick" = "$d" ]]; then
reply "Be patient!"
return
fi
done
reply "Probing..."
idle_probe_wants+=( "$(sf_unixtime) ${reply} $(src_nick) ${nick}" )
(
for verb in FINGER VERSION SOURCE USERINFO CLIENTINFO TIME; do
echo "PRIVMSG $nick :"$'\x01'"$verb"$'\x01' >"$FIFO"
sleep 11
done
) &
}
function idle_reply_do
{
[[ "$data" = "FINGER "* ]] || return 1
[[ -n "${idle_wants[*]:-}" ]] || return 1
local src_nick tmp i line
local timestamp reply reply_nick target
src_nick=$(src_nick)
src_nick=${src_nick,,}
for i in "${!idle_wants[@]}"; do
line=${idle_wants[i]}
IFS=" " read -r timestamp reply reply_nick target <<<"$line"
tmp=${target,,}
if [[ "${tmp}" = "$src_nick" ]]; then
unset 'idle_wants[i]'
read -r tmp <<<"${data#FINGER }"
reply="$reply" reply_nick="$reply_nick" reply "$(src_nick) told me: $tmp"
return 0
fi
done
return 1
}
function idle_probe_reply_do
{
[[ -n "${idle_probe_wants[*]:-}" ]] || return 0
local src_nick tmp verb stuff line
local timestamp reply reply_nick target
src_nick=$(src_nick)
src_nick=${src_nick,,}
for line in "${idle_probe_wants[@]}"; do
IFS=" " read -r timestamp reply reply_nick target <<<"$line"
tmp=${target,,}
if [[ "${tmp}" = "$src_nick" ]]; then
read -r verb stuff <<<"$data"
reply="$reply" reply_nick="$reply_nick" reply "$(src_nick) told me (${verb}): $stuff"
fi
done
}
function idle_tick
{
local i line
local timestamp reply reply_nick target
if [[ -n "${idle_wants[*]:-}" ]]; then
for i in "${!idle_wants[@]}"; do
line=${idle_wants[i]}
IFS=" " read -r timestamp reply reply_nick target <<<"$line"
if (( timestamp + 7 < $(sf_unixtime) )); then
unset 'idle_wants[i]'
reply="$reply" reply_nick="$reply_nick" reply "Timeout ($target)"
fi
done
fi
if [[ -n "${idle_probe_wants[*]:-}" ]]; then
for i in "${!idle_probe_wants[@]}"; do
line=${idle_probe_wants[i]}
IFS=" " read -r timestamp reply reply_nick target <<<"$line"
if (( timestamp + (11*6) < $(sf_unixtime) )); then
unset 'idle_probe_wants[i]'
reply="$reply" reply_nick="$reply_nick" reply "Probe done ($target)"
fi
done
fi
}
if [[ -n "$reply" ]]; then
case "$data" in
"idle")
reply "Usage: idle <username>"
;;
"idle "*)
if [[ "$reply" != "#"* ]] && ! admin_has "$(src_host)"; then
reply "This command is only available in a channel"
elif [[ -n "${data#idle }" ]]; then
idle_do "${data#idle }"
fi
;;
"probe")
reply "Usage: probe <username>"
;;
"probe "*)
if admin_verbosehas "$(src_host)" && [[ -n "${data#probe }" ]]; then
probe_do "${data#probe }"
fi
;;
esac
elif [[ "$cmd" = "NOTICE" ]]; then
while idle_reply_do; do :; done
idle_probe_reply_do
fi