X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Misc.pm;h=aad40e3c36aa5f9fcfb1c5a448a87ce55d61145f;hb=6815b7a875e95937693864b76a028f92ee2cbf35;hp=f1bf8165d3e18a661feb3da0913b22947dd2bac2;hpb=11ade9ddec1878dca71496b5659db13a756ee1ed;p=NDIRC.git diff --git a/Misc.pm b/Misc.pm index f1bf816..aad40e3 100644 --- a/Misc.pm +++ b/Misc.pm @@ -19,33 +19,15 @@ package NDIRC::Misc; use strict; use warnings; -require Exporter; - -our @ISA = qw/Exporter/; +use feature ':5.10'; -our @EXPORT = qw/valuecolor addCommand parseCommand commands/; +require Exporter; -our %channels; -our %commands; +use NDIRC::Context; -$channels{'#def-ndawn'} = ['all','member','def']; -$channels{'#nd'} = ['all','member']; -$channels{'#ndef'} = ['all','member','scan']; -$channels{'#nd-day'} = ['all','member']; -$channels{'#ndintel'} = ['all','member']; -$channels{'#nd-officers'} = ['all','member']; -$channels{'#nd-ia'} = ['all','member']; -$channels{'#ndawn'} = ['all']; -$channels{'pm'} = ['pm']; +our @ISA = qw/Exporter/; -$ND::defchan = "#def-ndawn"; -$ND::memchan = "#nd"; -$ND::scanchan = "#ndef"; -$ND::bcchan = "#nd-day"; -$ND::intelchan = "#ndintel"; -$ND::officerchan = "#nd-officers"; -$ND::communitychan = "#ndawn"; -$ND::pubchan = "#newdawn"; +our @EXPORT = qw/valuecolor/; sub valuecolor { my $s = $_; @@ -58,52 +40,5 @@ sub valuecolor { return $s; } -sub addCommand { - my ($command, $list, $func) = @_; - $commands{$command} = {fun => $func, acc => $list}; -} - -sub parseCommand { - my ($msg,$channel) = @_; - if ($msg =~ /^(\S+)(?: (.+))?$/){ - my $c = $1; - my $args = $2; - my @k = keys %commands; - if (exists $commands{$c}){ - my $a = $commands{$c}->{acc}; - my $b = (exists $channels{lc $channel} ? $channels{lc $channel} : ['all']); - if (intersect($a,$b) > 0){ - $commands{$c}->{fun}->($args,$c); - return 1; - } - } - } - 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; - foreach my $e (@{$a}) { $union{$e} = 1 } - - my %isect; - foreach my $e (@{$b}) { - $isect{$e} = 1 if ( exists $union{$e} ) - } - return keys %isect; -} 1;