X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Misc.pm;h=b3a1b315bcd108125b427d1ec83d06ab447d8981;hb=0037f3ea50d01fe17985b479bc9f5d7a3ae03381;hp=926ad0adaa83a71b7b39ea7039e1b56465ae6cb3;hpb=b8b137da117a678f977dcf3699335c335885c029;p=NDIRC.git diff --git a/Misc.pm b/Misc.pm index 926ad0a..b3a1b31 100644 --- a/Misc.pm +++ b/Misc.pm @@ -23,7 +23,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/valuecolor addCommand parseCommand/; +our @EXPORT = qw/valuecolor addCommand parseCommand commands/; our %channels; our %commands; @@ -72,7 +72,7 @@ sub parseCommand { my $a = $commands{$c}->{acc}; my $b = (exists $channels{lc $channel} ? $channels{lc $channel} : ['all']); if (intersect($a,$b) > 0){ - $commands{$c}->{fun}->($args); + $commands{$c}->{fun}->($args,$c); return 1; } } @@ -80,6 +80,19 @@ sub parseCommand { return 0; } +sub commands { + my ($channel) = @_; + my @commands; + my $b = (exists $channels{lc $channel} ? $channels{lc $channel} : ['all']); + for my $c (sort keys %commands){ + my $a = $commands{$c}->{acc}; + if (intersect($a,$b) > 0){ + push @commands, $c; + } + } + return join ', ', @commands; +} + sub intersect { my ($a, $b) = @_; my %union;