3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-01 17:16:39 +02:00

Refactor PBot::Core::Factoids into PBot::Core::Factoids::*

This commit is contained in:
Pragmatic Software 2021-07-26 21:39:44 -07:00
parent f51c9fd841
commit c75be8b4b0
13 changed files with 159 additions and 1592 deletions

1
data/commands vendored
View File

@ -153,7 +153,6 @@
"requires_cap" : "1" "requires_cap" : "1"
}, },
"export" : { "export" : {
"background-process" : "1",
"help" : "Exports specified list to HTML file. See https://github.com/pragma-/pbot/blob/master/doc/Admin.md#export", "help" : "Exports specified list to HTML file. See https://github.com/pragma-/pbot/blob/master/doc/Admin.md#export",
"requires_cap" : 1 "requires_cap" : 1
}, },

View File

@ -207,7 +207,7 @@ sub initialize {
# register command/factoid interpreters # register command/factoid interpreters
$self->{interpreter}->register(sub { $self->{commands}->interpreter(@_) }); $self->{interpreter}->register(sub { $self->{commands}->interpreter(@_) });
$self->{interpreter}->register(sub { $self->{factoids}->interpreter(@_) }); $self->{interpreter}->register(sub { $self->{factoids}->{interpreter}->interpreter(@_) });
# give botowner all capabilities # give botowner all capabilities
# -- this must happen last after all modules have registered their capabilities -- # -- this must happen last after all modules have registered their capabilities --

View File

@ -169,7 +169,7 @@ sub interpreter {
} }
unless ($self->get_meta($keyword, 'dont-replace-pronouns')) { unless ($self->get_meta($keyword, 'dont-replace-pronouns')) {
$context->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($context, $context->{arguments}); $context->{arguments} = $self->{pbot}->{factoids}->{variables}->expand_factoid_vars($context, $context->{arguments});
$context->{arglist} = $self->{pbot}->{interpreter}->make_args($context->{arguments}); $context->{arglist} = $self->{pbot}->{interpreter}->make_args($context->{arguments});
} }

View File

