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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
if (word(2 $loadinfo()) != [pf]) {
load -pf $word(1 $loadinfo());
return;
};
## Idlealert script for EPIC5.
## Written by zlonix@efnet, public domain.
##
## Version: 1.0
## - Initial roll-out (January, 2014)
## This script allows you to monitor activity of your friends, see when
## they become idle or active. It's done by issuing continious /whois
## requests and comparing current, previous and the threshold, which is
## set by you. We depend on builtins script for $server* function
## family.
##
## Script will notify you in two cases:
## 1) when remote user's idle time become above threshold;
## 2) when it become less than threshold, but only if previously we've
## seen situation '1)'. So you won't be flooded with notifications
## when person is active and reseting its idle status frequently.
##
## You have following controls to better tune the script:
##
## /set idlealert [on|off] - turns on timers for issuing whois
## requests;
##
## /set idlealert_interval [int] - frequency of the whois requests;
##
## /set idlealert_list [str] - nicks to monitor, may be given in two
## different formats: <nick> and <nick>/<network>, first format will
## monitor <nick> on every network you're connected to, second format
## will consider 005 NETWORK feature; space separated;
##
## /set idlealert_threshold [int] - threshold for notifying a user,
## when idle time of your fellow become above this value - you will be
## notified, after this, if idle time will be reset you will be
## notified that user has gone active.
##
## Bear in mind that this script issuing only /whois requests, and don't
## do any smart things like nick change monitoring, or looking after
## hostname change. Only thing in which it trying to be intellectual -
## considering signon time: if user's time spent on IRC and his idle
## time are equal, but less than your current threshold, you won't be
## notified, since user probably got disconnected by accident.
##
## Be very careful with your settings, since it's very easy to flood
## your server and run upon server-side ignore. Also, don't forget
## that some IRC operators set special user flag to see who is issuing
## /whois on them - they may be annoyed by continuous requests from
## your side.
##
## Whois lookup are done in following way: each network has a timer
## associated with it, and every $idlealert_interval one request will be
## issued. This actually means, that the more nicks you have in your
## list which qualify for /whois on a given network - the more time will
## pass between whois'es on the same nick from the list.
##
alias idlealert.clean (void) {
fe ($myservers()) serv {
@ :network = serverctl(GET $servernum($serv) 005 NETWORK);
^timer -delete idlealert.timer.$network;
^assign -idlealert[idle][$network];
^assign -idlealert[idle][$network];
^assign -idlealert[index][$network];
};
};
alias idlealert.setup (void) {
fe ($myservers()) serv {
idlealert.timer.init $serverctl(GET $servernum($serv) 005 NETWORK);
};
};
alias idlealert (void) {
if (idlealert == [off]) {
xecho -b Idlealert: set idlealert is OFF;
return;
};
if (!@idlealert_list) {
xecho -b Idlealert: set idlealert_list is EMPTY;
return;
};
fe ($idlealert_list) nick {
if (match(*/* $nick) > 0) {
@ :net = after(/ $nick);
@ :nick = before(/ $nick);
if (@::idlealert[time][$net][$nick]) {
xecho -b $nick/$net has been idle $tdiff($::idlealert[time][$net][$nick]);
} else {
xecho -b $nick/$net not monitored;
};
};
};
};
on #-005 500 "*" {
idlealert.timer.init $serverctl(GET $servernum($0) 005 NETWORK);
};
on #-server_lost 500 "*" {
timer -delete idlealert.timer.$serverctl(GET $0 005 NETWORK);
idlealert.timer.init $serverctl(GET $0 005 NETWORK);
};
alias idlealert.timer.init (network, void) {
if (!@network) {
return;
};
if (!timerctl(REFNUM idlealert.timer.$network)) {
fe ($myservers()) serv {
if (serverctl(GET $servernum($serv) 005 NETWORK) == network) {
timer -refnum idlealert.timer.$network -repeat -1 -server $serv $idlealert_interval idlealert.timer.loop $network;
break;
};
};
};
};
alias idlealert.timer.loop (network, void) {
if (!@network) {
return;
};
fe ($idlealert_list) nick {
if (match(*/* $nick) > 0) {
@ :net = after(/ $nick);
if (@net && net == network) {
@ :nick = before(/ $nick);
push :to_whois $nick;
};
} else {
push :to_whois $nick;
};
};
if (!@to_whois) {
return;
};
if (!@::idlealert[index][$network] || ::idlealert[index][$network] >= numwords($to_whois)-1) {
@ ::idlealert[index][$network] = 0;
} else {
@ ::idlealert[index][$network]++;
};
idlealert.whois $word($idlealert[index][$network] $to_whois);
};
alias idlealert.whois (nick) {
if (!@nick) {
return;
};
idlealert.addhooks $nick;
whois $nick $nick;
};
alias idlealert.addhooks (nick) {
if (!@nick) {
return;
};
^on ^311 '% $nick *' {
@ ::idlealert[$servername()][$1] = [$2@$3];
};
^on ^319 '% $nick *';
^on ^312 '% $nick *';
^on ^301 '$nick *';
^on ^671 '% $nick *';
^on ^338 '% $nick *';
^on ^317 '% $nick *' {
@ :net = serverctl(GET $servernum() 005 NETWORK);
if (*2 >= idlealert_threshold && findw($1 $idlealert[idle][$net]) == -1) {
xecho -l user1 -b Idlealert: $1 \($idlealert[$servername()][$1]\) on server $0 become idle;
@ push(idlealert[idle][$net] $1);
@ idlealert[notified][$net] = remw($1 $idlealert[notified][$net]);
@ ::idlealert[time][$net][$1] = *2;
return;
};
@ :on_irc = time() - *3;
if (*2 < idlealert_threshold && findw($1 $idlealert[idle][$net]) != -1 && findw($1 $idlealert[notified][$net]) == -1 && *2 != on_irc) {
xecho -l user1 -b Idlealert: $1 \($idlealert[$servername()][$1]\) on server $0 not idle anymore [has been idle for $tdiff($::idlealert[time][$net][$1])];
@ idlealert[idle][$net] = remw($1 $idlealert[idle][$net]);
@ push(idlealert[notified][$net] $1);
@ ::idlealert[time][$net][$1] = *2;
return;
};
};
^on ^330 '% $nick *';
^on ^402 '% $nick *' idlealert.delhooks $nick;
^on ^318 '% $nick *' idlealert.delhooks $nick;
};
alias idlealert.delhooks (nick) {
if (!@nick) {
return;
};
on ^311 -'% $nick *';
on ^319 -'% $nick *';
on ^312 -'% $nick *';
on ^301 -'$nick *';
on ^671 -'% $nick *';
on ^338 -'% $nick *';
on ^317 -'% $nick *';
on ^330 -'% $nick *';
on ^402 -'% $nick *';
on ^318 -'% $nick *';
};
addset idlealert bool {
if (*0 == [ON]) {
idlealert.clean;
idlealert.setup;
} else {
idlealert.clean;
};
};
addset idlealert_interval int {
idlealert.clean;
idlealert.setup;
};
set idlealert_interval 60;
addset idlealert_list str;
addset idlealert_threshold int {
idlealert.clean;
idlealert.setup;
};
set idlealert_threshold 600;
|