Skip to content

Commit

Permalink
New nick_lookup_h command to look up hosts associated with a nick
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Good authored and Isaac Good committed Nov 5, 2012
1 parent 92358da commit d99cc66
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
9 changes: 7 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
2012-11-05 .76
* New nick_lookup_h command that takes a nick and shows associated
hosts.
- IsaacG

2012-03-27 .75
* Add database indices to speed up read accesses.
- IsaacG
* Add database indices to speed up read accesses.
- IsaacG

2011-09-15 .74
* Merged in the testing branch to get two DB handles to avoid the parent
Expand Down
32 changes: 26 additions & 6 deletions stalker.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# DBI
# DBD::SQLite

$VERSION = '0.75';
$VERSION = '0.76';
%IRSSI = (
authors => 'SymKat',
contact => '[email protected]',
Expand All @@ -29,6 +29,7 @@

Irssi::command_bind( 'host_lookup', \&host_request );
Irssi::command_bind( 'nick_lookup', \&nick_request );
Irssi::command_bind( 'nick_lookup_h', \&nick_request_hosts );

Irssi::theme_register([
$IRSSI{'name'} => '{whois stalker %|$1}',
Expand Down Expand Up @@ -95,15 +96,19 @@ sub whois_request {
my ( $me, $n, $u, $h ) = split(" ", $data );

$server->printformat($n,MSGLEVEL_CRAP,$IRSSI{'name'},$n,
join( ", ", (get_records('host', $h, $server->{address}))) . "." );
join( ", ", (get_nick_records('host', $h, $server->{address}))) . "." );
}

sub nick_request_hosts {
windowPrint( join( ", ", (get_host_records('nick', $_[0], $_[1]->{address}))) . ".");
}

sub host_request {
windowPrint( join( ", ", (get_records('host', $_[0], $_[1]->{address}))) . ".");
windowPrint( join( ", ", (get_nick_records('host', $_[0], $_[1]->{address}))) . ".");
}

sub nick_request {
windowPrint( join( ", ", (get_records('nick', $_[0], $_[1]->{address}))) . ".");
windowPrint( join( ", ", (get_nick_records('nick', $_[0], $_[1]->{address}))) . ".");
}

# Record Adding Functions
Expand All @@ -115,7 +120,7 @@ sub nick_joined {

if ( Irssi::settings_get_bool($IRSSI{name} . "_stalk_on_join") ) {
my $window = $server->channel_find($channel);
my @used_nicknames = get_records( 'host', $host, $server->{address} );
my @used_nicknames = get_nick_records( 'host', $host, $server->{address} );

$window->printformat( MSGLEVEL_JOINS, 'stalker_join',
$nick, $address, $channel, join( ", ", @used_nicknames ));
Expand Down Expand Up @@ -313,6 +318,7 @@ sub async_add
Irssi::signal_remove( 'pidwait', \&record_added );
Irssi::command_unbind( 'host_lookup', \&host_request );
Irssi::command_unbind( 'nick_lookup', \&nick_request );
Irssi::command_unbind( 'nick_lookup_h', \&nick_request_h );

# In child, do the database tasks
db_add_record(@{$_}) for (@record_list);
Expand Down Expand Up @@ -348,7 +354,21 @@ sub db_add_record
debugPrint( "info", "Added record for $nick!$user\@$host to $serv" );
}

sub get_records {
sub get_host_records {
my ( $type, $query, $serv, @return ) = @_;

$count = 0; %data = ( );
my %data = _r_search( $serv, $type, $query );
for my $k ( keys %data ) {
debugPrint( "info", "$type query for records on $query from server $serv returned: $k" );
push @return, $k if $data{$k} eq 'host';
}

# case-insensitive sort
return sort {uc($a) cmp uc($b)} @return;
}

sub get_nick_records {
my ( $type, $query, $serv, @return ) = @_;

$count = 0; %data = ( );
Expand Down

0 comments on commit d99cc66

Please sign in to comment.