From 562d2652616e4d93ff4d7ca60e20bce91af1fdf1 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 21 Jun 2010 13:28:54 +0000 Subject: [PATCH] Adding factoid in a channel now creates that factoid in that channel instead of .*; info command now shows what channel factoid belongs to --- PBot/FactoidCommands.pm | 14 ++++++++------ PBot/Factoids.pm | 8 ++++++-- PBot/Interpreter.pm | 3 ++- PBot/VERSION.pm | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index f42dfbe7..569707ba 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -191,7 +191,7 @@ sub alias { } $from = '.*' if not defined $from or $from !~ /^#/; - my ($channel, $alias_trigger) = $self->{pbot}->factoids->find_factoid($from, $alias); + my ($channel, $alias_trigger) = $self->{pbot}->factoids->find_factoid($from, $alias, undef, 1); if(defined $alias_trigger) { $self->{pbot}->logger->log("attempt to overwrite existing command\n"); @@ -227,7 +227,7 @@ sub add_regex { return "/msg $nick Usage: regex "; } - my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword); + my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword, undef, 1); if(defined $trigger) { $self->{pbot}->logger->log("$nick!$user\@$host attempt to overwrite $trigger\n"); @@ -250,7 +250,7 @@ sub add_text { $from = '.*' if not defined $from or $from !~ /^#/; - my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword); + my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword, undef, 1); if(defined $trigger) { $self->{pbot}->logger->log("$nick!$user\@$host attempt to overwrite $keyword\n"); @@ -366,19 +366,21 @@ sub info { my $created_ago = ago(gettimeofday - $factoids->{$channel}->{$trigger}->{created_on}); my $ref_ago = ago(gettimeofday - $factoids->{$channel}->{$trigger}->{last_referenced_on}) if defined $factoids->{$channel}->{$trigger}->{last_referenced_on}; + my $chan = ($channel eq '.*' ? 'all channels' : $channel); + # factoid if($factoids->{$channel}->{$trigger}->{type} eq 'text') { - return "$trigger: Factoid submitted by " . $factoids->{$channel}->{$trigger}->{owner} . " on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], referenced " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; + return "$trigger: Factoid submitted by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], referenced " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; } # module if($factoids->{$channel}->{$trigger}->{type} eq 'module') { - return "$trigger: Module loaded by " . $factoids->{$channel}->{$trigger}->{owner} . " on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago] -> http://code.google.com/p/pbot2-pl/source/browse/trunk/modules/" . $factoids->{$channel}->{$trigger}->{action} . ", used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; + return "$trigger: Module loaded by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago] -> http://code.google.com/p/pbot2-pl/source/browse/trunk/modules/" . $factoids->{$channel}->{$trigger}->{action} . ", used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; } # regex if($factoids->{$channel}->{$trigger}->{type} eq 'regex') { - return "$trigger: Regex created by " . $factoids->{$channel}->{$trigger}->{owner} . " on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; + return "$trigger: Regex created by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; } return "/msg $nick $trigger is not a factoid or a module"; diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index adf882d0..87ba6b04 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -153,7 +153,7 @@ sub export_factoids { } sub find_factoid { - my ($self, $from, $keyword, $arguments) = @_; + my ($self, $from, $keyword, $arguments, $exact_channel) = @_; $from = '.*' if not defined $from; @@ -161,7 +161,11 @@ sub find_factoid { my @result = eval { foreach my $channel (sort keys %{ $self->factoids->hash }) { - next unless $from =~ m/$channel/i; + if($exact_channel) { + next unless $from eq $channel; + } else { + next unless $from =~ m/$channel/i; + } foreach my $trigger (keys %{ $self->factoids->hash->{$channel} }) { if($self->factoids->hash->{$channel}->{$trigger}->{type} eq 'regex') { if($string =~ m/$trigger/i) { diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index a12a179a..5daf6d01 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -180,7 +180,8 @@ sub interpret { } elsif($command =~ /^([^ ]+)\s+is\s+(.*)$/) { my ($k, $a) = ($1, $2); - my ($channel, $trigger) = $pbot->factoids->find_factoid($from, $k); + my ($channel, $trigger) = $pbot->factoids->find_factoid($from, $k, undef, 1); + if(defined $trigger) { ($keyword, $arguments) = ($k, "is $a"); } else { diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 2b9747ee..b9c8281d 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 => 190, + BUILD_REVISION => 191, BUILD_DATE => "2010-06-21", };