summaryrefslogtreecommitdiff
path: root/scripts/clones.pl
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-08-08 22:42:14 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-08-08 22:42:14 +0000
commit8a7fa0f047edcea09f51c22b31648eb744580340 (patch)
tree49d2679f9f2f39a8dcbabcc25fed4fd48494b171 /scripts/clones.pl
parentc54646cad9eb20eecbdad3c4df0c8b61972b9d08 (diff)
downloadirssi-8a7fa0f047edcea09f51c22b31648eb744580340.zip
Some cleanups, complains if not run in channel.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1729 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'scripts/clones.pl')
-rw-r--r--scripts/clones.pl35
1 files changed, 21 insertions, 14 deletions
diff --git a/scripts/clones.pl b/scripts/clones.pl
index a469a575..45fa2033 100644
--- a/scripts/clones.pl
+++ b/scripts/clones.pl
@@ -1,25 +1,32 @@
-# /CLONES - display real name of nick
+# /CLONES - Display clones in the active channel
use Irssi;
use strict;
sub cmd_clones {
- my ($data, $server, $channel) = @_;
- my (%hostnames, $host, @nicks, $nick);
+ my ($data, $server, $channel) = @_;
- @nicks = $channel->nicks();
+ if (!$channel || $channel->{type} ne "CHANNEL") {
+ Irssi::print("No active channel in window");
+ return;
+ }
- foreach $nick (@nicks) {
- $hostnames{$nick->{host}}++;
- }
+ my %hostnames = {};
+ foreach my $nick ($channel->nicks()) {
+ $hostnames{$nick->{host}}++;
+ }
- $channel->print("Clones:");
- foreach $host (keys %hostnames) {
- my $clones = $hostnames{$host};
- if ($clones >= 2) {
- $channel->print("$host: $clones");
- }
- }
+ my $count = 0;
+ foreach my $host (keys %hostnames) {
+ my $clones = $hostnames{$host};
+ if ($clones >= 2) {
+ $channel->print("Clones:") if ($count == 0);
+ $channel->print("$host: $clones");
+ $count++;
+ }
+ }
+
+ $channel->print("No clones in channel") if ($count == 0);
}
Irssi::command_bind('clones', 'cmd_clones');