diff options
author | David Phillips <david@sighup.nz> | 2017-03-17 15:52:59 +1300 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2017-03-17 16:04:00 +1300 |
commit | 0c48ea15d4fbaa687ec068c610547d1c317da63c (patch) | |
tree | a8d491a90a59623547f81059295dd35464bc349d | |
parent | bc0601bd2c28395f68613fd9966ea318ff93016c (diff) | |
download | idalius-0c48ea15d4fbaa687ec068c610547d1c317da63c.tar.xz |
Keep output in same order as trigger input
-rwxr-xr-x | saxrobot | 17 | ||||
-rw-r--r-- | sb_config.pm | 14 |
2 files changed, 19 insertions, 12 deletions
@@ -84,17 +84,12 @@ sub irc_public { my $me = $irc->nick_name; my $collected_response = ""; - for (@{$config{triggers}}) { - my ($match, $response) = split /=>/; - # strip quotes - $match =~ s/^[^']*'|'[^']*$//g; - $response =~ s/^[^']*'|'[^']*$//g; - - # do the count - my $repcount = () = $what =~ /$match/gi; - if ($repcount > 0) { - $collected_response .= $response x $repcount; - } + print $config{triggers}; + my @k = (keys %{$config{triggers}}); + my $expression = join '|', @k; + print "expression: $expression\n"; + while ($what =~ /($expression)/g) { + $collected_response .= $config{triggers}->{$1}; } $irc->yield(privmsg => $channel => $collected_response) if $collected_response; diff --git a/sb_config.pm b/sb_config.pm index 5440f0c..dcff683 100644 --- a/sb_config.pm +++ b/sb_config.pm @@ -9,7 +9,7 @@ use Config::Tiny; sub parse_config { my @scalar_configs = ('nick', 'username', 'ircname', 'server', 'port', 'password', 'must_id'); - my @list_configs = ('channels', 'ignore', 'admins', 'triggers'); + my @list_configs = ('channels', 'ignore', 'admins'); my $file = $_[0]; my %built_config; my $config = Config::Tiny->read($file); @@ -25,6 +25,18 @@ sub parse_config @built_config{$option} = [split /\s*,\s*/, $vals]; } + # special case: triggers hash + my %triggers; + foreach (split ',', $config->{_}->{triggers}) { + my ($match, $response) = split /=>/; + # strip outer quotes + $match =~ s/^[^']*'|'[^']*$//g; + $response =~ s/^[^']*'|'[^']*$//g; + $triggers{$match} = $response; + } + + $built_config{triggers} = \%triggers; + return %built_config; } 1; |