diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index 52083f53..209757f5 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -944,26 +944,28 @@ sub factadd { $from_chan = '.*' if lc $from_chan eq 'global'; $from_chan = '.*' if not $from_chan =~ m/^#/; + my $keyword_text = $keyword =~ / / ? "\"$keyword\"" : $keyword; + my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $keyword, undef, 1, 1); if(defined $trigger) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $keyword\n"); - return "/say $keyword already exists for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; + return "/say $keyword_text already exists for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; } ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid('.*', $keyword, undef, 1, 1); if(defined $trigger and $self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{$trigger}->{'nooverride'}) { - $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to override $keyword\n"); - return "/say $keyword already exists for the global channel and cannot be overridden for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; + $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to override $keyword_text\n"); + return "/say $keyword_text already exists for the global channel and cannot be overridden for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; } if ($self->{pbot}->{commands}->exists($keyword)) { - return "/say $keyword already exists as a built-in command."; + return "/say $keyword_text already exists as a built-in command."; } $self->{pbot}->{factoids}->add_factoid('text', $from_chan, "$nick!$user\@$host", $keyword, $text); - $self->{pbot}->{logger}->log("$nick!$user\@$host added [$from_chan] $keyword => $text\n"); - return "/say $keyword added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; + $self->{pbot}->{logger}->log("$nick!$user\@$host added [$from_chan] $keyword_text => $text\n"); + return "/say $keyword_text added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; } sub factrem { @@ -984,31 +986,33 @@ sub factrem { $channel = '.*' if $channel eq 'global'; $from_chan = '.*' if $channel eq 'global'; + my $trigger_text = $trigger =~ / / ? "\"$trigger\"" : $trigger;; + if($factoids->{$channel}->{$trigger}->{type} eq 'module') { - $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not factoid]\n"); - return "/say $trigger is not a factoid."; + $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger_text [not factoid]\n"); + return "/say $trigger_text is not a factoid."; } if ($channel =~ /^#/ and $from_chan =~ /^#/ and $channel ne $from_chan) { - return "/say $trigger belongs to $channel, but this is $from_chan. Please switch to $channel or /msg to remove this factoid."; + return "/say $trigger_text belongs to $channel, but this is $from_chan. Please switch to $channel or /msg to remove this factoid."; } my ($owner) = $factoids->{$channel}->{$trigger}->{'owner'} =~ m/([^!]+)/; if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host"))) { - $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not owner]\n"); + $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger_text [not owner]\n"); my $chan = ($channel eq '.*' ? 'the global channel' : $channel); - return "You are not the owner of $trigger for $chan"; + return "You are not the owner of $trigger_text for $chan"; } if($factoids->{$channel}->{$trigger}->{'locked'}) { - return "/say $trigger is locked; unlock before deleting."; + return "/say $trigger_text is locked; unlock before deleting."; } $self->{pbot}->{logger}->log("$nick!$user\@$host removed [$channel][$trigger][" . $factoids->{$channel}->{$trigger}->{action} . "]\n"); $self->{pbot}->{factoids}->remove_factoid($channel, $trigger); $self->log_factoid($channel, $trigger, "$nick!$user\@$host", "deleted", 1); - return "/say $trigger removed from " . ($channel eq '.*' ? 'the global channel' : $channel) . "."; + return "/say $trigger_text removed from " . ($channel eq '.*' ? 'the global channel' : $channel) . "."; } sub histogram { @@ -1054,7 +1058,9 @@ sub factshow { my ($channel, $trigger) = $self->find_factoid_with_optional_channel($from, $arguments, 'factshow'); return $channel if not defined $trigger; # if $trigger is not defined, $channel is an error message - my $result = "$trigger: " . $factoids->{$channel}->{$trigger}->{action}; + my $trigger_text = $trigger =~ / / ? "\"$trigger\"" : $trigger; + + my $result = "$trigger_text: " . $factoids->{$channel}->{$trigger}->{action}; if($factoids->{$channel}->{$trigger}->{type} eq 'module') { $result .= ' [module]'; diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index f5df52df..0587224b 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -938,6 +938,7 @@ sub handle_action { return "" if not length $action; my ($channel, $keyword) = ($stuff->{channel}, $stuff->{trigger}); + my $keyword_text = $keyword =~ / / ? "\"$keyword\"" : $keyword; unless (exists $self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} and $self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} eq '0') { $action = $self->expand_factoid_vars($stuff->{from}, $stuff->{nick}, $stuff->{root_keyword}, $action); @@ -980,15 +981,15 @@ sub handle_action { $stuff->{command} = $command; $stuff->{aliased} = 1; - $self->{pbot}->{logger}->log("[" . (defined $stuff->{from} ? $stuff->{from} : "stdin") . "] ($stuff->{nick}!$stuff->{user}\@$stuff->{host}) [$keyword] aliased to: [$command]\n"); + $self->{pbot}->{logger}->log("[" . (defined $stuff->{from} ? $stuff->{from} : "stdin") . "] ($stuff->{nick}!$stuff->{user}\@$stuff->{host}) [$keyword_text] aliased to: [$command]\n"); return $self->{pbot}->{interpreter}->interpret($stuff); } - $self->{pbot}->{logger}->log("(" . (defined $stuff->{from} ? $stuff->{from} : "(undef)") . "): $stuff->{nick}!$stuff->{user}\@$stuff->{host}: $keyword: action: \"$action\"\n"); + $self->{pbot}->{logger}->log("(" . (defined $stuff->{from} ? $stuff->{from} : "(undef)") . "): $stuff->{nick}!$stuff->{user}\@$stuff->{host}: $keyword_text: action: \"$action\"\n"); if ($self->{factoids}->hash->{$channel}->{$keyword}->{enabled} == 0) { - $self->{pbot}->{logger}->log("$keyword disabled.\n"); - return "/msg $stuff->{nick} $stuff->{ref_from}$keyword is currently disabled."; + $self->{pbot}->{logger}->log("$keyword_text disabled.\n"); + return "/msg $stuff->{nick} $stuff->{ref_from}$keyword_text is currently disabled."; } unless (exists $self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} and $self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} eq '0') { @@ -1028,7 +1029,7 @@ sub handle_action { || $action =~ s/^\/msg\s+([^ ]+)/\/msg $1 $stuff->{ref_from}/i) { return $action; } else { - return $stuff->{ref_from} . "$keyword is $action"; + return $stuff->{ref_from} . "$keyword_text is $action"; } } else { if ($action =~ m/^\/(?:say|me|msg)/i) { @@ -1036,7 +1037,7 @@ sub handle_action { } elsif ($action =~ s/^\/kick\s+//) { if (not exists $self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'}) { $stuff->{authorized} = 0; - return "/say $stuff->{nick}: $keyword doesn't have the effective-level to do that."; + return "/say $stuff->{nick}: $keyword_text doesn't have the effective-level to do that."; } my $level = 10; if ($self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'} >= $level) { @@ -1047,7 +1048,7 @@ sub handle_action { return "/say $stuff->{nick}: My effective-level isn't high enough to do that."; } } else { - return "/say $keyword is $action"; + return "/say $keyword_text is $action"; } } } elsif($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'regex') { @@ -1090,7 +1091,7 @@ sub handle_action { return ""; } } else { - $self->{pbot}->{logger}->log("($stuff->{from}): $stuff->{nick}!$stuff->{user}\@$stuff->{host}): Unknown command type for '$keyword'\n"); + $self->{pbot}->{logger}->log("($stuff->{from}): $stuff->{nick}!$stuff->{user}\@$stuff->{host}): Unknown command type for '$keyword_text'\n"); return "/me blinks." . " $stuff->{ref_from}"; } }