diff options
| author | dequis | 2015-11-16 19:36:52 -0300 |
|---|---|---|
| committer | dequis | 2015-11-23 13:59:24 -0300 |
| commit | 6dec1974e3ac2e71c26e842887a4b8fe2ec9082c (patch) | |
| tree | 95aeae48906c69305ae7d0afd123876ff908050b /scripts/cmpchans.pl | |
| parent | 2bc8e3368c0b842f1fe6fad069915a4bb90b1fa2 (diff) | |
| download | scripts.irssi.org-6dec1974e3ac2e71c26e842887a4b8fe2ec9082c.tar.bz2 | |
Add all non-nei scripts from nei's website
Some are mostly nei or nei variants, but not originally authored by nei
If any of the authors doesn't want to have these in scripts.irssi.org,
complain and we'll remove it.
Diffstat (limited to 'scripts/cmpchans.pl')
| -rw-r--r-- | scripts/cmpchans.pl | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/cmpchans.pl b/scripts/cmpchans.pl new file mode 100644 index 0000000..80324b0 --- /dev/null +++ b/scripts/cmpchans.pl @@ -0,0 +1,64 @@ +use strict; +use warnings; + +our $VERSION = "0.5"; +our %IRSSI = ( + authors => 'Jari Matilainen, init[1]@irc.freenode.net', + contact => 'vague@vague.se', + name => 'cmpchans', + description => 'Compare nicks in two channels', + license => 'Public Domain', + url => 'http://vague.se' +); + +use Irssi::TextUI; +use Data::Dumper; + +sub cmd_cmp { + local $/ = " "; + my ($args, $server, $witem) = @_; + my (@channels) = split /\s+/, $args; + + my $server1 = $server; + if ($channels[0] =~ s,(.*?)/,,) { + $server1 = Irssi::server_find_tag($1) || $server; + } + my $chan1 = $server1->channel_find($channels[0]); + if(!$chan1) { + Irssi::active_win()->{active}->print("You have to specify atleast one channel to compare nicks to"); + return; + } + + my @nicks_1; + my @nicks_2; + + @nicks_1 = $chan1->nicks() if(defined $chan1); + + if(not defined $channels[1]) { + @nicks_2 = $witem->nicks(); + } + else { + if ($channels[1] =~ s,(.*?)/,,) { + $server1 = Irssi::server_find_tag($1) || $server; + } + my ($chan2) = $server1->channel_find($channels[1]); + @nicks_2 = $chan2->nicks() if(defined $chan2); + } + + return if(scalar @nicks_1 == 0 || scalar @nicks_2 == 0); + + my %count = (); + my @intersection; + + foreach (@nicks_1, @nicks_2) { $count{$_->{nick}}++; } + foreach my $key (keys %count) { + if($count{$key} > 1) { + push @{\@intersection}, $key; + } + } + + my $common = join(", ", @intersection); + $witem->print("Common nicks: " . $common); +} + +Irssi::command_bind("cmp", \&cmd_cmp); |
