Okay, seen scripts have probably been done to death by now. Or not, I've never found a good one.
Anyways, since I'm working on rewriting my bot, I decided to write a proper seen script for her, and here's the result.
All seen data is stored in a hashtable for speedy adding/retrieving of and searching through everyone the bot may have seen. Every 10 minutes the data is dumped to disk, to seen.txt. On startup this data is loaded into the hashtable again.
You can search in a few possible ways;
!seen nickname
Will search for matches starting with 'nickname'. Yes, it automagically adds a wildcard to the end of the search query.
It is possible to search hostmasks with wildcards as well;
!seen *!*@*.com
And so on.
If A single match for the query is found, it will return how long ago he/she was seen, otherwise it will return the most recent 2 or 3 matches.
;; Knoeki's seen script. (C) 2010, All rights and/or wrongs reserved.
;; Use it, enjoy it, modify it, but don't pretend you did all the work.
on *:TEXT:*:#: {
seen add $address $ctime talk $chan $network $1-
if ($1 == !seen) {
msg $chan $seen(get, $2-)
}
}
on *:ACTION:*:#: {
seen add $address($nick, 5) $ctime talk $chan $network $1-
}
on *:JOIN:#: {
seen add $address($nick, 5) $ctime join $chan $network
}
on *:PART:#: {
seen add $address($nick, 5) $ctime part $chan $network $1-
}
on *:QUIT: {
seen add $address($nick, 5) $ctime quit irc $network $1-
}
on *:NICK: {
seen add $address($nick, 5) $ctime nick irc $network $newnick
}
on *:KICK:#: {
seen add $address($knick, 5) $ctime kick $chan $network $nick $1-
}
on *:TOPIC:#: {
seen add $address($nick, 5) $ctime topic $chan $network $1-
}
on *:START: {
hmake -s seen 5000
if ($file($scriptdirseen.txt) != $null) {
hload seen $qt($scriptdirseen.txt)
}
timerseen.dump 0 600 hsave seen $qt($scriptdirseen.txt)
}
alias seen {
if ($1 == add) {
hadd -m seen $2-
}
if ($1 == query) {
var %query $2
if (%query == $null) {
return Error: Insufficent parameters.
}
elseif ($len($remove(%query, $chr(42), $chr(63))) < 2) {
return Error: Please use 2 or more non-wildcard characters in your query.
}
else {
var %ticks $ticks
if ($chr(42) !isin %query) {
var %query $+(%query,*)
}
var %total $hfind(seen, %query, 0, w)
if (%total > 1) {
window -aslh @seen.sort
var %count 1
while (%count <= %total) {
var %current $hfind(seen, %query, %count, w)
aline @seen.sort $gettok($hget(seen, %current), 1, 32) %current
inc %count
}
var %result.1 $wintok(@seen.sort, %total, 2, 32)
var %result.2 $wintok(@seen.sort, $calc(%total - 1), 2, 32)
var %result.3 $wintok(@seen.sort, $calc(%total - 2), 2, 32)
window -c @seen.sort
return %total results to your query in $+($dur(%ticks),$chr(59)) most recent $iif(%total > 2, 3:, 2:) %result.1 %result.2 $iif(%total > 2, %result.3)
}
elseif (%total == 0) {
return No results for your query. $iif($chr(42) !isin %query, Try using wildcards.)
}
else {
tokenize 32 $hfind(seen, %query, 1, w) $hget(seen, $hfind(seen, %query, 1, w))
if ($3 isin talk,part,quit,join) {
return $1 was last seen $+($3,ing) $iif($3 == talk, on) $4 @ $+($5,$chr(44)) $dur($2).ctime ago.
}
if ($3 == kick) {
return $1 was last seen getting kicked from $3 @ $4 by $+($5,$chr(44)) $dur($2).ctime ago.
}
if ($3 == nick) {
return $1 was last seen changing their nick to $5 @ $+($4,$chr(44)) $dur($2).ctime ago.
}
if ($3 == topic) {
return $1 was last seen changing the topic for $3 @ $+($4,$chr(44)) $dur($2).ctime ago.
}
else {
return Error: This isn't supposed to happen.
}
}
}
}
else {
return Invalid request.
}
}