From 65073e311df45739646d72041fe03a1893c95739 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 11 Jul 2014 12:56:17 +0000 Subject: [PATCH] Add support for `nooverride` to prevent commands from being overridden in different namespaces --- PBot/FactoidCommands.pm | 11 +++++++++-- PBot/VERSION.pm | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index efb0fdf1..48b75e81 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -40,6 +40,7 @@ my %factoid_metadata_levels = ( edited_on => 60, locked => 10, add_nick => 10, + nooverride => 10, # all others are allowed to be factset by anybody/default to level 0 ); @@ -447,10 +448,15 @@ sub factadd { $from_chan = '.*' if not $from_chan =~ m/^#/; 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 "$keyword already exists for " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; + return "$keyword 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 "$keyword already exists for the global channel and cannot be overridden for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; } $self->{pbot}->{factoids}->add_factoid('text', $from_chan, "$nick!$user\@$host", $keyword, $text); @@ -860,6 +866,7 @@ sub load_module { if(not exists($factoids->{'.*'}->{$keyword})) { $self->{pbot}->{factoids}->add_factoid('module', '.*', "$nick!$user\@$host", $keyword, $module); $factoids->{'.*'}->{$keyword}->{add_nick} = 1; + $factoids->{'.*'}->{$keyword}->{nooverride} = 1; $self->{pbot}->{logger}->log("$nick!$user\@$host loaded module $keyword => $module\n"); $self->{pbot}->{factoids}->save_factoids(); return "Loaded module $keyword => $module"; diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index dd424d6b..e4746133 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 729, + BUILD_REVISION => 730, BUILD_DATE => "2014-07-11", };