#version 0.2 /* * seen.irc - Seen script for EPIC4 and BitchX. * Copyright (c) 2003 Brian Weiss (except where noted) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. All redistributions, whether of source code or in binary form must * retain the above copyright notice, the above paragraph (the one * permitting redistribution), this list of conditions, and the following * disclaimer. * 2. The names of the author(s) may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * This script uses serial number 460 for all /ON hooks. * * The public queue system in this script is based on several aliases * written by CrazyEddy and distributed with the EPIC4 source code in * the commandqueues script. */ /****** CONFIG SECTION ******/ assign SEEN_ALLOW_PUBLIC_CMDS 0 assign SEEN_PUBLIC_TRIGGER !seen assign SEEN_SAVE_DIR ~/.seen /****** END CONFIG SECTION ******/ /****** USER ALIASES ******/ alias seen { if (![$0]) { xecho -b Usage: /SEEN [-p] [] return } /* BX handles local variable scope a bit differently than EPIC. */ ^local serv,nick,chan,pub,item,tmp,time,diff,type,extra @ serv = winserv() if (match($0 -p -pub -public)) { @ nick = [$1] @ chan = [$2] ? [$2] : C @ pub = 1 } else { @ nick = [$0] @ chan = [$1] ? [$1] : C } if (nick == servernick($serv)) { xecho -b That's our nick! Aborting seen lookup... return } if ((item = matchitem(seen.db.$serv $nick $chan *)) > -1) { @ tmp = getitem(seen.db.$serv $item) @ time = word(2 $tmp) @ diff = time() - time @ type = word(3 $tmp) @ extra = restw(4 $tmp) if (pub) { defer msg $chan $nick was last seen in $chan on $strftime($time %a %b %d %T %Z %Y) \($tdiff2($diff)\ ago) defer msg $chan Action: $type $extra } else { echo $G $nick was last seen in $chan on $strftime($time %a %b %d %T %Z %Y) \($tdiff2($diff)\ ago) echo $G Action: $type $extra } } } /****** INTERNAL ALIASES ******/ if (bitchx()) { ^alias defer { ^timer 0 {$*} } } /* * Based on CrazyEddy's /1CMD alias (part of the commandqueues script * distributed with the EPIC4 source code). * * This limits each user to one public request every 8 seconds. */ alias seen.pubcmd (serv, nick, chan, seen_nick, void) { if (!seen_nick) { echo Error: seen.pubcmd: Not enough arguments return } ^local e_nick if (SEEN_ALLOW_PUBLIC_CMDS) { @ :e_nick = encode($nick) if (time() - SEEN[PUBCMD][$serv][$e_nick] >= 8) { @ SEEN[PUBCMD][$serv][$e_nick] = time() seen.pubqueue $serv $seen_nick $chan } if (time() != SEEN[PUBCMD][$serv]) { @ SEEN[PUBCMD][$serv] = time() foreach SEEN[PUBCMD][$serv] tmp { if (SEEN[PUBCMD][$serv][$tmp] < time()) { @ SEEN[PUBCMD][$serv][$tmp] = [] } } } } } /* * Based on CrazyEddy's /QCMD alias (also part of the commandqueues script). */ alias seen.pubqueue (serv, args) { if (args) { @ push(SEEN.PUBQUEUE.$serv \"$msar(gr/\\/\\\\/\"/\\\"/args)\") ^timer -ref SEEN.PUBQUEUE.$serv 2 seen.pubqueue $serv } else { @ :tmp = shift(SEEN[PUBQUEUE][$serv]) @ msar(gr/\\\\/\\/\\\"/\"/tmp) @ :nick = word(0 $tmp) @ :chan = word(1 $tmp) if (nick == servernick($serv)) { return } if ((:item = matchitem(seen.db.$serv $nick $chan *)) > -1) { @ :tmp = getitem(seen.db.$serv $item) @ :time = word(2 $tmp) @ :diff = time() - time @ :type = word(3 $tmp) @ :extra = restw(4 $tmp) defer msg $chan $nick was last seen in $chan on $strftime($time %a %b %d %T %Z %Y) \($tdiff2($diff)\ ago) defer msg $chan Action: $type $extra } } } alias seen.readdb (void) { if (fexist($SEEN_SAVE_DIR) != -1) { fe ($glob($SEEN_SAVE_DIR\/*)) fname { @ :serv = servernum($after(-1 / $fname)) @ :fd = open($fname R) if (fd != -1) { while (!eof($fd)) { @ :tmp = read($fd) if (#tmp > 0) { @ :nick = word(0 $tmp) @ :chan = word(1 $tmp) @ :ts = word(2 $tmp) @ :type = word(3 $tmp) @ :extra = restw(4 $tmp) if ((:item = matchitem(seen.db.$serv $nick $chan *)) > -1) { @ setitem(seen.db.$serv $item $nick $chan $ts $type $extra) } else { @ setitem(seen.db.$serv $numitems(seen.db.$serv) $nick $chan $ts $type $extra) } } } } } } } alias seen.updatedb (serv, nick, chan, type, ...) { if (![$*] || nick == servernick($serv)) { return } if ((:item = matchitem(seen.db.$serv $nick $chan *)) > -1) { @ setitem(seen.db.$serv $item $nick $chan $time() $type $*) } else { @ setitem(seen.db.$serv $numitems(seen.db.$serv) $nick $chan $time() $type $*) } } alias seen.writedb (void) { if (fexist($SEEN_SAVE_DIR) == -1) { if (mkdir($SEEN_SAVE_DIR)) { echo Error: seen.writedb: Unable to create directory: $SEEN_SAVE_DIR return } } fe ($getarrays(seen.db.*)) array { @ :serv = after(-1 . $array) @ unlink($SEEN_SAVE_DIR/$servername($serv)) @ :fd = open($SEEN_SAVE_DIR/$servername($serv) W) if (fd != -1) { fe ($jot(0 ${numitems($array) - 1})) cnt { @ write($fd $getitem($array $cnt)) } @ close($fd) } else { echo Error: seen.writedb: Unable to write file: $SEEN_SAVE_DIR/$servername($serv) } } } /****** ON HOOKS ******/ on #-join 460 "*" {seen.updatedb $servernum() $0 $1 JOIN $2-} on #-leave 460 "*" {seen.updatedb $servernum() $0 $1 LEAVE $2-} on #-mode 460 "*" {seen.updatedb $servernum() $0 $1 MODE $2-} on #-public 460 "*" {seen.updatedb $servernum() $0 $1 PUBLIC $2-} on #-public_other 460 "*" {seen.updatedb $servernum() $0 $1 PUBLIC $2-} on #-topic 460 "*" {seen.updatedb $servernum() $0 $1 TOPIC $2-} on #-timer 460 "??:?0" {seen.writedb} on #-public 460 '% % $SEEN_PUBLIC_TRIGGER *' { seen.pubcmd $servernum() $0 $1 $3 seen.updatedb $servernum() $0 $1 PUBLIC $2- } on #-public_other 460 '% % $SEEN_PUBLIC_TRIGGER *' { seen.pubcmd $servernum() $0 $1 $3 seen.updatedb $servernum() $0 $1 PUBLIC $2- } /****** STARTUP ******/ seen.readdb /* EOF */