From 6e3dc6dba2497aa8eb219706ad1a5311b96de992 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 24 Feb 2014 00:58:00 +0000 Subject: [PATCH] Add `add_nick` metadata key to tell modules to prepend nick to resulting text; unquote all spaces in module arguments --- PBot/FactoidModuleLauncher.pm | 14 ++++++++++---- PBot/VERSION.pm | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/PBot/FactoidModuleLauncher.pm b/PBot/FactoidModuleLauncher.pm index ed534803..afe68cd9 100644 --- a/PBot/FactoidModuleLauncher.pm +++ b/PBot/FactoidModuleLauncher.pm @@ -62,7 +62,7 @@ sub execute_module { $arguments =~ s/\$nick/$nick/g; $arguments = quotemeta($arguments); - $arguments =~ s/\\\s/ /; + $arguments =~ s/\\\s/ /g; if(exists $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{modulelauncher_subpattern}) { if($self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{modulelauncher_subpattern} =~ m/s\/(.*?)\/(.*)\//) { @@ -80,6 +80,7 @@ sub execute_module { $arguments =~ s/\$9/$i/g; $arguments =~ s/\$`/$before/g; $arguments =~ s/\$'/$after/g; + $self->{pbot}->logger->log("arguments subpattern: $arguments\n"); } else { $self->{pbot}->logger->log("Invalid module substitution pattern [" . $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{modulelauncher_subpattern}. "], ignoring.\n"); } @@ -129,11 +130,12 @@ sub execute_module { Carp::croak("Could not chdir to '$module_dir': $!"); } - # print "module arguments: [$arguments]\n"; + # $self->{pbot}->logger->log("module arguments: [$arguments]\n"); + + $text = `$module_dir/$module $arguments`; if(defined $tonick) { $self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n"); - $text = `$module_dir/$module $arguments`; if(defined $text && length $text > 0) { # get rid of original caller's nick $text =~ s/^\/([^ ]+) \Q$nick\E:\s+/\/$1 /; @@ -144,7 +146,11 @@ sub execute_module { return ""; } } else { - return `$module_dir/$module $arguments`; + if(exists $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{add_nick} and $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{add_nick} != 0) { + return "$nick: $text"; + } else { + return $text; + } } return "/me moans loudly."; # er, didn't execute the module? diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index be9617ae..79bd433c 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 483, - BUILD_DATE => "2014-02-22", + BUILD_REVISION => 484, + BUILD_DATE => "2014-02-23", }; 1;