mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
Adding factoid in a channel now creates that factoid in that channel instead of .*; info command now shows what channel factoid belongs to
This commit is contained in:
parent
645310de15
commit
562d265261
@ -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 <regex> <command>";
|
||||
}
|
||||
|
||||
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";
|
||||
|
@ -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 }) {
|
||||
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) {
|
||||
|
@ -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 {
|
||||
|
@ -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",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user