@ -75,7 +75,7 @@ sub cmd_call_factoid {
if (not defined $chan or not defined $keyword) { return "Usage: fact <channel> <keyword> [arguments]"; } if (not defined $chan or not defined $keyword) { return "Usage: fact <channel> <keyword> [arguments]"; }
my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $keyword, arguments => $args, exact_channel => 1, exact_trigger => 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->{data}->find($chan, $keyword, arguments => $args, exact_channel => 1, exact_trigger => 1);
if (not defined $trigger) { return "No such factoid $keyword exists for $chan"; } if (not defined $trigger) { return "No such factoid $keyword exists for $chan"; }
@ -85,7 +85,7 @@ sub cmd_call_factoid {
$context->{arguments} = $args; $context->{arguments} = $args;
$context->{root_keyword} = $trigger; $context->{root_keyword} = $trigger;
return $self->{pbot}->{factoids}->interpreter($context); return $self->{pbot}->{factoids}->{interpreter}->interpreter($context);
} }
sub cmd_factundo { sub cmd_factundo {
@ -141,8 +141,8 @@ sub cmd_factundo {
my $path = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/factlog'; my $path = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/factlog';
my $undos = eval { retrieve("$path/$trigger_safe.$channel_path_safe.undo"); }; my $undos = eval { retrieve("$path/$trigger_safe.$channel_path_safe.undo"); };
my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$channel_name = 'global' if $channel_name eq '.*'; $channel_name = 'global' if $channel_name eq '.*';
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
@ -154,7 +154,7 @@ sub cmd_factundo {
return $self->list_undo_history($undos, $list_undos); return $self->list_undo_history($undos, $list_undos);
} }
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my $userinfo = $self->{pbot}->{users}->loggedin($channel, $context->{hostmask}); my $userinfo = $self->{pbot}->{users}->loggedin($channel, $context->{hostmask});
if ($factoids->get_data($channel, $trigger, 'locked')) { if ($factoids->get_data($channel, $trigger, 'locked')) {
return "/say $trigger_name is locked and cannot be reverted." if not $self->{pbot}->{capabilities}->userhas($userinfo, 'admin'); return "/say $trigger_name is locked and cannot be reverted." if not $self->{pbot}->{capabilities}->userhas($userinfo, 'admin');
@ -185,7 +185,7 @@ sub cmd_factundo {
} }
} }
$self->{pbot}->{factoids}->{storage}->add($channel, $trigger, $undos->{list}->[$undos->{idx}], 0, 1); $self->{pbot}->{factoids}->{data}->{storage}->add($channel, $trigger, $undos->{list}->[$undos->{idx}], 0, 1);
my $changes = $self->hash_differences_as_string($undos->{list}->[$undos->{idx} + 1], $undos->{list}->[$undos->{idx}]); my $changes = $self->hash_differences_as_string($undos->{list}->[$undos->{idx} + 1], $undos->{list}->[$undos->{idx}]);
$self->log_factoid($channel, $trigger, $context->{hostmask}, "reverted (undo): $changes", 1); $self->log_factoid($channel, $trigger, $context->{hostmask}, "reverted (undo): $changes", 1);
@ -231,8 +231,8 @@ sub cmd_factredo {
my $channel_path_safe = safe_filename $channel_path; my $channel_path_safe = safe_filename $channel_path;
my $trigger_safe = safe_filename $trigger; my $trigger_safe = safe_filename $trigger;
my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$channel_name = 'global' if $channel_name eq '.*'; $channel_name = 'global' if $channel_name eq '.*';
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
@ -246,7 +246,7 @@ sub cmd_factredo {
return $self->list_undo_history($undos, $list_undos); return $self->list_undo_history($undos, $list_undos);
} }
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my $userinfo = $self->{pbot}->{users}->loggedin($channel, $context->{hostmask}); my $userinfo = $self->{pbot}->{users}->loggedin($channel, $context->{hostmask});
if ($factoids->get_data($channel, $trigger, 'locked')) { if ($factoids->get_data($channel, $trigger, 'locked')) {
return "/say $trigger_name is locked and cannot be reverted." if not defined $self->{pbot}->{capabilities}->userhas($userinfo, 'admin'); return "/say $trigger_name is locked and cannot be reverted." if not defined $self->{pbot}->{capabilities}->userhas($userinfo, 'admin');
@ -276,7 +276,7 @@ sub cmd_factredo {
$self->{pbot}->{logger}->log("Error storing undo: $@\n") if $@; $self->{pbot}->{logger}->log("Error storing undo: $@\n") if $@;
} }
$self->{pbot}->{factoids}->{storage}->add($channel, $trigger, $undos->{list}->[$undos->{idx}], 0, 1); $self->{pbot}->{factoids}->{data}->{storage}->add($channel, $trigger, $undos->{list}->[$undos->{idx}], 0, 1);
my $changes = $self->hash_differences_as_string($undos->{list}->[$undos->{idx} - 1], $undos->{list}->[$undos->{idx}]); my $changes = $self->hash_differences_as_string($undos->{list}->[$undos->{idx} - 1], $undos->{list}->[$undos->{idx}]);
@ -294,7 +294,7 @@ sub cmd_factset {
return $channel if not defined $trigger; # if $trigger is not defined, $channel is an error message return $channel if not defined $trigger; # if $trigger is not defined, $channel is an error message
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
@ -304,7 +304,7 @@ sub cmd_factset {
$channel = '.*' if $channel !~ /^#/; $channel = '.*' if $channel !~ /^#/;
my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, exact_channel => 1, exact_trigger => 1); my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->{data}->find($channel, $trigger, exact_channel => 1, exact_trigger => 1);
my $userinfo; my $userinfo;
@ -328,7 +328,7 @@ sub cmd_factset {
} }
if (defined $value and !$self->{pbot}->{capabilities}->userhas($userinfo, 'admin') if (defined $value and !$self->{pbot}->{capabilities}->userhas($userinfo, 'admin')
and $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, 'locked')) and $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'locked'))
{ {
return "/say $trigger_name is locked; unlock before setting."; return "/say $trigger_name is locked; unlock before setting.";
} }
@ -342,10 +342,10 @@ sub cmd_factset {
return "Your user account must have the $value capability to set cap-override to $value."; return "Your user account must have the $value capability to set cap-override to $value.";
} }
$self->{pbot}->{factoids}->{storage}->set($channel, $trigger, 'locked', '1'); $self->{pbot}->{factoids}->{data}->{storage}->set($channel, $trigger, 'locked', '1');
} }
if (lc $key eq 'locked' and $self->{pbot}->{factoids}->{storage}->exists($channel, $trigger, 'cap-override')) { if (lc $key eq 'locked' and $self->{pbot}->{factoids}->{data}->{storage}->exists($channel, $trigger, 'cap-override')) {
if (not $self->{pbot}->{capabilities}->userhas($userinfo, 'botowner')) { if (not $self->{pbot}->{capabilities}->userhas($userinfo, 'botowner')) {
return "/say $trigger_name has a cap-override and cannot be unlocked until the override is removed."; return "/say $trigger_name has a cap-override and cannot be unlocked until the override is removed.";
} }
@ -353,7 +353,7 @@ sub cmd_factset {
} }
if (defined $owner_channel) { if (defined $owner_channel) {
my $factoid = $self->{pbot}->{factoids}->{storage}->get_data($owner_channel, $owner_trigger); my $factoid = $self->{pbot}->{factoids}->{data}->{storage}->get_data($owner_channel, $owner_trigger);
my $owner; my $owner;
my $mask; my $mask;
@ -376,7 +376,7 @@ sub cmd_factset {
} }
} }
my $result = $self->{pbot}->{factoids}->{storage}->set($channel, $trigger, $key, $value); my $result = $self->{pbot}->{factoids}->{data}->{storage}->set($channel, $trigger, $key, $value);
if (defined $value and $result =~ m/set to/) { $self->log_factoid($channel, $trigger, $context->{hostmask}, "set $key to $value"); } if (defined $value and $result =~ m/set to/) { $self->log_factoid($channel, $trigger, $context->{hostmask}, "set $key to $value"); }
@ -397,7 +397,7 @@ sub cmd_factunset {
return $usage if not length $key; return $usage if not length $key;
my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, exact_channel => 1, exact_trigger => 1); my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->{data}->find($channel, $trigger, exact_channel => 1, exact_trigger => 1);
my $userinfo; my $userinfo;
@ -419,18 +419,18 @@ sub cmd_factunset {
} }
} }
if ($self->{pbot}->{factoids}->{storage}->exists($channel, $trigger, 'cap-override')) { if ($self->{pbot}->{factoids}->{data}->{storage}->exists($channel, $trigger, 'cap-override')) {
if (lc $key eq 'locked') { if (lc $key eq 'locked') {
if ($self->{pbot}->{capabilities}->userhas($userinfo, 'botowner')) { if ($self->{pbot}->{capabilities}->userhas($userinfo, 'botowner')) {
$self->{pbot}->{factoids}->{storage}->unset($channel, $trigger, 'cap-override', 1); $self->{pbot}->{factoids}->{data}->{storage}->unset($channel, $trigger, 'cap-override', 1);
} else { } else {
return "You cannot unlock this factoid because it has a cap-override. Remove the override first."; return "You cannot unlock this factoid because it has a cap-override. Remove the override first.";
} }
} }
} }
my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$channel_name = 'global' if $channel_name eq '.*'; $channel_name = 'global' if $channel_name eq '.*';
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
@ -438,7 +438,7 @@ sub cmd_factunset {
my $oldvalue; my $oldvalue;
if (defined $owner_channel) { if (defined $owner_channel) {
my $factoid = $self->{pbot}->{factoids}->{storage}->get_data($owner_channel, $owner_trigger); my $factoid = $self->{pbot}->{factoids}->{data}->{storage}->get_data($owner_channel, $owner_trigger);
my ($owner) = $factoid->{'owner'} =~ m/([^!]+)/; my ($owner) = $factoid->{'owner'} =~ m/([^!]+)/;
if ($key ne 'action_with_args' and lc $context->{nick} ne lc $owner if ($key ne 'action_with_args' and lc $context->{nick} ne lc $owner
@ -447,7 +447,7 @@ sub cmd_factunset {
return "You are not the owner of $trigger_name."; return "You are not the owner of $trigger_name.";
} }
$oldvalue = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, $key); $oldvalue = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, $key);
} }
if (not defined $oldvalue) { if (not defined $oldvalue) {
@ -460,7 +460,7 @@ sub cmd_factunset {
} }
} }
my $result = $self->{pbot}->{factoids}->{storage}->unset($channel, $trigger, $key); my $result = $self->{pbot}->{factoids}->{data}->{storage}->unset($channel, $trigger, $key);
if ($result =~ m/unset/) { if ($result =~ m/unset/) {
$self->log_factoid($channel, $trigger, $context->{hostmask}, "unset $key (value: $oldvalue)"); $self->log_factoid($channel, $trigger, $context->{hostmask}, "unset $key (value: $oldvalue)");
@ -499,18 +499,18 @@ sub cmd_factmove {
return "/say $context->{nick}: I don't think the channel name needs to be that long."; return "/say $context->{nick}: I don't think the channel name needs to be that long.";
} }
my ($found_src_channel, $found_source) = $self->{pbot}->{factoids}->find_factoid($src_channel, $source, exact_channel => 1, exact_trigger => 1); my ($found_src_channel, $found_source) = $self->{pbot}->{factoids}->{data}->find($src_channel, $source, exact_channel => 1, exact_trigger => 1);
if (not defined $found_src_channel) { if (not defined $found_src_channel) {
return "Source factoid $source not found in channel $src_channel"; return "Source factoid $source not found in channel $src_channel";
} }
my $source_channel_name = $self->{pbot}->{factoids}->{storage}->get_data($found_src_channel, '_name'); my $source_channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($found_src_channel, '_name');
my $source_trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($found_src_channel, $found_source, '_name'); my $source_trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($found_src_channel, $found_source, '_name');
$source_channel_name = 'global' if $source_channel_name eq '.*'; $source_channel_name = 'global' if $source_channel_name eq '.*';
$source_trigger_name = "\"$source_trigger_name\"" if $source_trigger_name =~ / /; $source_trigger_name = "\"$source_trigger_name\"" if $source_trigger_name =~ / /;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my ($owner) = $factoids->get_data($found_src_channel, $found_source, 'owner') =~ m/([^!]+)/; my ($owner) = $factoids->get_data($found_src_channel, $found_source, 'owner') =~ m/([^!]+)/;
if ((lc $context->{nick} ne lc $owner) and (not $self->{pbot}->{users}->loggedin_admin($found_src_channel, $context->{hostmask}))) { if ((lc $context->{nick} ne lc $owner) and (not $self->{pbot}->{users}->loggedin_admin($found_src_channel, $context->{hostmask}))) {
@ -523,7 +523,7 @@ sub cmd_factmove {
return "/say $source_trigger_name is locked; unlock before moving."; return "/say $source_trigger_name is locked; unlock before moving.";
} }
my ($found_target_channel, $found_target) = $self->{pbot}->{factoids}->find_factoid($target_channel, $target, exact_channel => 1, exact_trigger => 1); my ($found_target_channel, $found_target) = $self->{pbot}->{factoids}->{data}->find($target_channel, $target, exact_channel => 1, exact_trigger => 1);
if (defined $found_target_channel) { if (defined $found_target_channel) {
my $target_channel_name = $factoids->get_data($found_target_channel, '_name'); my $target_channel_name = $factoids->get_data($found_target_channel, '_name');
@ -533,7 +533,7 @@ sub cmd_factmove {
return "Target factoid $target_trigger_name already exists in channel $target_channel_name."; return "Target factoid $target_trigger_name already exists in channel $target_channel_name.";
} }
my ($overchannel, $overtrigger) = $self->{pbot}->{factoids}->find_factoid('.*', $target, exact_channel => 1, exact_trigger => 1); my ($overchannel, $overtrigger) = $self->{pbot}->{factoids}->{data}->find('.*', $target, exact_channel => 1, exact_trigger => 1);
if (defined $overtrigger and $factoids->get_data('.*', $overtrigger, 'nooverride')) { if (defined $overtrigger and $factoids->get_data('.*', $overtrigger, 'nooverride')) {
my $override_channel_name = $factoids->get_data($overchannel, '_name'); my $override_channel_name = $factoids->get_data($overchannel, '_name');
my $override_trigger_name = $factoids->get_data($overchannel, $overtrigger, '_name'); my $override_trigger_name = $factoids->get_data($overchannel, $overtrigger, '_name');
@ -587,25 +587,25 @@ sub cmd_factalias {
if (length $chan > $self->{pbot}->{registry}->get_value('factoids', 'max_channel_length')) { return "/say $context->{nick}: I don't think the channel name needs to be that long."; } if (length $chan > $self->{pbot}->{registry}->get_value('factoids', 'max_channel_length')) { return "/say $context->{nick}: I don't think the channel name needs to be that long."; }
my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $alias, exact_channel => 1, exact_trigger => 1); my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->{data}->find($chan, $alias, exact_channel => 1, exact_trigger => 1);
if (defined $alias_trigger) { if (defined $alias_trigger) {
my $alias_channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name'); my $alias_channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, '_name');
my $alias_trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $alias_trigger, '_name'); my $alias_trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $alias_trigger, '_name');
$alias_channel_name = 'global' if $alias_channel_name eq '.*'; $alias_channel_name = 'global' if $alias_channel_name eq '.*';
$alias_trigger_name = "\"$alias_trigger_name\"" if $alias_trigger_name =~ / /; $alias_trigger_name = "\"$alias_trigger_name\"" if $alias_trigger_name =~ / /;
return "$alias_trigger_name already exists for $alias_channel_name."; return "$alias_trigger_name already exists for $alias_channel_name.";
} }
my ($overchannel, $overtrigger) = $self->{pbot}->{factoids}->find_factoid('.*', $alias, exact_channel => 1, exact_trigger => 1); my ($overchannel, $overtrigger) = $self->{pbot}->{factoids}->{data}->find('.*', $alias, exact_channel => 1, exact_trigger => 1);
if (defined $overtrigger and $self->{pbot}->{factoids}->{storage}->get_data('.*', $overtrigger, 'nooverride')) { if (defined $overtrigger and $self->{pbot}->{factoids}->{data}->{storage}->get_data('.*', $overtrigger, 'nooverride')) {
my $override_trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($overchannel, $overtrigger, '_name'); my $override_trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($overchannel, $overtrigger, '_name');
$override_trigger_name = "\"$override_trigger_name\"" if $override_trigger_name =~ / /; $override_trigger_name = "\"$override_trigger_name\"" if $override_trigger_name =~ / /;
return "/say $override_trigger_name already exists for the global channel and cannot be overridden for " . ($chan eq '.*' ? 'the global channel' : $chan) . "."; return "/say $override_trigger_name already exists for the global channel and cannot be overridden for " . ($chan eq '.*' ? 'the global channel' : $chan) . ".";
} }
if ($self->{pbot}->{commands}->exists($alias)) { return "/say $alias already exists as a built-in command."; } if ($self->{pbot}->{commands}->exists($alias)) { return "/say $alias already exists as a built-in command."; }
$self->{pbot}->{factoids}->add_factoid('text', $chan, $context->{hostmask}, $alias, "/call $command"); $self->{pbot}->{factoids}->{data}->add('text', $chan, $context->{hostmask}, $alias, "/call $command");
$self->{pbot}->{logger}->log("$context->{hostmask} [$chan] aliased $alias => $command\n"); $self->{pbot}->{logger}->log("$context->{hostmask} [$chan] aliased $alias => $command\n");
return "/say $alias aliases `$command` for " . ($chan eq '.*' ? 'the global channel' : $chan); return "/say $alias aliases `$command` for " . ($chan eq '.*' ? 'the global channel' : $chan);
} }
@ -621,8 +621,8 @@ sub cmd_add_regex {
if (not defined $text) { if (not defined $text) {
my @regexes; my @regexes;
my $iter = $self->{pbot}->{factoids}->{storage}->get_each('type = regex', "index1 = $keyword", 'index2', '_sort = index2'); my $iter = $self->{pbot}->{factoids}->{data}->{storage}->get_each('type = regex', "index1 = $keyword", 'index2', '_sort = index2');
while (defined (my $factoid = $self->{pbot}->{factoids}->{storage}->get_next($iter))) { while (defined (my $factoid = $self->{pbot}->{factoids}->{data}->{storage}->get_next($iter))) {
push @regexes, $factoid->{index2}; push @regexes, $factoid->{index2};
} }
$text = join '; ', @regexes; $text = join '; ', @regexes;
@ -631,19 +631,20 @@ sub cmd_add_regex {
} }
my $trigger; my $trigger;
($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $keyword, exact_channel => 1, exact_trigger => 1); ($channel, $trigger) = $self->{pbot}->{factoids}->{data}->find($channel, $keyword, exact_channel => 1, exact_trigger => 1);
if (defined $trigger) { if (defined $trigger) {
return "/say $trigger already exists for channel $channel."; return "/say $trigger already exists for channel $channel.";
} }
$self->{pbot}->{factoids}->add_factoid('regex', $channel, $context->{hostmask}, $keyword, $text); $self->{pbot}->{factoids}->{data}->add('regex', $channel, $context->{hostmask}, $keyword, $text);
$self->{pbot}->{logger}->log("$context->{hostmask} added regex [$keyword] => [$text]\n"); $self->{pbot}->{logger}->log("$context->{hostmask} added regex [$keyword] => [$text]\n");
return "/say $keyword added."; return "/say $keyword added.";
} }
sub cmd_factadd { sub cmd_factadd {
my ($self, $context) = @_; my ($self, $context) = @_;
my ($from_chan, $keyword, $text, $force); my ($from_chan, $keyword, $text, $force);
my @arglist = @{$context->{arglist}}; my @arglist = @{$context->{arglist}};
@ -656,8 +657,11 @@ sub cmd_factadd {
} }
# check if this is an optional channel argument # check if this is an optional channel argument
if ($arglist[0] =~ m/(?:^#|^global$|^\.\*$)/i) { $from_chan = $self->{pbot}->{interpreter}->shift_arg(\@arglist); } if ($arglist[0] =~ m/(?:^#|^global$|^\.\*$)/i) {
else { $from_chan = $context->{from}; } $from_chan = $self->{pbot}->{interpreter}->shift_arg(\@arglist);
} else {
$from_chan = $context->{from};
}
# check for -f again since we also allow it to appear after the channel argument # check for -f again since we also allow it to appear after the channel argument
if ($arglist[0] eq '-f') { if ($arglist[0] eq '-f') {
@ -677,7 +681,9 @@ sub cmd_factadd {
my ($url) = $self->{pbot}->{interpreter}->split_args(\@arglist, 1); my ($url) = $self->{pbot}->{interpreter}->split_args(\@arglist, 1);
# FIXME: move this to registry # FIXME: move this to registry
if ($url !~ m/^https?:\/\/(?:sprunge.us|ix.io)\/\w+$/) { return "Invalid URL: acceptable URLs are: http://sprunge.us, http://ix.io"; } if ($url !~ m/^https?:\/\/(?:sprunge.us|ix.io)\/\w+$/) {
return "Invalid URL: acceptable URLs are: http://sprunge.us, http://ix.io";
}
# create a UserAgent # create a UserAgent
my $ua = LWP::UserAgent->new(timeout => 10); my $ua = LWP::UserAgent->new(timeout => 10);
@ -686,11 +692,16 @@ sub cmd_factadd {
my $response = $ua->get($url); my $response = $ua->get($url);
# process the response # process the response
if ($response->is_success) { $text = $response->decoded_content; } if ($response->is_success) {
else { return "Failed to get URL: " . $response->status_line; } $text = $response->decoded_content;
} else {
return "Failed to get URL: " . $response->status_line;
}
} else { } else {
# check for optional "is" and discard # check for optional "is" and discard
if (lc $arglist[0] eq 'is') { $self->{pbot}->{interpreter}->shift_arg(\@arglist); } if (lc $arglist[0] eq 'is') {
$self->{pbot}->{interpreter}->shift_arg(\@arglist);
}
# and the text is the remaining arguments with quotes preserved # and the text is the remaining arguments with quotes preserved
($text) = $self->{pbot}->{interpreter}->split_args(\@arglist, 1, 0, 1); ($text) = $self->{pbot}->{interpreter}->split_args(\@arglist, 1, 0, 1);
@ -703,48 +714,59 @@ sub cmd_factadd {
$from_chan = '.*' if $from_chan !~ /^#/; $from_chan = '.*' if $from_chan !~ /^#/;
if (length $keyword > $self->{pbot}->{registry}->get_value('factoids', 'max_name_length')) { return "/say $context->{nick}: I don't think the factoid name needs to be that long."; } if (length $keyword > $self->{pbot}->{registry}->get_value('factoids', 'max_name_length')) {
return "/say $context->{nick}: I don't think the factoid name needs to be that long.";
}
if (length $from_chan > $self->{pbot}->{registry}->get_value('factoids', 'max_channel_length')) { return "/say $context->{nick}: I don't think the channel needs to be that long."; } if (length $from_chan > $self->{pbot}->{registry}->get_value('factoids', 'max_channel_length')) {
return "/say $context->{nick}: I don't think the channel needs to be that long.";
}
$from_chan = '.*' if lc $from_chan eq 'global'; $from_chan = '.*' if lc $from_chan eq 'global';
$from_chan = '.*' if not $from_chan =~ m/^#/; $from_chan = '.*' if not $from_chan =~ m/^#/;
my $keyword_text = $keyword =~ / / ? "\"$keyword\"" : $keyword; my $keyword_text = $keyword =~ / / ? "\"$keyword\"" : $keyword;
my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $keyword, exact_channel => 1, exact_trigger => 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->{data}->find($from_chan, $keyword, exact_channel => 1, exact_trigger => 1);
if (defined $trigger) { if (defined $trigger) {
my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$channel_name = 'global' if $channel_name eq '.*'; $channel_name = 'global' if $channel_name eq '.*';
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
if (not $force) { if (not $force) {
return "/say $trigger_name already exists for $channel_name."; return "/say $trigger_name already exists for $channel_name.";
} else { } else {
my $factoids = $self->{pbot}->{factoids}->{storage}; if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'locked')) {
if ($factoids->get_data($channel, $trigger, 'locked')) { return "/say $trigger_name is locked; unlock before overwriting."; } return "/say $trigger_name is locked; unlock before overwriting.";
}
} }
} }
($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid('.*', $keyword, exact_channel => 1, exact_trigger => 1); ($channel, $trigger) = $self->{pbot}->{factoids}->{data}->find('.*', $keyword, exact_channel => 1, exact_trigger => 1);
if (defined $trigger and $self->{pbot}->{factoids}->{storage}->get_data('.*', $trigger, 'nooverride')) {
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); if (defined $trigger and $self->{pbot}->{factoids}->{data}->{storage}->get_data('.*', $trigger, 'nooverride')) {
my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
return "/say $trigger_name already exists for the global channel and cannot be overridden for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; return "/say $trigger_name 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_text already exists as a built-in command."; } if ($self->{pbot}->{commands}->exists($keyword)) { return "/say $keyword_text already exists as a built-in command."; }
$self->{pbot}->{factoids}->add_factoid('text', $from_chan, $context->{hostmask}, $keyword, $text); $self->{pbot}->{factoids}->{data}->add('text', $from_chan, $context->{hostmask}, $keyword, $text);
$self->{pbot}->{logger}->log("$context->{hostmask} added [$from_chan] $keyword_text => $text\n"); $self->{pbot}->{logger}->log("$context->{hostmask} added [$from_chan] $keyword_text => $text\n");
$self->log_factoid($channel, $trigger, $context->{hostmask}, "created");
$self->log_factoid($from_chan, $keyword, $context->{hostmask}, "created");
return "/say $keyword_text added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; return "/say $keyword_text added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . ".";
} }
sub cmd_factrem { sub cmd_factrem {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my ($from_chan, $from_trig) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2); my ($from_chan, $from_trig) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
@ -780,12 +802,12 @@ sub cmd_factrem {
$self->{pbot}->{logger}->log("$context->{hostmask} removed [$channel][$trigger][" . $factoids->get_data($channel, $trigger, 'action') . "]\n"); $self->{pbot}->{logger}->log("$context->{hostmask} removed [$channel][$trigger][" . $factoids->get_data($channel, $trigger, 'action') . "]\n");
$self->log_factoid($channel, $trigger, $context->{hostmask}, "deleted", 1); $self->log_factoid($channel, $trigger, $context->{hostmask}, "deleted", 1);
return '/say '. $self->{pbot}->{factoids}->remove_factoid($channel, $trigger); return '/say '. $self->{pbot}->{factoids}->{data}->remove($channel, $trigger);
} }
sub cmd_factshow { sub cmd_factshow {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
$context->{preserve_whitespace} = 1; $context->{preserve_whitespace} = 1;
my $usage = "Usage: factshow [-p] [channel] <keyword>; -p to paste"; my $usage = "Usage: factshow [-p] [channel] <keyword>; -p to paste";
return $usage if not length $context->{arguments}; return $usage if not length $context->{arguments};
@ -909,7 +931,7 @@ sub cmd_factlog {
sub cmd_factinfo { sub cmd_factinfo {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2); my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
if (not defined $trig) { if (not defined $trig) {
@ -1006,7 +1028,7 @@ sub cmd_factfind {
my $usage = "Usage: factfind [-channel channel] [-owner regex] [-editby regex] [-refby regex] [-regex] [text]"; my $usage = "Usage: factfind [-channel channel] [-owner regex] [-editby regex] [-refby regex] [-regex] [text]";
return $usage if not length $arguments; return $usage if not length $arguments;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my ($channel, $owner, $refby, $editby, $use_regex); my ($channel, $owner, $refby, $editby, $use_regex);
$channel = $1 if $arguments =~ s/\s*-channel\s+([^\b\s]+)//i; $channel = $1 if $arguments =~ s/\s*-channel\s+([^\b\s]+)//i;
$owner = $1 if $arguments =~ s/\s*-owner\s+([^\b\s]+)//i; $owner = $1 if $arguments =~ s/\s*-owner\s+([^\b\s]+)//i;
@ -1111,7 +1133,7 @@ sub cmd_factfind {
sub cmd_factchange { sub cmd_factchange {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids_data = $self->{pbot}->{factoids}->{storage}; my $factoids_data = $self->{pbot}->{factoids}->{data}->{storage};
my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier, $url); my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier, $url);
$context->{preserve_whitespace} = 1; $context->{preserve_whitespace} = 1;
@ -1168,7 +1190,7 @@ sub cmd_factchange {
} }
my ($from_trigger, $from_chan) = ($keyword, $channel); my ($from_trigger, $from_chan) = ($keyword, $channel);
my @factoids = $self->{pbot}->{factoids}->find_factoid($from_chan, $keyword, exact_trigger => 1); my @factoids = $self->{pbot}->{factoids}->{data}->find($from_chan, $keyword, exact_trigger => 1);
if (not @factoids or not $factoids[0]) { if (not @factoids or not $factoids[0]) {
$from_chan = 'global channel' if $from_chan eq '.*'; $from_chan = 'global channel' if $from_chan eq '.*';
@ -1195,8 +1217,8 @@ sub cmd_factchange {
if (not defined $trigger) { return "/say $keyword not found in channel $from_chan."; } if (not defined $trigger) { return "/say $keyword not found in channel $from_chan."; }
my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$channel_name = 'global' if $channel_name eq '.*'; $channel_name = 'global' if $channel_name eq '.*';
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
@ -1297,7 +1319,7 @@ sub cmd_factchange {
sub cmd_top20 { sub cmd_top20 {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my %hash = (); my %hash = ();
my $text = ""; my $text = "";
my $i = 0; my $i = 0;
@ -1357,7 +1379,7 @@ sub cmd_top20 {
sub cmd_histogram { sub cmd_histogram {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my %owners; my %owners;
my $factoid_count = 0; my $factoid_count = 0;
@ -1382,7 +1404,7 @@ sub cmd_histogram {
sub cmd_count { sub cmd_count {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
my $i = 0; my $i = 0;
my $total = 0; my $total = 0;
@ -1456,7 +1478,7 @@ sub log_factoid {
if ($undos->{idx} > -1 and @{$undos->{list}} > $undos->{idx} + 1) { splice @{$undos->{list}}, $undos->{idx} + 1; } if ($undos->{idx} > -1 and @{$undos->{list}} > $undos->{idx} + 1) { splice @{$undos->{list}}, $undos->{idx} + 1; }
push @{$undos->{list}}, $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger); push @{$undos->{list}}, $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger);
$undos->{idx}++; $undos->{idx}++;
eval { store $undos, "$path/$trigger_safe.$channel_path_safe.undo"; }; eval { store $undos, "$path/$trigger_safe.$channel_path_safe.undo"; };
@ -1506,14 +1528,14 @@ sub find_factoid_with_optional_channel {
my ($channel, $trigger); my ($channel, $trigger);
if ($opts{exact_channel} == 1) { if ($opts{exact_channel} == 1) {
($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $from_trigger, exact_channel => 1, exact_trigger => 1); ($channel, $trigger) = $self->{pbot}->{factoids}->{data}->find($from_chan, $from_trigger, exact_channel => 1, exact_trigger => 1);
if (not defined $channel) { if (not defined $channel) {
$from_chan = 'the global channel' if $from_chan eq '.*'; $from_chan = 'the global channel' if $from_chan eq '.*';
return "/say $from_trigger not found in $from_chan."; return "/say $from_trigger not found in $from_chan.";
} }
} else { } else {
my @factoids = $self->{pbot}->{factoids}->find_factoid($from_chan, $from_trigger, exact_trigger => 1); my @factoids = $self->{pbot}->{factoids}->{data}->find($from_chan, $from_trigger, exact_trigger => 1);
if (not @factoids or not $factoids[0]) { if (not @factoids or not $factoids[0]) {
if ($needs_disambig) { return "/say $from_trigger not found"; } if ($needs_disambig) { return "/say $from_trigger not found"; }
@ -1553,8 +1575,8 @@ sub find_factoid_with_optional_channel {
$from_chan = '.*' if $channel eq 'global'; $from_chan = '.*' if $channel eq 'global';
if ($opts{explicit} and $channel =~ /^#/ and $from_chan =~ /^#/ and lc $channel ne $from_chan) { if ($opts{explicit} and $channel =~ /^#/ and $from_chan =~ /^#/ and lc $channel ne $from_chan) {
my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, '_name');
$channel_name = 'global' if $channel_name eq '.*'; $channel_name = 'global' if $channel_name eq '.*';
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
return "/say $trigger_name belongs to $channel_name, not $from_chan. Please switch to or explicitly specify $channel_name."; return "/say $trigger_name belongs to $channel_name, not $from_chan. Please switch to or explicitly specify $channel_name.";

View File

@ -67,7 +67,7 @@ sub cmd_help {
} }
# find factoids # find factoids
my @factoids = $self->{pbot}->{factoids}->find_factoid($channel_arg, $keyword, exact_trigger => 1); my @factoids = $self->{pbot}->{factoids}->{data}->find($channel_arg, $keyword, exact_trigger => 1);
if (not @factoids or not $factoids[0]) { if (not @factoids or not $factoids[0]) {
# nothing found # nothing found
@ -96,8 +96,8 @@ sub cmd_help {
} }
# get canonical channel and trigger names with original typographical casing # get canonical channel and trigger names with original typographical casing
my $channel_name = $self->{pbot}->{factoids}->{storage}->get_key_name($channel); my $channel_name = $self->{pbot}->{factoids}->{data}->{storage}->get_key_name($channel);
my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_key_name($channel, $trigger); my $trigger_name = $self->{pbot}->{factoids}->{data}->{storage}->get_key_name($channel, $trigger);
# prettify channel name if it's ".*" # prettify channel name if it's ".*"
if ($channel_name eq '.*') { if ($channel_name eq '.*') {
@ -110,7 +110,7 @@ sub cmd_help {
} }
# get factoid's `help` metadata # get factoid's `help` metadata
my $help = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, 'help'); my $help = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'help');
# return immediately if no help text # return immediately if no help text
if (not defined $help or not length $help) { if (not defined $help or not length $help) {

View File

@ -81,11 +81,11 @@ sub cmd_list {
if ($context->{arguments} =~ /^modules$/i) { if ($context->{arguments} =~ /^modules$/i) {
$text = 'Loaded modules: '; $text = 'Loaded modules: ';
foreach my $channel (sort $self->{pbot}->{factoids}->{storage}->get_keys) { foreach my $channel (sort $self->{pbot}->{factoids}->{data}->{storage}->get_keys) {
foreach my $command (sort $self->{pbot}->{factoids}->{storage}->get_keys($channel)) { foreach my $command (sort $self->{pbot}->{factoids}->{data}->{storage}->get_keys($channel)) {
next if $command eq '_name'; next if $command eq '_name';
if ($self->{pbot}->{factoids}->{storage}->get_data($channel, $command, 'type') eq 'module') { if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $command, 'type') eq 'module') {
$text .= $self->{pbot}->{factoids}->{storage}->get_data($channel, $command, '_name') . ' '; $text .= $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $command, '_name') . ' ';
} }
} }
} }
@ -128,8 +128,16 @@ sub cmd_die {
sub cmd_export { sub cmd_export {
my ($self, $context) = @_; my ($self, $context) = @_;
return "Usage: export <factoids>" if not length $context->{arguments};
if ($context->{arguments} =~ /^factoids$/i) { return $self->{pbot}->{factoids}->export_factoids; } my $usage = "Usage: export factoids";
return $usage if not length $context->{arguments};
if ($context->{arguments} =~ /^factoids$/i) {
return $self->{pbot}->{factoids}->{exporter}->export;
}
return $usage;
} }
sub cmd_eval { sub cmd_eval {

View File

@ -28,13 +28,13 @@ sub cmd_load {
return "Usage: load <keyword> <module>" if not defined $module; return "Usage: load <keyword> <module>" if not defined $module;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
if ($factoids->exists('.*', $keyword)) { if ($factoids->exists('.*', $keyword)) {
return 'There is already a keyword named ' . $factoids->get_data('.*', $keyword, '_name') . '.'; return 'There is already a keyword named ' . $factoids->get_data('.*', $keyword, '_name') . '.';
} }
$self->{pbot}->{factoids}->add_factoid('module', '.*', $context->{hostmask}, $keyword, $module, 1); $self->{pbot}->{factoids}->{data}->add_factoid('module', '.*', $context->{hostmask}, $keyword, $module, 1);
$factoids->set('.*', $keyword, 'add_nick', 1, 1); $factoids->set('.*', $keyword, 'add_nick', 1, 1);
$factoids->set('.*', $keyword, 'nooverride', 1); $factoids->set('.*', $keyword, 'nooverride', 1);
@ -51,7 +51,7 @@ sub cmd_unload {
return "Usage: unload <keyword>" if not defined $module; return "Usage: unload <keyword>" if not defined $module;
my $factoids = $self->{pbot}->{factoids}->{storage}; my $factoids = $self->{pbot}->{factoids}->{data}->{storage};
if (not $factoids->exists('.*', $module)) { if (not $factoids->exists('.*', $module)) {
return "/say $module not found."; return "/say $module not found.";

View File

@ -72,7 +72,7 @@ sub cmd_reload {
}, },
'factoids' => sub { 'factoids' => sub {
$self->{pbot}->{factoids}->load_factoids; $self->{pbot}->{factoids}->{data}->load;
return "Factoids reloaded."; return "Factoids reloaded.";
} }
); );

File diff suppressed because it is too large Load Diff

View File

@ -418,7 +418,7 @@ sub interpret {
# replace pronouns like "i", "my", etc, with "nick", "nick's", etc # replace pronouns like "i", "my", etc, with "nick", "nick's", etc
if (not $self->{pbot}->{commands}->get_meta($keyword, 'dont-replace-pronouns') if (not $self->{pbot}->{commands}->get_meta($keyword, 'dont-replace-pronouns')
and not $self->{pbot}->{factoids}->get_meta($context->{from}, $keyword, 'dont-replace-pronouns')) and not $self->{pbot}->{factoids}->{data}->get_meta($context->{from}, $keyword, 'dont-replace-pronouns'))
{ {
# if command recipient is "me" then replace it with invoker's nick # if command recipient is "me" then replace it with invoker's nick
@ -449,7 +449,7 @@ sub interpret {
# the bot doesn't like performing bot commands on itself # the bot doesn't like performing bot commands on itself
# unless dont-protect-self is true # unless dont-protect-self is true
if (not $self->{pbot}->{commands}->get_meta($keyword, 'dont-protect-self') if (not $self->{pbot}->{commands}->get_meta($keyword, 'dont-protect-self')
and not $self->{pbot}->{factoids}->get_meta($context->{from}, $keyword, 'dont-protect-self')) and not $self->{pbot}->{factoids}->{data}->get_meta($context->{from}, $keyword, 'dont-protect-self'))
{ {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
@ -636,7 +636,7 @@ sub handle_result {
my $use_output_queue = 0; my $use_output_queue = 0;
if (not $self->{pbot}->{commands}->exists($context->{keyword})) { if (not $self->{pbot}->{commands}->exists($context->{keyword})) {
my @factoids = $self->{pbot}->{factoids}->find_factoid($context->{from}, $context->{keyword}, my @factoids = $self->{pbot}->{factoids}->{data}->find($context->{from}, $context->{keyword},
arguments => $context->{arguments}, arguments => $context->{arguments},
exact_channel => 0, exact_channel => 0,
exact_trigger => 0, exact_trigger => 0,
@ -647,10 +647,10 @@ sub handle_result {
my ($chan, $trigger) = ($factoids[0]->[0], $factoids[0]->[1]); my ($chan, $trigger) = ($factoids[0]->[0], $factoids[0]->[1]);
if ($context->{preserve_whitespace} == 0) { if ($context->{preserve_whitespace} == 0) {
$context->{preserve_whitespace} = $self->{pbot}->{factoids}->{storage}->get_data($chan, $trigger, 'preserve_whitespace') // 0; $context->{preserve_whitespace} = $self->{pbot}->{factoids}->{data}->{storage}->get_data($chan, $trigger, 'preserve_whitespace') // 0;
} }
$use_output_queue = $self->{pbot}->{factoids}->{storage}->get_data($chan, $trigger, 'use_output_queue') // 0; $use_output_queue = $self->{pbot}->{factoids}->{data}->{storage}->get_data($chan, $trigger, 'use_output_queue') // 0;
} }
} }

View File

@ -40,7 +40,7 @@ sub launch_module {
$context->{arguments} //= ''; $context->{arguments} //= '';
my @factoids = $self->{pbot}->{factoids}->find_factoid($context->{from}, $context->{keyword}, exact_channel => 2, exact_trigger => 2); my @factoids = $self->{pbot}->{factoids}->{data}->find($context->{from}, $context->{keyword}, exact_channel => 2, exact_trigger => 2);
if (not @factoids or not $factoids[0]) { if (not @factoids or not $factoids[0]) {
$context->{checkflood} = 1; $context->{checkflood} = 1;
@ -54,14 +54,14 @@ sub launch_module {
$context->{keyword} = $trigger; $context->{keyword} = $trigger;
$context->{trigger} = $trigger; $context->{trigger} = $trigger;
my $module = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, 'action'); my $module = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'action');
$self->{pbot}->{logger}->log( $self->{pbot}->{logger}->log(
'(' . (defined $context->{from} ? $context->{from} : "(undef)") . '): ' '(' . (defined $context->{from} ? $context->{from} : "(undef)") . '): '
. "$context->{hostmask}: Executing module [$context->{command}] $module $context->{arguments}\n" . "$context->{hostmask}: Executing module [$context->{command}] $module $context->{arguments}\n"
); );
$context->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($context, $context->{arguments}); $context->{arguments} = $self->{pbot}->{factoids}->{variables}->expand_factoid_vars($context, $context->{arguments});
my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir'); my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir');
@ -70,8 +70,8 @@ sub launch_module {
Carp::croak("Could not chdir to '$module_dir': $!"); Carp::croak("Could not chdir to '$module_dir': $!");
} }
if ($self->{pbot}->{factoids}->{storage}->exists($channel, $trigger, 'workdir')) { if ($self->{pbot}->{factoids}->{data}->{storage}->exists($channel, $trigger, 'workdir')) {
chdir $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, 'workdir'); chdir $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $trigger, 'workdir');
} }
# FIXME -- add check to ensure $module exists # FIXME -- add check to ensure $module exists

View File

@ -186,7 +186,7 @@ sub process_pipe_reader {
} }
$context->{original_keyword} = $context->{root_keyword}; $context->{original_keyword} = $context->{root_keyword};
$context->{result} = $self->{pbot}->{factoids}->handle_action($context, $context->{result}); $context->{result} = $self->{pbot}->{factoids}->{interpreter}->handle_action($context, $context->{result});
} }
# if nick isn't overridden yet, check for a potential nick prefix # if nick isn't overridden yet, check for a potential nick prefix
@ -196,8 +196,8 @@ sub process_pipe_reader {
# if add_nick is set on the factoid, set the nick override to the caller's nick # if add_nick is set on the factoid, set the nick override to the caller's nick
if (exists $context->{special} and $context->{special} ne 'code-factoid' if (exists $context->{special} and $context->{special} ne 'code-factoid'
and $self->{pbot}->{factoids}->{storage}->exists($context->{channel}, $context->{trigger}, 'add_nick') and $self->{pbot}->{factoids}->{data}->{storage}->exists($context->{channel}, $context->{trigger}, 'add_nick')
and $self->{pbot}->{factoids}->{storage}->get_data($context->{channel}, $context->{trigger}, 'add_nick') != 0) and $self->{pbot}->{factoids}->{data}->{storage}->get_data($context->{channel}, $context->{trigger}, 'add_nick') != 0)
{ {
$context->{nickprefix} = $context->{nick}; $context->{nickprefix} = $context->{nick};
$context->{nickprefix_disabled} = 0; $context->{nickprefix_disabled} = 0;

View File

@ -168,13 +168,13 @@ sub plang_validate_builtin_print {
sub is_locked { sub is_locked {
my ($self, $channel, $keyword) = @_; my ($self, $channel, $keyword) = @_;
return $self->{pbot}->{factoids}->get_meta($channel, $keyword, 'locked'); return $self->{pbot}->{factoids}->{data}->get_meta($channel, $keyword, 'locked');
} }
sub plang_builtin_factget { sub plang_builtin_factget {
my ($self, $plang, $context, $name, $arguments) = @_; my ($self, $plang, $context, $name, $arguments) = @_;
my ($channel, $keyword, $meta) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]); my ($channel, $keyword, $meta) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]);
my $result = $self->{pbot}->{factoids}->get_meta($channel, $keyword, $meta); my $result = $self->{pbot}->{factoids}->{data}->get_meta($channel, $keyword, $meta);
if (defined $result) { if (defined $result) {
return [['TYPE', 'String'], $result]; return [['TYPE', 'String'], $result];
} else { } else {
@ -190,7 +190,7 @@ sub plang_builtin_factset {
my ($self, $plang, $context, $name, $arguments) = @_; my ($self, $plang, $context, $name, $arguments) = @_;
my ($channel, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]); my ($channel, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]);
die "Factoid $channel.$keyword is locked. Cannot set.\n" if $self->is_locked($channel, $keyword); die "Factoid $channel.$keyword is locked. Cannot set.\n" if $self->is_locked($channel, $keyword);
$self->{pbot}->{factoids}->add_factoid('text', $channel, 'Plang', $keyword, $text); $self->{pbot}->{factoids}->{data}->add_factoid('text', $channel, 'Plang', $keyword, $text);
return [['TYPE', 'String'], $text]; return [['TYPE', 'String'], $text];
} }
@ -202,10 +202,10 @@ sub plang_builtin_factappend {
my ($self, $plang, $context, $name, $arguments) = @_; my ($self, $plang, $context, $name, $arguments) = @_;
my ($channel, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]); my ($channel, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]);
die "Factoid $channel.$keyword is locked. Cannot append.\n" if $self->is_locked($channel, $keyword); die "Factoid $channel.$keyword is locked. Cannot append.\n" if $self->is_locked($channel, $keyword);
my $action = $self->{pbot}->{factoids}->get_meta($channel, $keyword, 'action'); my $action = $self->{pbot}->{factoids}->{data}->get_meta($channel, $keyword, 'action');
$action = "" if not defined $action; $action = "" if not defined $action;
$action .= $text; $action .= $text;
$self->{pbot}->{factoids}->add_factoid('text', $channel, 'Plang', $keyword, $action); $self->{pbot}->{factoids}->{data}->add_factoid('text', $channel, 'Plang', $keyword, $action);
return [['TYPE', 'String'], $action]; return [['TYPE', 'String'], $action];
} }