!seen script

By knoeki on Jan 22, 2010

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.
    }
}

Comments

Sign in to comment.
doorkie   -  Sep 15, 2017

not working :/

 Respond  
cptpan   -  Jul 11, 2012

What the fuck, this doesn't even have a !seen trigger in it?

 Respond  
JBigga   -  Nov 06, 2010

.

 Respond  
knoeki   -  Jan 22, 2010

True, and a good point. I was actually considering pasting just the alias with usage directions, but thought I'd paste the full script instead.
The rewrite of my bot makes releasing of scripts I write for it easier, so I might release more in the future.

I'll 'fix' the -m switch now.

 Respond  
Jethro   -  Jan 22, 2010

Well, adding the -m switch is beneficial for newbies who simply copies and pastes the script without starting or restarting their mirc. Not everybody is keen enough to do that or to manually /hmake seen. Flux is one living proof. I'm sure there are more people like that.

 Respond  
knoeki   -  Jan 22, 2010

True, but I didn't personally need the -m switch for once. ;_)

 Respond  
Jethro   -  Jan 22, 2010

You can always add the -m switch to the /hadd if it's not already been created:> hadd -m seen $2-This ensures that the seen table is ready at all times.

 Respond  
knoeki   -  Jan 22, 2010

Did you let the script initialize? it creates the table in the on START event.

regardless, if you want to create the table manually:

/hmake seen 5000
 Respond  
Flux   -  Jan 22, 2010

said that...

/hadd: no such table 'seen' (line 670, remote.ini)

.>

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.