3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 03:33:06 +01:00

Rename various duplicated backend keys, e.g., $pbot->{factoids}->{factoids} to, e.g., $pbot->{factoids}->{storage}

This commit is contained in:
Pragmatic Software 2021-07-09 14:39:35 -07:00
parent 1158c36ce1
commit 61881535fa
22 changed files with 310 additions and 280 deletions

View File

@ -548,7 +548,7 @@ sub check_flood {
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $chan, $chan_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $chan, $chan_data);
} else { # private message flood } else { # private message flood
my $hostmask = $self->address_to_mask($host); my $hostmask = $self->address_to_mask($host);
next if $self->{pbot}->{ignorelist}->{ignorelist}->exists($chan, "*!$user\@$hostmask"); next if $self->{pbot}->{ignorelist}->{storage}->exists($chan, "*!$user\@$hostmask");
my $chan_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $chan, 'offenses', 'last_offense'); my $chan_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $chan, 'offenses', 'last_offense');
$chan_data->{offenses}++; $chan_data->{offenses}++;

View File

@ -56,7 +56,7 @@ sub cmd_cap {
} }
my $result = "Users with capability $cap: "; my $result = "Users with capability $cap: ";
my $users = $self->{pbot}->{users}->{users}; my $users = $self->{pbot}->{users}->{storage};
my @matches; my @matches;
foreach my $name (sort $users->get_keys) { foreach my $name (sort $users->get_keys) {
@ -85,13 +85,13 @@ sub cmd_cap {
$cap = lc $cap if defined $cap; $cap = lc $cap if defined $cap;
my $u = $self->{pbot}->{users}->{users}->get_data($name); my $u = $self->{pbot}->{users}->{storage}->get_data($name);
if (not defined $u) { if (not defined $u) {
return "No such user $name."; return "No such user $name.";
} }
$name = $self->{pbot}->{users}->{users}->get_key_name($name); $name = $self->{pbot}->{users}->{storage}->get_key_name($name);
if (defined $cap) { if (defined $cap) {
if (not $self->exists($cap)) { if (not $self->exists($cap)) {

View File

@ -57,9 +57,9 @@ sub can_gain_ops {
my ($self, $channel) = @_; my ($self, $channel) = @_;
$channel = lc $channel; $channel = lc $channel;
return return
$self->{pbot}->{channels}->{channels}->exists($channel) $self->{pbot}->{channels}->{storage}->exists($channel)
&& $self->{pbot}->{channels}->{channels}->get_data($channel, 'chanop') && $self->{pbot}->{channels}->{storage}->get_data($channel, 'chanop')
&& $self->{pbot}->{channels}->{channels}->get_data($channel, 'enabled'); && $self->{pbot}->{channels}->{storage}->get_data($channel, 'enabled');
} }
sub gain_ops { sub gain_ops {
@ -125,13 +125,13 @@ sub check_opped_timeouts {
my $now = gettimeofday(); my $now = gettimeofday();
foreach my $channel (keys %{$self->{is_opped}}) { foreach my $channel (keys %{$self->{is_opped}}) {
if ($self->{is_opped}->{$channel}{timeout} < $now) { if ($self->{is_opped}->{$channel}{timeout} < $now) {
unless ($self->{pbot}->{channels}->{channels}->exists($channel) and $self->{pbot}->{channels}->{channels}->get_data($channel, 'permop')) { $self->lose_ops($channel); } unless ($self->{pbot}->{channels}->{storage}->exists($channel) and $self->{pbot}->{channels}->{storage}->get_data($channel, 'permop')) { $self->lose_ops($channel); }
} }
} }
foreach my $channel (keys %{$self->{op_requested}}) { foreach my $channel (keys %{$self->{op_requested}}) {
if ($now - $self->{op_requested}->{$channel} > 60 * 5) { if ($now - $self->{op_requested}->{$channel} > 60 * 5) {
if ($self->{pbot}->{channels}->{channels}->exists($channel) and $self->{pbot}->{channels}->{channels}->get_data($channel, 'enabled')) { if ($self->{pbot}->{channels}->{storage}->exists($channel) and $self->{pbot}->{channels}->{storage}->get_data($channel, 'enabled')) {
$self->{pbot}->{logger}->log("5 minutes since OP request for $channel and no OP yet; trying again ...\n"); $self->{pbot}->{logger}->log("5 minutes since OP request for $channel and no OP yet; trying again ...\n");
delete $self->{op_requested}->{$channel}; delete $self->{op_requested}->{$channel};
$self->gain_ops($channel); $self->gain_ops($channel);

View File

@ -13,8 +13,8 @@ use PBot::Imports;
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{channels} = PBot::HashObject->new(pbot => $self->{pbot}, name => 'Channels', filename => $conf{filename}); $self->{storage} = PBot::HashObject->new(pbot => $self->{pbot}, name => 'Channels', filename => $conf{filename});
$self->{channels}->load; $self->{storage}->load;
$self->{pbot}->{commands}->register(sub { $self->cmd_join(@_) }, "join", 1); $self->{pbot}->{commands}->register(sub { $self->cmd_join(@_) }, "join", 1);
$self->{pbot}->{commands}->register(sub { $self->cmd_part(@_) }, "part", 1); $self->{pbot}->{commands}->register(sub { $self->cmd_part(@_) }, "part", 1);
@ -52,14 +52,14 @@ sub cmd_set {
my ($self, $context) = @_; my ($self, $context) = @_;
my ($channel, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3); my ($channel, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
return "Usage: chanset <channel> [key [value]]" if not defined $channel; return "Usage: chanset <channel> [key [value]]" if not defined $channel;
return $self->{channels}->set($channel, $key, $value); return $self->{storage}->set($channel, $key, $value);
} }
sub cmd_unset { sub cmd_unset {
my ($self, $context) = @_; my ($self, $context) = @_;
my ($channel, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2); my ($channel, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: chanunset <channel> <key>" if not defined $channel or not defined $key; return "Usage: chanunset <channel> <key>" if not defined $channel or not defined $key;
return $self->{channels}->unset($channel, $key); return $self->{storage}->unset($channel, $key);
} }
sub cmd_add { sub cmd_add {
@ -72,7 +72,7 @@ sub cmd_add {
permop => 0 permop => 0
}; };
return $self->{channels}->add($context->{arguments}, $data); return $self->{storage}->add($context->{arguments}, $data);
} }
sub cmd_remove { sub cmd_remove {
@ -86,17 +86,17 @@ sub cmd_remove {
$self->{pbot}->{event_queue}->dequeue_event("unmute $context->{arguments} .*"); $self->{pbot}->{event_queue}->dequeue_event("unmute $context->{arguments} .*");
# TODO: ignores, etc? # TODO: ignores, etc?
return $self->{channels}->remove($context->{arguments}); return $self->{storage}->remove($context->{arguments});
} }
sub cmd_list { sub cmd_list {
my ($self, $context) = @_; my ($self, $context) = @_;
my $result; my $result;
foreach my $channel (sort $self->{channels}->get_keys) { foreach my $channel (sort $self->{storage}->get_keys) {
$result .= $self->{channels}->get_key_name($channel) . ': {'; $result .= $self->{storage}->get_key_name($channel) . ': {';
my $comma = ' '; my $comma = ' ';
foreach my $key (sort $self->{channels}->get_keys($channel)) { foreach my $key (sort $self->{storage}->get_keys($channel)) {
$result .= "$comma$key => " . $self->{channels}->get_data($channel, $key); $result .= "$comma$key => " . $self->{storage}->get_data($channel, $key);
$comma = ', '; $comma = ', ';
} }
$result .= " }\n"; $result .= " }\n";
@ -116,7 +116,7 @@ sub join {
delete $self->{pbot}->{chanops}->{is_opped}->{$channel}; delete $self->{pbot}->{chanops}->{is_opped}->{$channel};
delete $self->{pbot}->{chanops}->{op_requested}->{$channel}; delete $self->{pbot}->{chanops}->{op_requested}->{$channel};
if ($self->{channels}->exists($channel) and $self->{channels}->get_data($channel, 'permop')) { if ($self->{storage}->exists($channel) and $self->{storage}->get_data($channel, 'permop')) {
$self->{pbot}->{chanops}->gain_ops($channel); $self->{pbot}->{chanops}->gain_ops($channel);
} }
@ -137,9 +137,9 @@ sub autojoin {
my ($self) = @_; my ($self) = @_;
return if $self->{pbot}->{joined_channels}; return if $self->{pbot}->{joined_channels};
my $channels; my $channels;
foreach my $channel ($self->{channels}->get_keys) { foreach my $channel ($self->{storage}->get_keys) {
if ($self->{channels}->get_data($channel, 'enabled')) { if ($self->{storage}->get_data($channel, 'enabled')) {
$channels .= $self->{channels}->get_key_name($channel) . ','; $channels .= $self->{storage}->get_key_name($channel) . ',';
} }
} }
$self->{pbot}->{logger}->log("Joining channels: $channels\n"); $self->{pbot}->{logger}->log("Joining channels: $channels\n");
@ -150,17 +150,17 @@ sub autojoin {
sub is_active { sub is_active {
my ($self, $channel) = @_; my ($self, $channel) = @_;
# returns undef if channel doesn't exist; otherwise, the value of 'enabled' # returns undef if channel doesn't exist; otherwise, the value of 'enabled'
return $self->{channels}->get_data($channel, 'enabled'); return $self->{storage}->get_data($channel, 'enabled');
} }
sub is_active_op { sub is_active_op {
my ($self, $channel) = @_; my ($self, $channel) = @_;
return $self->is_active($channel) && $self->{channels}->get_data($channel, 'chanop'); return $self->is_active($channel) && $self->{storage}->get_data($channel, 'chanop');
} }
sub get_meta { sub get_meta {
my ($self, $channel, $key) = @_; my ($self, $channel, $key) = @_;
return $self->{channels}->get_data($channel, $key); return $self->{storage}->get_data($channel, $key);
} }
1; 1;

View File

@ -135,8 +135,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}->{factoids}->get_key_name($channel); my $channel_name = $self->{pbot}->{factoids}->{storage}->get_key_name($channel);
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_key_name($channel, $trigger); my $trigger_name = $self->{pbot}->{factoids}->{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 '.*') {
@ -149,7 +149,7 @@ sub cmd_help {
} }
# get factoid's `help` metadata # get factoid's `help` metadata
my $help = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, 'help'); my $help = $self->{pbot}->{factoids}->{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) {
@ -305,8 +305,8 @@ sub interpreter {
$context->{arglist} = $self->{pbot}->{interpreter}->make_args($context->{arguments}); $context->{arglist} = $self->{pbot}->{interpreter}->make_args($context->{arguments});
} }
$self->{pbot}->{logger}->log("Disabling nickprefix\n"); # $self->{pbot}->{logger}->log("Disabling nickprefix\n");
$context->{nickprefix_disabled} = 1; #$context->{nickprefix_disabled} = 1;
if ($self->get_meta($keyword, 'background-process')) { if ($self->get_meta($keyword, 'background-process')) {
# execute this command as a backgrounded process # execute this command as a backgrounded process

View File

@ -149,7 +149,7 @@ sub do_events {
for (my $i = 0; $i < @{$self->{event_queue}}; $i++) { for (my $i = 0; $i < @{$self->{event_queue}}; $i++) {
# we call time for a fresh time, instead of using a stale $now that # we call time for a fresh time, instead of using a stale $now that
# could be well in the past depending on a previous event's duration # could be in the past depending on a previous event's duration
if (time >= $self->{event_queue}->[$i]->{timeout}) { if (time >= $self->{event_queue}->[$i]->{timeout}) {
my $event = $self->{event_queue}->[$i]; my $event = $self->{event_queue}->[$i];
@ -306,8 +306,11 @@ sub dequeue_event {
# nothing removed # nothing removed
return "No matching events." if not $count; return "No matching events." if not $count;
# list all removed events # list all removed events
return "Removed $count event" . ($count == 1 ? '' : 's') . ': ' . join(', ', map { $_->{id} } @removed); my $removed = "Removed $count event" . ($count == 1 ? '' : 's') . ': ' . join(', ', map { $_->{id} } @removed);
$self->{pbot}->{logger}->log("EventQueue: dequeued $removed\n");
return $removed;
}; };
if ($@) { if ($@) {

View File

@ -140,8 +140,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}->{factoids}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{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 =~ / /;
@ -153,7 +153,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}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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');
@ -184,7 +184,7 @@ sub cmd_factundo {
} }
} }
$self->{pbot}->{factoids}->{factoids}->add($channel, $trigger, $undos->{list}->[$undos->{idx}], 0, 1); $self->{pbot}->{factoids}->{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);
@ -230,8 +230,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}->{factoids}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{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 =~ / /;
@ -245,7 +245,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}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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');
@ -275,7 +275,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}->{factoids}->add($channel, $trigger, $undos->{list}->[$undos->{idx}], 0, 1); $self->{pbot}->{factoids}->{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 (redo): $changes", 1); $self->log_factoid($channel, $trigger, $context->{hostmask}, "reverted (redo): $changes", 1);
@ -291,7 +291,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}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, '_name');
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /; $trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
my $arglist = $self->{pbot}->{interpreter}->make_args($arguments); my $arglist = $self->{pbot}->{interpreter}->make_args($arguments);
@ -312,16 +312,16 @@ sub cmd_factset {
if (not $self->{pbot}->{capabilities}->userhas($userinfo, $meta_cap)) { return "Your user account must have the $meta_cap capability to set $key."; } if (not $self->{pbot}->{capabilities}->userhas($userinfo, $meta_cap)) { return "Your user account must have the $meta_cap capability to set $key."; }
} }
if (defined $value and !$self->{pbot}->{capabilities}->userhas($userinfo, 'admin') and $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, 'locked')) { if (defined $value and !$self->{pbot}->{capabilities}->userhas($userinfo, 'admin') and $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, 'locked')) {
return "/say $trigger_name is locked; unlock before setting."; return "/say $trigger_name is locked; unlock before setting.";
} }
if (lc $key eq 'cap-override' and defined $value) { if (lc $key eq 'cap-override' and defined $value) {
if (not $self->{pbot}->{capabilities}->exists($value)) { return "No such capability $value."; } if (not $self->{pbot}->{capabilities}->exists($value)) { return "No such capability $value."; }
$self->{pbot}->{factoids}->{factoids}->set($channel, $trigger, 'locked', '1'); $self->{pbot}->{factoids}->{storage}->set($channel, $trigger, 'locked', '1');
} }
if (lc $key eq 'locked' and $self->{pbot}->{factoids}->{factoids}->exists($channel, $trigger, 'cap-override')) { if (lc $key eq 'locked' and $self->{pbot}->{factoids}->{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.";
} }
@ -329,7 +329,7 @@ sub cmd_factset {
} }
if (defined $owner_channel) { if (defined $owner_channel) {
my $factoid = $self->{pbot}->{factoids}->{factoids}->get_data($owner_channel, $owner_trigger); my $factoid = $self->{pbot}->{factoids}->{storage}->get_data($owner_channel, $owner_trigger);
my $owner; my $owner;
my $mask; my $mask;
@ -348,7 +348,7 @@ sub cmd_factset {
} }
} }
my $result = $self->{pbot}->{factoids}->{factoids}->set($channel, $trigger, $key, $value); my $result = $self->{pbot}->{factoids}->{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"); }
@ -380,30 +380,30 @@ sub cmd_factunset {
if (not $self->{pbot}->{capabilities}->userhas($userinfo, $meta_cap)) { return "Your user account must have the $meta_cap capability to unset $key."; } if (not $self->{pbot}->{capabilities}->userhas($userinfo, $meta_cap)) { return "Your user account must have the $meta_cap capability to unset $key."; }
} }
if ($self->{pbot}->{factoids}->{factoids}->exists($channel, $trigger, 'cap-override')) { if ($self->{pbot}->{factoids}->{storage}->exists($channel, $trigger, 'cap-override')) {
if (lc $key eq 'locked') { if (lc $key eq 'locked') {
if ($self->{pbot}->{capabilities}->userhas($userinfo, 'botowner')) { $self->{pbot}->{factoids}->{factoids}->unset($channel, $trigger, 'cap-override', 1); } if ($self->{pbot}->{capabilities}->userhas($userinfo, 'botowner')) { $self->{pbot}->{factoids}->{storage}->unset($channel, $trigger, 'cap-override', 1); }
else { return "You cannot unlock this factoid because it has a cap-override. Remove the override first."; } else { return "You cannot unlock this factoid because it has a cap-override. Remove the override first."; }
} }
} }
my $channel_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{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 =~ / /;
my $oldvalue; my $oldvalue;
if (defined $owner_channel) { if (defined $owner_channel) {
my $factoid = $self->{pbot}->{factoids}->{factoids}->get_data($owner_channel, $owner_trigger); my $factoid = $self->{pbot}->{factoids}->{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 and not $self->{pbot}->{capabilities}->userhas($userinfo, 'admin')) { if ($key ne 'action_with_args' and lc $context->{nick} ne lc $owner and not $self->{pbot}->{capabilities}->userhas($userinfo, 'admin')) {
return "You are not the owner of $trigger_name."; return "You are not the owner of $trigger_name.";
} }
$oldvalue = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, $key); $oldvalue = $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, $key);
} }
return "[$channel_name] $trigger_name: key '$key' does not exist." if not defined $oldvalue; return "[$channel_name] $trigger_name: key '$key' does not exist." if not defined $oldvalue;
my $result = $self->{pbot}->{factoids}->{factoids}->unset($channel, $trigger, $key); my $result = $self->{pbot}->{factoids}->{storage}->unset($channel, $trigger, $key);
if ($result =~ m/unset/) { $self->log_factoid($channel, $trigger, $context->{hostmask}, "unset $key (value: $oldvalue)"); } if ($result =~ m/unset/) { $self->log_factoid($channel, $trigger, $context->{hostmask}, "unset $key (value: $oldvalue)"); }
return $result; return $result;
} }
@ -432,12 +432,12 @@ sub cmd_factmove {
if (not defined $found_src_channel) { return "Source factoid $source not found in channel $src_channel"; } if (not defined $found_src_channel) { return "Source factoid $source not found in channel $src_channel"; }
my $source_channel_name = $self->{pbot}->{factoids}->{factoids}->get_data($found_src_channel, '_name'); my $source_channel_name = $self->{pbot}->{factoids}->{storage}->get_data($found_src_channel, '_name');
my $source_trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($found_src_channel, $found_source, '_name'); my $source_trigger_name = $self->{pbot}->{factoids}->{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}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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}))) {
@ -514,16 +514,16 @@ sub cmd_factalias {
my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $alias, exact_channel => 1, exact_trigger => 1); my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $alias, exact_channel => 1, exact_trigger => 1);
if (defined $alias_trigger) { if (defined $alias_trigger) {
my $alias_channel_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, '_name'); my $alias_channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name');
my $alias_trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $alias_trigger, '_name'); my $alias_trigger_name = $self->{pbot}->{factoids}->{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}->find_factoid('.*', $alias, exact_channel => 1, exact_trigger => 1);
if (defined $overtrigger and $self->{pbot}->{factoids}->{factoids}->get_data('.*', $overtrigger, 'nooverride')) { if (defined $overtrigger and $self->{pbot}->{factoids}->{storage}->get_data('.*', $overtrigger, 'nooverride')) {
my $override_trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($overchannel, $overtrigger, '_name'); my $override_trigger_name = $self->{pbot}->{factoids}->{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) . ".";
} }
@ -546,8 +546,8 @@ sub cmd_add_regex {
if (not defined $text) { if (not defined $text) {
my @regexes; my @regexes;
my $iter = $self->{pbot}->{factoids}->{factoids}->get_each('type = regex', "index1 = $keyword", 'index2', '_sort = index2'); my $iter = $self->{pbot}->{factoids}->{storage}->get_each('type = regex', "index1 = $keyword", 'index2', '_sort = index2');
while (defined (my $factoid = $self->{pbot}->{factoids}->{factoids}->get_next($iter))) { while (defined (my $factoid = $self->{pbot}->{factoids}->{storage}->get_next($iter))) {
push @regexes, $factoid->{index2}; push @regexes, $factoid->{index2};
} }
$text = join '; ', @regexes; $text = join '; ', @regexes;
@ -639,22 +639,22 @@ sub cmd_factadd {
my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $keyword, exact_channel => 1, exact_trigger => 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $keyword, exact_channel => 1, exact_trigger => 1);
if (defined $trigger) { if (defined $trigger) {
my $channel_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{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}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{storage};
if ($factoids->get_data($channel, $trigger, 'locked')) { return "/say $trigger_name is locked; unlock before overwriting."; } if ($factoids->get_data($channel, $trigger, 'locked')) { 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}->find_factoid('.*', $keyword, exact_channel => 1, exact_trigger => 1);
if (defined $trigger and $self->{pbot}->{factoids}->{factoids}->get_data('.*', $trigger, 'nooverride')) { if (defined $trigger and $self->{pbot}->{factoids}->{storage}->get_data('.*', $trigger, 'nooverride')) {
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{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) . ".";
} }
@ -669,7 +669,7 @@ sub cmd_factadd {
sub cmd_factrem { sub cmd_factrem {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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);
@ -710,7 +710,7 @@ sub cmd_factrem {
sub cmd_factshow { sub cmd_factshow {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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};
@ -834,7 +834,7 @@ sub cmd_factlog {
sub cmd_factinfo { sub cmd_factinfo {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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) {
@ -931,7 +931,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}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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;
@ -1036,7 +1036,7 @@ sub cmd_factfind {
sub cmd_factchange { sub cmd_factchange {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids_data = $self->{pbot}->{factoids}->{factoids}; my $factoids_data = $self->{pbot}->{factoids}->{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;
@ -1120,8 +1120,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}->{factoids}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{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 =~ / /;
@ -1222,7 +1222,7 @@ sub cmd_factchange {
sub cmd_top20 { sub cmd_top20 {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{storage};
my %hash = (); my %hash = ();
my $text = ""; my $text = "";
my $i = 0; my $i = 0;
@ -1282,7 +1282,7 @@ sub cmd_top20 {
sub cmd_histogram { sub cmd_histogram {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{storage};
my %owners; my %owners;
my $factoid_count = 0; my $factoid_count = 0;
@ -1307,7 +1307,7 @@ sub cmd_histogram {
sub cmd_count { sub cmd_count {
my ($self, $context) = @_; my ($self, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{storage};
my $i = 0; my $i = 0;
my $total = 0; my $total = 0;
@ -1381,7 +1381,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}->{factoids}->get_data($channel, $trigger); push @{$undos->{list}}, $self->{pbot}->{factoids}->{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"; };
@ -1478,8 +1478,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}->{factoids}->get_data($channel, '_name'); my $channel_name = $self->{pbot}->{factoids}->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, '_name'); my $trigger_name = $self->{pbot}->{factoids}->{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

@ -69,7 +69,8 @@ sub initialize {
$self->{pbot} = $self->{pbot}; $self->{pbot} = $self->{pbot};
$self->{pbot}->{atexit}->register(sub { $self->save_factoids; return; }); $self->{pbot}->{atexit}->register(sub { $self->save_factoids; return; });
$self->{factoids} = PBot::DualIndexSQLiteObject->new(name => 'Factoids', filename => $filename, pbot => $self->{pbot}); $self->{storage} = PBot::DualIndexSQLiteObject->new(name => 'Factoids', filename => $filename, pbot => $self->{pbot});
$self->{commands} = PBot::FactoidCommands->new(pbot => $self->{pbot}); $self->{commands} = PBot::FactoidCommands->new(pbot => $self->{pbot});
$self->{pbot}->{registry}->add_default('text', 'factoids', 'default_rate_limit', 15); $self->{pbot}->{registry}->add_default('text', 'factoids', 'default_rate_limit', 15);
@ -82,13 +83,13 @@ sub initialize {
sub load_factoids { sub load_factoids {
my $self = shift; my $self = shift;
$self->{factoids}->load; $self->{storage}->load;
$self->{factoids}->create_metadata(\%factoid_metadata); $self->{storage}->create_metadata(\%factoid_metadata);
} }
sub save_factoids { sub save_factoids {
my $self = shift; my $self = shift;
$self->{factoids}->save; $self->{storage}->save;
$self->export_factoids; $self->export_factoids;
} }
@ -98,7 +99,7 @@ sub get_meta {
$trigger = lc $trigger; $trigger = lc $trigger;
my ($chan, $trig) = $self->find_factoid($channel, $trigger, exact_channel => 1, exact_trigger => 1); my ($chan, $trig) = $self->find_factoid($channel, $trigger, exact_channel => 1, exact_trigger => 1);
return undef if not defined $chan; return undef if not defined $chan;
return $self->{factoids}->get_data($chan, $trig, $key); return $self->{storage}->get_data($chan, $trig, $key);
} }
sub add_factoid { sub add_factoid {
@ -107,9 +108,10 @@ sub add_factoid {
$channel = '.*' if $channel !~ /^#/; $channel = '.*' if $channel !~ /^#/;
my $data; my $data;
if ($self->{factoids}->exists($channel, $trigger)) { if ($self->{storage}->exists($channel, $trigger)) {
# only update action field if force-adding it through factadd -f # only update action field if force-adding it through factadd -f
$data = $self->{factoids}->get_data($channel, $trigger); $data = $self->{storage}->get_data($channel, $trigger);
$data->{action} = $action; $data->{action} = $action;
$data->{type} = $type; $data->{type} = $type;
} else { } else {
@ -125,7 +127,7 @@ sub add_factoid {
}; };
} }
$self->{factoids}->add($channel, $trigger, $data, $dont_save); $self->{storage}->add($channel, $trigger, $data, $dont_save);
$self->{commands}->log_factoid($channel, $trigger, $owner, "created: $action") unless $dont_save; $self->{commands}->log_factoid($channel, $trigger, $owner, "created: $action") unless $dont_save;
} }
@ -133,7 +135,7 @@ sub remove_factoid {
my $self = shift; my $self = shift;
my ($channel, $trigger) = @_; my ($channel, $trigger) = @_;
$channel = '.*' if $channel !~ /^#/; $channel = '.*' if $channel !~ /^#/;
return $self->{factoids}->remove($channel, $trigger); return $self->{storage}->remove($channel, $trigger);
} }
sub export_factoids { sub export_factoids {
@ -144,7 +146,7 @@ sub export_factoids {
else { $filename = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/factoids.html'; } else { $filename = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/factoids.html'; }
return if not defined $filename; return if not defined $filename;
return if not defined $self->{factoids}->{dbh}; return if not defined $self->{storage}->{dbh};
$self->{pbot}->{logger}->log("Exporting factoids to $filename\n"); $self->{pbot}->{logger}->log("Exporting factoids to $filename\n");
@ -162,17 +164,17 @@ sub export_factoids {
my $i = 0; my $i = 0;
my $table_id = 1; my $table_id = 1;
foreach my $channel (sort $self->{factoids}->get_keys) { foreach my $channel (sort $self->{storage}->get_keys) {
next if not $self->{factoids}->get_keys($channel); next if not $self->{storage}->get_keys($channel);
my $chan = $self->{factoids}->get_data($channel, '_name'); my $chan = $self->{storage}->get_data($channel, '_name');
$chan = 'global' if $chan eq '.*'; $chan = 'global' if $chan eq '.*';
print FILE "<a href='#" . encode_entities($chan) . "'>" . encode_entities($chan) . "</a><br>\n"; print FILE "<a href='#" . encode_entities($chan) . "'>" . encode_entities($chan) . "</a><br>\n";
} }
foreach my $channel (sort $self->{factoids}->get_keys) { foreach my $channel (sort $self->{storage}->get_keys) {
next if not $self->{factoids}->get_keys($channel); next if not $self->{storage}->get_keys($channel);
my $chan = $self->{factoids}->get_data($channel, '_name'); my $chan = $self->{storage}->get_data($channel, '_name');
$chan = 'global' if $chan eq '.*'; $chan = 'global' if $chan eq '.*';
print FILE "<a name='" . encode_entities($chan) . "'></a>\n"; print FILE "<a name='" . encode_entities($chan) . "'></a>\n";
print FILE "<hr>\n<h3>" . encode_entities($chan) . "</h3>\n<hr>\n"; print FILE "<hr>\n<h3>" . encode_entities($chan) . "</h3>\n<hr>\n";
@ -189,9 +191,9 @@ sub export_factoids {
print FILE "</tr>\n</thead>\n<tbody>\n"; print FILE "</tr>\n</thead>\n<tbody>\n";
$table_id++; $table_id++;
my $iter = $self->{factoids}->get_each("index1 = $channel", '_everything', '_sort = index1'); my $iter = $self->{storage}->get_each("index1 = $channel", '_everything', '_sort = index1');
while (defined (my $factoid = $self->{factoids}->get_next($iter))) { while (defined (my $factoid = $self->{storage}->get_next($iter))) {
my $trigger_name = $self->{factoids}->get_data($factoid->{index1}, $factoid->{index2}, '_name'); my $trigger_name = $self->{storage}->get_data($factoid->{index1}, $factoid->{index2}, '_name');
if ($factoid->{type} eq 'text') { if ($factoid->{type} eq 'text') {
$i++; $i++;
if ($i % 2) { print FILE "<tr bgcolor=\"#dddddd\">\n"; } if ($i % 2) { print FILE "<tr bgcolor=\"#dddddd\">\n"; }
@ -302,12 +304,12 @@ sub find_factoid {
$self->{pbot}->{logger}->log("string: $string\n") if $debug; $self->{pbot}->{logger}->log("string: $string\n") if $debug;
if ($opts{exact_channel} and $opts{exact_trigger}) { if ($opts{exact_channel} and $opts{exact_trigger}) {
if ($self->{factoids}->exists($from, $keyword)) { if ($self->{storage}->exists($from, $keyword)) {
($channel, $trigger) = ($from, $keyword); ($channel, $trigger) = ($from, $keyword);
goto CHECK_ALIAS; goto CHECK_ALIAS;
} }
if ($opts{exact_trigger} > 1 and $self->{factoids}->exists('.*', $keyword)) { if ($opts{exact_trigger} > 1 and $self->{storage}->exists('.*', $keyword)) {
($channel, $trigger) = ('.*', $keyword); ($channel, $trigger) = ('.*', $keyword);
goto CHECK_ALIAS; goto CHECK_ALIAS;
} }
@ -316,10 +318,10 @@ sub find_factoid {
} }
if ($opts{exact_channel} and not $opts{exact_trigger}) { if ($opts{exact_channel} and not $opts{exact_trigger}) {
if (not $self->{factoids}->exists($from, $keyword)) { if (not $self->{storage}->exists($from, $keyword)) {
($channel, $trigger) = ($from, $keyword); ($channel, $trigger) = ($from, $keyword);
goto CHECK_REGEX if $from eq '.*'; goto CHECK_REGEX if $from eq '.*';
goto CHECK_REGEX if not $self->{factoids}->exists('.*', $keyword); goto CHECK_REGEX if not $self->{storage}->exists('.*', $keyword);
($channel, $trigger) = ('.*', $keyword); ($channel, $trigger) = ('.*', $keyword);
goto CHECK_ALIAS; goto CHECK_ALIAS;
} }
@ -328,7 +330,7 @@ sub find_factoid {
} }
if (not $opts{exact_channel}) { if (not $opts{exact_channel}) {
foreach my $factoid ($self->{factoids}->get_all("index2 = $keyword", 'index1', 'action')) { foreach my $factoid ($self->{storage}->get_all("index2 = $keyword", 'index1', 'action')) {
$channel = $factoid->{index1}; $channel = $factoid->{index1};
$trigger = $keyword; $trigger = $keyword;
@ -344,7 +346,7 @@ sub find_factoid {
CHECK_ALIAS: CHECK_ALIAS:
if ($opts{find_alias}) { if ($opts{find_alias}) {
$action = $self->{factoids}->get_data($channel, $trigger, 'action') if not defined $action; $action = $self->{storage}->get_data($channel, $trigger, 'action') if not defined $action;
if ($action =~ m{^/call\s+(.*)$}ms) { if ($action =~ m{^/call\s+(.*)$}ms) {
my $command; my $command;
if (length $arguments) { if (length $arguments) {
@ -370,12 +372,12 @@ sub find_factoid {
if ($opts{exact_channel}) { if ($opts{exact_channel}) {
if ($channel ne '.*') { if ($channel ne '.*') {
@factoids = $self->{factoids}->get_all('type = regex', "index1 = $channel", 'OR index1 = .*', 'index2', 'action'); @factoids = $self->{storage}->get_all('type = regex', "index1 = $channel", 'OR index1 = .*', 'index2', 'action');
} else { } else {
@factoids = $self->{factoids}->get_all('type = regex', "index1 = $channel", 'index2', 'action'); @factoids = $self->{storage}->get_all('type = regex', "index1 = $channel", 'index2', 'action');
} }
} else { } else {
@factoids = $self->{factoids}->get_all('type = regex', 'index1', 'index2', 'action'); @factoids = $self->{storage}->get_all('type = regex', 'index1', 'index2', 'action');
} }
foreach my $factoid (@factoids) { foreach my $factoid (@factoids) {
@ -742,7 +744,7 @@ sub expand_factoid_vars {
$action = defined $action ? $action : $context->{action}; $action = defined $action ? $action : $context->{action};
my $interpolate = $self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'interpolate'); my $interpolate = $self->{storage}->get_data($context->{channel}, $context->{keyword}, 'interpolate');
return $action if defined $interpolate and $interpolate == 0; return $action if defined $interpolate and $interpolate == 0;
$interpolate = $self->{pbot}->{registry}->get_value($context->{channel}, 'interpolate_factoids'); $interpolate = $self->{pbot}->{registry}->get_value($context->{channel}, 'interpolate_factoids');
@ -813,7 +815,7 @@ sub expand_factoid_vars {
my $var_chan; my $var_chan;
($var_chan, $var) = ($factoids[0]->[0], $factoids[0]->[1]); ($var_chan, $var) = ($factoids[0]->[0], $factoids[0]->[1]);
if ($self->{factoids}->get_data($var_chan, $var, 'action') =~ m{^/call (.*)}ms) { if ($self->{storage}->get_data($var_chan, $var, 'action') =~ m{^/call (.*)}ms) {
$var = $1; $var = $1;
if (++$recurse > 100) { if (++$recurse > 100) {
@ -828,8 +830,8 @@ sub expand_factoid_vars {
my $copy = $rest; my $copy = $rest;
my %settings = $self->parse_expansion_modifiers(\$copy); my %settings = $self->parse_expansion_modifiers(\$copy);
if ($self->{factoids}->get_data($var_chan, $var, 'type') eq 'text') { if ($self->{storage}->get_data($var_chan, $var, 'type') eq 'text') {
my $change = $self->{factoids}->get_data($var_chan, $var, 'action'); my $change = $self->{storage}->get_data($var_chan, $var, 'action');
my @list = $self->{pbot}->{interpreter}->split_line($change); my @list = $self->{pbot}->{interpreter}->split_line($change);
my @replacements; my @replacements;
@ -1015,8 +1017,8 @@ sub expand_special_vars {
sub execute_code_factoid_using_vm { sub execute_code_factoid_using_vm {
my ($self, $context) = @_; my ($self, $context) = @_;
unless ($self->{factoids}->exists($context->{channel}, $context->{keyword}, 'interpolate') unless ($self->{storage}->exists($context->{channel}, $context->{keyword}, 'interpolate')
and $self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'interpolate') eq '0') and $self->{storage}->get_data($context->{channel}, $context->{keyword}, 'interpolate') eq '0')
{ {
if ($context->{code} =~ m/(?:\$\{?nick\b|\$\{?args\b|\$\{?arg\[)/ and length $context->{arguments}) { if ($context->{code} =~ m/(?:\$\{?nick\b|\$\{?args\b|\$\{?arg\[)/ and length $context->{arguments}) {
$context->{nickprefix_disabled} = 1; $context->{nickprefix_disabled} = 1;
@ -1026,7 +1028,7 @@ sub execute_code_factoid_using_vm {
$context->{code} = $self->expand_factoid_vars($context, $context->{code}); $context->{code} = $self->expand_factoid_vars($context, $context->{code});
if ($self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'allow_empty_args')) { if ($self->{storage}->get_data($context->{channel}, $context->{keyword}, 'allow_empty_args')) {
$context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, ''); $context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, '');
} else { } else {
$context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, $context->{nick}); $context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, $context->{nick});
@ -1048,7 +1050,7 @@ sub execute_code_factoid_using_vm {
# the vm can persist filesystem data to external storage identified by a key. # the vm can persist filesystem data to external storage identified by a key.
# if the `persist-key` factoid metadata is set, then use this key. # if the `persist-key` factoid metadata is set, then use this key.
my $persist_key = $self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'persist-key'); my $persist_key = $self->{storage}->get_data($context->{channel}, $context->{keyword}, 'persist-key');
if (defined $persist_key) { if (defined $persist_key) {
$args{'persist-key'} = $persist_key; $args{'persist-key'} = $persist_key;
@ -1133,9 +1135,9 @@ sub interpreter {
unless ($strictnamespace) { unless ($strictnamespace) {
# build list of which channels contain the keyword, keeping track of the last one and count # build list of which channels contain the keyword, keeping track of the last one and count
foreach my $factoid ($self->{factoids}->get_all("index2 = $original_keyword", 'index1', 'type')) { foreach my $factoid ($self->{storage}->get_all("index2 = $original_keyword", 'index1', 'type')) {
next if $factoid->{type} ne 'text' and $factoid->{type} ne 'module'; next if $factoid->{type} ne 'text' and $factoid->{type} ne 'module';
push @chanlist, $self->{factoids}->get_data($factoid->{index1}, '_name'); push @chanlist, $self->{storage}->get_data($factoid->{index1}, '_name');
$fwd_chan = $factoid->{index1}; $fwd_chan = $factoid->{index1};
$fwd_trig = $original_keyword; $fwd_trig = $original_keyword;
} }
@ -1155,7 +1157,7 @@ sub interpreter {
$context->{keyword} = $fwd_trig; $context->{keyword} = $fwd_trig;
$context->{interpret_depth}++; $context->{interpret_depth}++;
$context->{ref_from} = $fwd_chan; $context->{ref_from} = $fwd_chan;
return $pbot->{factoids}->interpreter($context); return $self->interpreter($context);
} }
# otherwise keyword hasn't been found, display similiar matches for all channels # otherwise keyword hasn't been found, display similiar matches for all channels
@ -1176,7 +1178,7 @@ sub interpreter {
} }
# otherwise find levenshtein closest matches # otherwise find levenshtein closest matches
$matches = $self->{factoids}->levenshtein_matches($namespace, lc $original_keyword, 0.50, $strictnamespace); $matches = $self->{storage}->levenshtein_matches($namespace, lc $original_keyword, 0.50, $strictnamespace);
# if a non-nick argument was supplied, e.g., a sentence using the bot's nick, /msg the error to the caller # if a non-nick argument was supplied, e.g., a sentence using the bot's nick, /msg the error to the caller
if (length $context->{arguments} and not $self->{pbot}->{nicklist}->is_present($context->{from}, $context->{arguments})) { if (length $context->{arguments} and not $self->{pbot}->{nicklist}->is_present($context->{from}, $context->{arguments})) {
@ -1199,8 +1201,8 @@ sub interpreter {
} }
} }
my $channel_name = $self->{factoids}->get_data($channel, '_name'); my $channel_name = $self->{storage}->get_data($channel, '_name');
my $trigger_name = $self->{factoids}->get_data($channel, $keyword, '_name'); my $trigger_name = $self->{storage}->get_data($channel, $keyword, '_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 =~ / /;
@ -1211,56 +1213,56 @@ sub interpreter {
$context->{channel_name} = $channel_name; $context->{channel_name} = $channel_name;
$context->{trigger_name} = $trigger_name; $context->{trigger_name} = $trigger_name;
return undef if $context->{referenced} and $self->{factoids}->get_data($channel, $keyword, 'noembed'); return undef if $context->{referenced} and $self->{storage}->get_data($channel, $keyword, 'noembed');
if ($self->{factoids}->get_data($channel, $keyword, 'locked_to_channel')) { if ($self->{storage}->get_data($channel, $keyword, 'locked_to_channel')) {
if ($context->{ref_from} ne "") { # called from another channel if ($context->{ref_from} ne "") { # called from another channel
return "$trigger_name may be invoked only in $context->{ref_from}."; return "$trigger_name may be invoked only in $context->{ref_from}.";
} }
} }
if ($context->{interpret_depth} <= 1 and $self->{factoids}->get_data($channel, $keyword, 'last_referenced_in') eq $context->{from}) { if ($context->{interpret_depth} <= 1 and $self->{storage}->get_data($channel, $keyword, 'last_referenced_in') eq $context->{from}) {
my $ratelimit = $self->{pbot}->{registry}->get_value($context->{from}, 'ratelimit_override'); my $ratelimit = $self->{pbot}->{registry}->get_value($context->{from}, 'ratelimit_override');
$ratelimit = $self->{factoids}->get_data($channel, $keyword, 'rate_limit') if not defined $ratelimit; $ratelimit = $self->{storage}->get_data($channel, $keyword, 'rate_limit') if not defined $ratelimit;
if (gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) { if (gettimeofday - $self->{storage}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) {
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : ""; my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
return return
"/msg $context->{nick} $ref_from'$trigger_name' is rate-limited; try again in " "/msg $context->{nick} $ref_from'$trigger_name' is rate-limited; try again in "
. duration($ratelimit - int(gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on'))) . "." . duration($ratelimit - int(gettimeofday - $self->{storage}->get_data($channel, $keyword, 'last_referenced_on'))) . "."
unless $self->{pbot}->{users}->loggedin_admin($channel, "$context->{nick}!$context->{user}\@$context->{host}"); unless $self->{pbot}->{users}->loggedin_admin($channel, "$context->{nick}!$context->{user}\@$context->{host}");
} }
} }
my $ref_count = $self->{factoids}->get_data($channel, $keyword, 'ref_count'); my $ref_count = $self->{storage}->get_data($channel, $keyword, 'ref_count');
my $update_data = { my $update_data = {
ref_count => ++$ref_count, ref_count => ++$ref_count,
ref_user => "$context->{nick}!$context->{user}\@$context->{host}", ref_user => "$context->{nick}!$context->{user}\@$context->{host}",
last_referenced_on => scalar gettimeofday, last_referenced_on => scalar gettimeofday,
last_referenced_in => $context->{from} || 'stdin', last_referenced_in => $context->{from} || 'stdin',
}; };
$self->{factoids}->add($channel, $keyword, $update_data, 1, 1); $self->{storage}->add($channel, $keyword, $update_data, 1, 1);
my $action; my $action;
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $context->{arguments} and $self->{factoids}->get_data($channel, $keyword, 'requires_arguments')) { if ($self->{storage}->exists($channel, $keyword, 'usage') and not length $context->{arguments} and $self->{storage}->get_data($channel, $keyword, 'requires_arguments')) {
$context->{alldone} = 1; $context->{alldone} = 1;
my $usage = $self->{factoids}->get_data($channel, $keyword, 'usage'); my $usage = $self->{storage}->get_data($channel, $keyword, 'usage');
$usage =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g; $usage =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g;
return $usage; return $usage;
} }
if (length $context->{arguments} and $self->{factoids}->exists($channel, $keyword, 'action_with_args')) { if (length $context->{arguments} and $self->{storage}->exists($channel, $keyword, 'action_with_args')) {
$action = $self->{factoids}->get_data($channel, $keyword, 'action_with_args'); $action = $self->{storage}->get_data($channel, $keyword, 'action_with_args');
} else { } else {
$action = $self->{factoids}->get_data($channel, $keyword, 'action'); $action = $self->{storage}->get_data($channel, $keyword, 'action');
} }
if ($action =~ m{^/code\s+([^\s]+)\s+(.+)$}msi) { if ($action =~ m{^/code\s+([^\s]+)\s+(.+)$}msi) {
my ($lang, $code) = ($1, $2); my ($lang, $code) = ($1, $2);
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $context->{arguments}) { if ($self->{storage}->exists($channel, $keyword, 'usage') and not length $context->{arguments}) {
$context->{alldone} = 1; $context->{alldone} = 1;
my $usage = $self->{factoids}->get_data($channel, $keyword, 'usage'); my $usage = $self->{storage}->get_data($channel, $keyword, 'usage');
$usage =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g; $usage =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g;
return $usage; return $usage;
} }
@ -1271,8 +1273,8 @@ sub interpreter {
return ""; return "";
} }
if ($self->{factoids}->get_data($channel, $keyword, 'background-process')) { if ($self->{storage}->get_data($channel, $keyword, 'background-process')) {
my $timeout = $self->{factoids}->get_data($channel, $keyword, 'process-timeout') // $self->{pbot}->{registry}->get_value('processmanager', 'default_timeout'); my $timeout = $self->{storage}->get_data($channel, $keyword, 'process-timeout') // $self->{pbot}->{registry}->get_value('processmanager', 'default_timeout');
$self->{pbot}->{process_manager}->execute_process( $self->{pbot}->{process_manager}->execute_process(
$context, $context,
sub { $context->{result} = $self->handle_action($context, $action); }, sub { $context->{result} = $self->handle_action($context, $action); },
@ -1305,15 +1307,15 @@ sub handle_action {
$ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : ''; $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : '';
} }
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') { unless ($self->{storage}->exists($channel, $keyword, 'interpolate') and $self->{storage}->get_data($channel, $keyword, 'interpolate') eq '0') {
my ($root_channel, $root_keyword) = my ($root_channel, $root_keyword) =
$self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1); $self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1);
if (not defined $root_channel or not defined $root_keyword) { if (not defined $root_channel or not defined $root_keyword) {
$root_channel = $channel; $root_channel = $channel;
$root_keyword = $keyword; $root_keyword = $keyword;
} }
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) { if (not length $context->{keyword_override} and length $self->{storage}->get_data($root_channel, $root_keyword, 'keyword_override')) {
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override'); $context->{keyword_override} = $self->{storage}->get_data($root_channel, $root_keyword, 'keyword_override');
} }
$action = $self->expand_factoid_vars($context, $action); $action = $self->expand_factoid_vars($context, $action);
@ -1321,14 +1323,14 @@ sub handle_action {
if (length $context->{arguments}) { if (length $context->{arguments}) {
if ($action =~ m/\$\{?args/ or $action =~ m/\$\{?arg\[/) { if ($action =~ m/\$\{?args/ or $action =~ m/\$\{?arg\[/) {
unless (defined $self->{factoids}->get_data($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') { unless (defined $self->{storage}->get_data($channel, $keyword, 'interpolate') and $self->{storage}->get_data($channel, $keyword, 'interpolate') eq '0') {
$action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick}); $action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick});
} }
$context->{arguments} = ""; $context->{arguments} = "";
$context->{original_arguments} = ""; $context->{original_arguments} = "";
} else { } else {
if ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'text') { if ($self->{storage}->get_data($channel, $keyword, 'type') eq 'text') {
my $target = $self->{pbot}->{nicklist}->is_present_similar($context->{from}, $context->{arguments}); my $target = $self->{pbot}->{nicklist}->is_present_similar($context->{from}, $context->{arguments});
if ($target and $action !~ /\$\{?(?:nick|args)\b/) { if ($target and $action !~ /\$\{?(?:nick|args)\b/) {
@ -1339,12 +1341,12 @@ sub handle_action {
} }
} else { } else {
# no arguments supplied, replace $args with $nick/$tonick, etc # no arguments supplied, replace $args with $nick/$tonick, etc
if ($self->{factoids}->exists($channel, $keyword, 'usage')) { if ($self->{storage}->exists($channel, $keyword, 'usage')) {
$action = "/say " . $self->{factoids}->get_data($channel, $keyword, 'usage'); $action = "/say " . $self->{storage}->get_data($channel, $keyword, 'usage');
$action =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g; $action =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g;
$context->{alldone} = 1; $context->{alldone} = 1;
} else { } else {
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) { if ($self->{storage}->get_data($channel, $keyword, 'allow_empty_args')) {
$action = $self->expand_action_arguments($action, undef, ''); $action = $self->expand_action_arguments($action, undef, '');
} else { } else {
$action = $self->expand_action_arguments($action, undef, $context->{nick}); $action = $self->expand_action_arguments($action, undef, $context->{nick});
@ -1357,13 +1359,13 @@ sub handle_action {
if ($action =~ /^\/call\s+(.*)$/msi) { if ($action =~ /^\/call\s+(.*)$/msi) {
my $command = $1; my $command = $1;
$command =~ s/\n$//; $command =~ s/\n$//;
unless ($self->{factoids}->get_data($channel, $keyword, 'require_explicit_args')) { unless ($self->{storage}->get_data($channel, $keyword, 'require_explicit_args')) {
my $args = $context->{arguments}; my $args = $context->{arguments};
$command .= " $args" if length $args and not $context->{special} eq 'code-factoid'; $command .= " $args" if length $args and not $context->{special} eq 'code-factoid';
$context->{arguments} = ''; $context->{arguments} = '';
} }
unless ($self->{factoids}->get_data($channel, $keyword, 'no_keyword_override')) { unless ($self->{storage}->get_data($channel, $keyword, 'no_keyword_override')) {
if ($command =~ s/\s*--keyword-override=([^ ]+)\s*//) { $context->{keyword_override} = $1; } if ($command =~ s/\s*--keyword-override=([^ ]+)\s*//) { $context->{keyword_override} = $1; }
} }
@ -1373,12 +1375,12 @@ sub handle_action {
$self->{pbot}->{logger} $self->{pbot}->{logger}
->log("[" . (defined $context->{from} ? $context->{from} : "stdin") . "] ($context->{nick}!$context->{user}\@$context->{host}) $trigger_name aliased to: $command\n"); ->log("[" . (defined $context->{from} ? $context->{from} : "stdin") . "] ($context->{nick}!$context->{user}\@$context->{host}) $trigger_name aliased to: $command\n");
if (defined $self->{factoids}->get_data($channel, $keyword, 'cap-override')) { if (defined $self->{storage}->get_data($channel, $keyword, 'cap-override')) {
if ($self->{factoids}->get_data($channel, $keyword, 'locked')) { if ($self->{storage}->get_data($channel, $keyword, 'locked')) {
$self->{pbot}->{logger}->log("Capability override set to " . $self->{factoids}->get_data($channel, $keyword, 'cap-override') . "\n"); $self->{pbot}->{logger}->log("Capability override set to " . $self->{storage}->get_data($channel, $keyword, 'cap-override') . "\n");
$context->{'cap-override'} = $self->{factoids}->get_data($channel, $keyword, 'cap-override'); $context->{'cap-override'} = $self->{storage}->get_data($channel, $keyword, 'cap-override');
} else { } else {
$self->{pbot}->{logger}->log("Ignoring cap-override of " . $self->{factoids}->get_data($channel, $keyword, 'cap-override') . " on unlocked factoid\n"); $self->{pbot}->{logger}->log("Ignoring cap-override of " . $self->{storage}->get_data($channel, $keyword, 'cap-override') . " on unlocked factoid\n");
} }
} }
@ -1388,14 +1390,14 @@ sub handle_action {
$self->{pbot}->{logger} $self->{pbot}->{logger}
->log("(" . (defined $context->{from} ? $context->{from} : "(undef)") . "): $context->{nick}!$context->{user}\@$context->{host}: $trigger_name: action: \"$action\"\n"); ->log("(" . (defined $context->{from} ? $context->{from} : "(undef)") . "): $context->{nick}!$context->{user}\@$context->{host}: $trigger_name: action: \"$action\"\n");
my $enabled = $self->{factoids}->get_data($channel, $keyword, 'enabled'); my $enabled = $self->{storage}->get_data($channel, $keyword, 'enabled');
if (defined $enabled and $enabled == 0) { if (defined $enabled and $enabled == 0) {
$self->{pbot}->{logger}->log("$trigger_name disabled.\n"); $self->{pbot}->{logger}->log("$trigger_name disabled.\n");
return "/msg $context->{nick} ${ref_from}$trigger_name is currently disabled."; return "/msg $context->{nick} ${ref_from}$trigger_name is currently disabled.";
} }
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') { unless ($self->{storage}->exists($channel, $keyword, 'interpolate') and $self->{storage}->get_data($channel, $keyword, 'interpolate') eq '0') {
my ($root_channel, $root_keyword) = my ($root_channel, $root_keyword) =
$self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1); $self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1);
@ -1404,13 +1406,13 @@ sub handle_action {
$root_keyword = $keyword; $root_keyword = $keyword;
} }
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) { if (not length $context->{keyword_override} and length $self->{storage}->get_data($root_channel, $root_keyword, 'keyword_override')) {
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override'); $context->{keyword_override} = $self->{storage}->get_data($root_channel, $root_keyword, 'keyword_override');
} }
$action = $self->expand_factoid_vars($context, $action); $action = $self->expand_factoid_vars($context, $action);
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) { if ($self->{storage}->get_data($channel, $keyword, 'allow_empty_args')) {
$action = $self->expand_action_arguments($action, $context->{arguments}, ''); $action = $self->expand_action_arguments($action, $context->{arguments}, '');
} else { } else {
$action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick}); $action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick});
@ -1419,8 +1421,8 @@ sub handle_action {
return $action if $context->{special} eq 'code-factoid'; return $action if $context->{special} eq 'code-factoid';
if ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'module') { if ($self->{storage}->get_data($channel, $keyword, 'type') eq 'module') {
my $preserve_whitespace = $self->{factoids}->get_data($channel, $keyword, 'preserve_whitespace'); my $preserve_whitespace = $self->{storage}->get_data($channel, $keyword, 'preserve_whitespace');
$preserve_whitespace = 0 if not defined $preserve_whitespace; $preserve_whitespace = 0 if not defined $preserve_whitespace;
$context->{preserve_whitespace} = $preserve_whitespace; $context->{preserve_whitespace} = $preserve_whitespace;
@ -1434,7 +1436,7 @@ sub handle_action {
} else { } else {
return ""; return "";
} }
} elsif ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'text') { } elsif ($self->{storage}->get_data($channel, $keyword, 'type') eq 'text') {
# Don't allow user-custom /msg factoids, unless factoid triggered by admin # Don't allow user-custom /msg factoids, unless factoid triggered by admin
if ($action =~ m/^\/msg/i) { if ($action =~ m/^\/msg/i) {
if (not $self->{pbot}->{users}->loggedin_admin($context->{from}, $context->{hostmask})) { if (not $self->{pbot}->{users}->loggedin_admin($context->{from}, $context->{hostmask})) {
@ -1456,7 +1458,7 @@ sub handle_action {
if ($action =~ m/^\/(?:say|me|msg)/i) { return $action; } if ($action =~ m/^\/(?:say|me|msg)/i) { return $action; }
else { return "/say $trigger_name is $action"; } else { return "/say $trigger_name is $action"; }
} }
} elsif ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'regex') { } elsif ($self->{storage}->get_data($channel, $keyword, 'type') eq 'regex') {
my $result = eval { my $result = eval {
my $string = "$context->{original_keyword}" . (defined $context->{arguments} ? " $context->{arguments}" : ""); my $string = "$context->{original_keyword}" . (defined $context->{arguments} ? " $context->{arguments}" : "");
my $cmd; my $cmd;

View File

@ -375,7 +375,7 @@ sub on_mode {
} }
# TODO: here as well # TODO: here as well
$self->{pbot}->{channels}->{channels}->set($channel, 'MODE', $modes, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'MODE', $modes, 1);
} }
} }
} }
@ -839,7 +839,7 @@ sub on_channelmodeis {
$self->{pbot}->{logger}->log("Channel $channel modes: $modes\n"); $self->{pbot}->{logger}->log("Channel $channel modes: $modes\n");
$self->{pbot}->{channels}->{channels}->set($channel, 'MODE', $modes, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'MODE', $modes, 1);
} }
sub on_channelcreate { sub on_channelcreate {
@ -849,8 +849,8 @@ sub on_channelcreate {
$self->{pbot}->{logger}->log("Channel $channel created by $owner on " . localtime($timestamp) . "\n"); $self->{pbot}->{logger}->log("Channel $channel created by $owner on " . localtime($timestamp) . "\n");
$self->{pbot}->{channels}->{channels}->set($channel, 'CREATED_BY', $owner, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'CREATED_BY', $owner, 1);
$self->{pbot}->{channels}->{channels}->set($channel, 'CREATED_ON', $timestamp, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'CREATED_ON', $timestamp, 1);
} }
sub on_topic { sub on_topic {
@ -860,7 +860,7 @@ sub on_topic {
# on join # on join
my (undef, $channel, $topic) = $event->{event}->args; my (undef, $channel, $topic) = $event->{event}->args;
$self->{pbot}->{logger}->log("Topic for $channel: $topic\n"); $self->{pbot}->{logger}->log("Topic for $channel: $topic\n");
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC', $topic, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC', $topic, 1);
} else { } else {
# user changing topic # user changing topic
my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host); my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host);
@ -868,9 +868,9 @@ sub on_topic {
my $topic = $event->{event}->{args}->[0]; my $topic = $event->{event}->{args}->[0];
$self->{pbot}->{logger}->log("$nick!$user\@$host changed topic for $channel to: $topic\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host changed topic for $channel to: $topic\n");
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC', $topic, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC', $topic, 1);
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_BY', "$nick!$user\@$host", 1); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC_SET_BY', "$nick!$user\@$host", 1);
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_ON', time); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC_SET_ON', time);
} }
return 0; return 0;
@ -880,8 +880,8 @@ sub on_topicinfo {
my ($self, $event_type, $event) = @_; my ($self, $event_type, $event) = @_;
my (undef, $channel, $by, $timestamp) = $event->{event}->args; my (undef, $channel, $by, $timestamp) = $event->{event}->args;
$self->{pbot}->{logger}->log("Topic for $channel set by $by on " . localtime($timestamp) . "\n"); $self->{pbot}->{logger}->log("Topic for $channel set by $by on " . localtime($timestamp) . "\n");
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_BY', $by, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC_SET_BY', $by, 1);
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_ON', $timestamp, 1); $self->{pbot}->{channels}->{storage}->set($channel, 'TOPIC_SET_ON', $timestamp, 1);
return 0; return 0;
} }

View File

@ -18,8 +18,8 @@ sub initialize {
$self->{filename} = $conf{filename}; $self->{filename} = $conf{filename};
$self->{ignorelist} = PBot::DualIndexHashObject->new(pbot => $self->{pbot}, name => 'IgnoreList', filename => $self->{filename}); $self->{storage} = PBot::DualIndexHashObject->new(pbot => $self->{pbot}, name => 'IgnoreList', filename => $self->{filename});
$self->{ignorelist}->load; $self->{storage}->load;
$self->enqueue_ignores; $self->enqueue_ignores;
$self->{pbot}->{commands}->register(sub { $self->cmd_ignore(@_) }, "ignore", 1); $self->{pbot}->{commands}->register(sub { $self->cmd_ignore(@_) }, "ignore", 1);
@ -44,11 +44,11 @@ sub cmd_ignore {
my $now = time; my $now = time;
my $ignored = 0; my $ignored = 0;
foreach my $channel (sort $self->{ignorelist}->get_keys) { foreach my $channel (sort $self->{storage}->get_keys) {
$text .= $channel eq '.*' ? "global:\n" : "$channel:\n"; $text .= $channel eq '.*' ? "global:\n" : "$channel:\n";
my @list; my @list;
foreach my $hostmask (sort $self->{ignorelist}->get_keys($channel)) { foreach my $hostmask (sort $self->{storage}->get_keys($channel)) {
my $timeout = $self->{ignorelist}->get_data($channel, $hostmask, 'timeout'); my $timeout = $self->{storage}->get_data($channel, $hostmask, 'timeout');
if ($timeout == -1) { if ($timeout == -1) {
push @list, " $hostmask"; push @list, " $hostmask";
} else { } else {
@ -90,9 +90,9 @@ sub enqueue_ignores {
my ($self) = @_; my ($self) = @_;
my $now = time; my $now = time;
foreach my $channel ($self->{ignorelist}->get_keys) { foreach my $channel ($self->{storage}->get_keys) {
foreach my $hostmask ($self->{ignorelist}->get_keys($channel)) { foreach my $hostmask ($self->{storage}->get_keys($channel)) {
my $timeout = $self->{ignorelist}->get_data($channel, $hostmask, 'timeout'); my $timeout = $self->{storage}->get_data($channel, $hostmask, 'timeout');
next if $timeout == -1; # permanent ignore next if $timeout == -1; # permanent ignore
my $interval = $timeout - $now; my $interval = $timeout - $now;
@ -133,7 +133,7 @@ sub add {
$data->{timeout} = time + $length; $data->{timeout} = time + $length;
} }
$self->{ignorelist}->add($channel, $hostmask, $data); $self->{storage}->add($channel, $hostmask, $data);
if ($length > 0) { if ($length > 0) {
$self->{pbot}->{event_queue}->dequeue_event("ignore_timeout $channel $hostmask"); $self->{pbot}->{event_queue}->dequeue_event("ignore_timeout $channel $hostmask");
@ -160,7 +160,7 @@ sub remove {
$channel = '.*' if $channel !~ /^#/; $channel = '.*' if $channel !~ /^#/;
$self->{pbot}->{event_queue}->dequeue_event("ignore_timeout $channel $hostmask"); $self->{pbot}->{event_queue}->dequeue_event("ignore_timeout $channel $hostmask");
return $self->{ignorelist}->remove($channel, $hostmask); return $self->{storage}->remove($channel, $hostmask);
} }
sub is_ignored { sub is_ignored {
@ -169,8 +169,8 @@ sub is_ignored {
return 0 if $self->{pbot}->{users}->loggedin_admin($channel, $hostmask); return 0 if $self->{pbot}->{users}->loggedin_admin($channel, $hostmask);
foreach my $chan ('.*', $channel) { foreach my $chan ('.*', $channel) {
foreach my $ignored ($self->{ignorelist}->get_keys($chan)) { foreach my $ignored ($self->{storage}->get_keys($chan)) {
my $regex = $self->{ignorelist}->get_data($chan, $ignored, 'regex'); my $regex = $self->{storage}->get_data($chan, $ignored, 'regex');
return 1 if $hostmask =~ /^$regex$/i; return 1 if $hostmask =~ /^$regex$/i;
} }
} }

View File

@ -646,10 +646,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}->{factoids}->get_data($chan, $trigger, 'preserve_whitespace') // 0; $context->{preserve_whitespace} = $self->{pbot}->{factoids}->{storage}->get_data($chan, $trigger, 'preserve_whitespace') // 0;
} }
$use_output_queue = $self->{pbot}->{factoids}->{factoids}->get_data($chan, $trigger, 'use_output_queue') // 0; $use_output_queue = $self->{pbot}->{factoids}->{storage}->get_data($chan, $trigger, 'use_output_queue') // 0;
} }
} }

View File

@ -83,11 +83,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}->{factoids}->get_keys) { foreach my $channel (sort $self->{pbot}->{factoids}->{storage}->get_keys) {
foreach my $command (sort $self->{pbot}->{factoids}->{factoids}->get_keys($channel)) { foreach my $command (sort $self->{pbot}->{factoids}->{storage}->get_keys($channel)) {
next if $command eq '_name'; next if $command eq '_name';
if ($self->{pbot}->{factoids}->{factoids}->get_data($channel, $command, 'type') eq 'module') { if ($self->{pbot}->{factoids}->{storage}->get_data($channel, $command, 'type') eq 'module') {
$text .= $self->{pbot}->{factoids}->{factoids}->get_data($channel, $command, '_name') . ' '; $text .= $self->{pbot}->{factoids}->{storage}->get_data($channel, $command, '_name') . ' ';
} }
} }
} }
@ -176,7 +176,7 @@ sub cmd_reload {
}, },
'ignores' => sub { 'ignores' => sub {
$self->{pbot}->{ignorelist}->{ignorelist}->load; $self->{pbot}->{ignorelist}->{storage}->load;
return "Ignore list reloaded."; return "Ignore list reloaded.";
}, },
@ -186,7 +186,7 @@ sub cmd_reload {
}, },
'channels' => sub { 'channels' => sub {
$self->{pbot}->{channels}->{channels}->load; $self->{pbot}->{channels}->{storage}->load;
return "Channels reloaded."; return "Channels reloaded.";
}, },

View File

@ -33,7 +33,7 @@ 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}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{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') . '.';
@ -56,7 +56,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}->{factoids}; my $factoids = $self->{pbot}->{factoids}->{storage};
if (not $factoids->exists('.*', $module)) { if (not $factoids->exists('.*', $module)) {
return "/say $module not found."; return "/say $module not found.";
@ -108,7 +108,7 @@ sub launch_module {
$context->{keyword} = $trigger; $context->{keyword} = $trigger;
$context->{trigger} = $trigger; $context->{trigger} = $trigger;
my $module = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, 'action'); my $module = $self->{pbot}->{factoids}->{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)") . '): '
@ -124,8 +124,8 @@ sub launch_module {
Carp::croak("Could not chdir to '$module_dir': $!"); Carp::croak("Could not chdir to '$module_dir': $!");
} }
if ($self->{pbot}->{factoids}->{factoids}->exists($channel, $trigger, 'workdir')) { if ($self->{pbot}->{factoids}->{storage}->exists($channel, $trigger, 'workdir')) {
chdir $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, 'workdir'); chdir $self->{pbot}->{factoids}->{storage}->get_data($channel, $trigger, 'workdir');
} }
# FIXME -- add check to ensure $module exists # FIXME -- add check to ensure $module exists

View File

@ -330,8 +330,8 @@ sub process_pipe_reader {
if (not $context->{nickprefix}) { if (not $context->{nickprefix}) {
# 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}->{factoids}->exists($context->{channel}, $context->{trigger}, 'add_nick') and $self->{pbot}->{factoids}->{storage}->exists($context->{channel}, $context->{trigger}, 'add_nick')
and $self->{pbot}->{factoids}->{factoids}->get_data($context->{channel}, $context->{trigger}, 'add_nick') != 0) and $self->{pbot}->{factoids}->{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

@ -22,7 +22,7 @@ sub initialize {
my $filename = $conf{filename} // Carp::croak("Missing filename configuration item in " . __FILE__); my $filename = $conf{filename} // Carp::croak("Missing filename configuration item in " . __FILE__);
# registry is stored as a dual-index hash object # registry is stored as a dual-index hash object
$self->{registry} = PBot::DualIndexHashObject->new(name => 'Registry', filename => $filename, pbot => $self->{pbot}); $self->{storage} = PBot::DualIndexHashObject->new(name => 'Registry', filename => $filename, pbot => $self->{pbot});
# registry triggers are processed when a registry entry is modified # registry triggers are processed when a registry entry is modified
$self->{triggers} = {}; $self->{triggers} = {};
@ -57,8 +57,8 @@ sub initialize {
$self->add_default('text', 'irc', 'port', $conf{port} // 6667); $self->add_default('text', 'irc', 'port', $conf{port} // 6667);
$self->add_default('text', 'irc', 'sasl', $conf{SASL} // 0); $self->add_default('text', 'irc', 'sasl', $conf{SASL} // 0);
$self->add_default('text', 'irc', 'ssl', $conf{SSL} // 0); $self->add_default('text', 'irc', 'ssl', $conf{SSL} // 0);
$self->add_default('text', 'irc', 'ssl_ca_file', $conf{SSL_ca_file} // 'none'); $self->add_default('text', 'irc', 'ssl_ca_file', $conf{SSL_ca_file} // '');
$self->add_default('text', 'irc', 'ssl_ca_path', $conf{SSL_ca_path} // 'none'); $self->add_default('text', 'irc', 'ssl_ca_path', $conf{SSL_ca_path} // '');
$self->add_default('text', 'irc', 'botnick', $conf{botnick} // ""); $self->add_default('text', 'irc', 'botnick', $conf{botnick} // "");
$self->add_default('text', 'irc', 'username', $conf{username} // "pbot3"); $self->add_default('text', 'irc', 'username', $conf{username} // "pbot3");
$self->add_default('text', 'irc', 'realname', $conf{realname} // "https://github.com/pragma-/pbot"); $self->add_default('text', 'irc', 'realname', $conf{realname} // "https://github.com/pragma-/pbot");
@ -123,12 +123,12 @@ sub load {
my $self = shift; my $self = shift;
# load registry from file # load registry from file
$self->{registry}->load; $self->{storage}->load;
# fire off all registered triggers # fire off all registered triggers
foreach my $section ($self->{registry}->get_keys) { foreach my $section ($self->{storage}->get_keys) {
foreach my $item ($self->{registry}->get_keys($section)) { foreach my $item ($self->{storage}->get_keys($section)) {
$self->process_trigger($section, $item, $self->{registry}->get_data($section, $item, 'value')); $self->process_trigger($section, $item, $self->{storage}->get_data($section, $item, 'value'));
} }
} }
} }
@ -136,7 +136,7 @@ sub load {
sub save { sub save {
my $self = shift; my $self = shift;
$self->{registry}->save; $self->{storage}->save;
} }
sub add_default { sub add_default {
@ -150,7 +150,7 @@ sub add {
$type = lc $type; $type = lc $type;
if (not $self->{registry}->exists($section, $item)) { if (not $self->{storage}->exists($section, $item)) {
# registry entry does not exist # registry entry does not exist
my $data = { my $data = {
@ -158,7 +158,7 @@ sub add {
type => $type, type => $type,
}; };
$self->{registry}->add($section, $item, $data, 1); $self->{storage}->add($section, $item, $data, 1);
} else { } else {
# registry entry already exists # registry entry already exists
@ -168,11 +168,11 @@ sub add {
} }
# update value # update value
$self->{registry}->set($section, $item, 'value', $value, 1); $self->{storage}->set($section, $item, 'value', $value, 1);
# update type only if it doesn't exist # update type only if it doesn't exist
unless ($self->{registry}->exists($section, $item, 'type')) { unless ($self->{storage}->exists($section, $item, 'type')) {
$self->{registry}->set($section, $item, 'type', $type, 1); $self->{storage}->set($section, $item, 'type', $type, 1);
} }
} }
@ -185,7 +185,7 @@ sub add {
sub remove { sub remove {
my ($self, $section, $item) = @_; my ($self, $section, $item) = @_;
$self->{registry}->remove($section, $item); $self->{storage}->remove($section, $item);
} }
sub set_default { sub set_default {
@ -199,7 +199,7 @@ sub set {
$key = lc $key if defined $key; $key = lc $key if defined $key;
if ($is_default && $self->{registry}->exists($section, $item, $key)) { if ($is_default && $self->{storage}->exists($section, $item, $key)) {
return; return;
} }
@ -211,7 +211,7 @@ sub set {
$oldvalue //= ''; $oldvalue //= '';
my $result = $self->{registry}->set($section, $item, $key, $value, 1); my $result = $self->{storage}->set($section, $item, $key, $value, 1);
if (defined $key and $key eq 'value' and defined $value and $oldvalue ne $value) { if (defined $key and $key eq 'value' and defined $value and $oldvalue ne $value) {
$self->process_trigger($section, $item, $value); $self->process_trigger($section, $item, $value);
@ -227,7 +227,7 @@ sub unset {
$key = lc $key if defined $key; $key = lc $key if defined $key;
return $self->{registry}->unset($section, $item, $key); return $self->{storage}->unset($section, $item, $key);
} }
sub get_value { sub get_value {
@ -241,16 +241,16 @@ sub get_value {
# TODO: use user-metadata for this # TODO: use user-metadata for this
if (defined $context and exists $context->{nick}) { if (defined $context and exists $context->{nick}) {
my $context_nick = lc $context->{nick}; my $context_nick = lc $context->{nick};
if ($self->{registry}->exists($section, "$item.nick.$context_nick")) { if ($self->{storage}->exists($section, "$item.nick.$context_nick")) {
$key = "$item.nick.$context_nick"; $key = "$item.nick.$context_nick";
} }
} }
if ($self->{registry}->exists($section, $key)) { if ($self->{storage}->exists($section, $key)) {
if (not $as_text and $self->{registry}->get_data($section, $key, 'type') eq 'array') { if (not $as_text and $self->{storage}->get_data($section, $key, 'type') eq 'array') {
return split /\s*,\s*/, $self->{registry}->get_data($section, $key, 'value'); return split /\s*,\s*/, $self->{storage}->get_data($section, $key, 'value');
} else { } else {
return $self->{registry}->get_data($section, $key, 'value'); return $self->{storage}->get_data($section, $key, 'value');
} }
} }
@ -268,17 +268,17 @@ sub get_array_value {
# TODO: use user-metadata for this # TODO: use user-metadata for this
if (defined $context and exists $context->{nick}) { if (defined $context and exists $context->{nick}) {
my $context_nick = lc $context->{nick}; my $context_nick = lc $context->{nick};
if ($self->{registry}->exists($section, "$item.nick.$context_nick")) { if ($self->{storage}->exists($section, "$item.nick.$context_nick")) {
$key = "$item.nick.$context_nick"; $key = "$item.nick.$context_nick";
} }
} }
if ($self->{registry}->exists($section, $key)) { if ($self->{storage}->exists($section, $key)) {
if ($self->{registry}->get_data($section, $key, 'type') eq 'array') { if ($self->{storage}->get_data($section, $key, 'type') eq 'array') {
my @array = split /\s*,\s*/, $self->{registry}->get_data($section, $key, 'value'); my @array = split /\s*,\s*/, $self->{storage}->get_data($section, $key, 'value');
return $array[$index >= $#array ? $#array : $index]; return $array[$index >= $#array ? $#array : $index];
} else { } else {
return $self->{registry}->get_data($section, $key, 'value'); return $self->{storage}->get_data($section, $key, 'value');
} }
} }

View File

@ -72,11 +72,11 @@ sub cmd_regunset {
return $usage; return $usage;
} }
if (not $self->{pbot}->{registry}->{registry}->exists($section)) { if (not $self->{pbot}->{registry}->{storage}->exists($section)) {
return "No such registry section $section."; return "No such registry section $section.";
} }
if (not $self->{pbot}->{registry}->{registry}->exists($section, $item)) { if (not $self->{pbot}->{registry}->{storage}->exists($section, $item)) {
return "No such item $item in section $section."; return "No such item $item in section $section.";
} }
@ -140,7 +140,7 @@ sub cmd_regshow {
my ($self, $context) = @_; my ($self, $context) = @_;
my $usage = "Usage: regshow <section>.<item>"; my $usage = "Usage: regshow <section>.<item>";
my $registry = $self->{pbot}->{registry}->{registry}; my $registry = $self->{pbot}->{registry}->{storage};
# support "<section>.<key>" syntax in addition to "<section> <key>" # support "<section>.<key>" syntax in addition to "<section> <key>"
my $section = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // return $usage; my $section = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // return $usage;
@ -181,7 +181,7 @@ sub cmd_regfind {
my ($self, $context) = @_; my ($self, $context) = @_;
my $usage = "Usage: regfind [-showvalues] [-section section] <regex>"; my $usage = "Usage: regfind [-showvalues] [-section section] <regex>";
my $registry = $self->{pbot}->{registry}->{registry}; my $registry = $self->{pbot}->{registry}->{storage};
my $arguments = $context->{arguments}; my $arguments = $context->{arguments};
@ -291,7 +291,7 @@ sub cmd_regchange {
$section = lc $section; $section = lc $section;
$item = lc $item; $item = lc $item;
my $registry = $self->{pbot}->{registry}->{registry}; my $registry = $self->{pbot}->{registry}->{storage};
if (not $registry->exists($section)) { if (not $registry->exists($section)) {
return "No such registry section $section."; return "No such registry section $section.";

View File

@ -13,7 +13,7 @@ use PBot::Imports;
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{users} = PBot::HashObject->new(name => 'Users', filename => $conf{filename}, pbot => $conf{pbot}); $self->{storage} = PBot::HashObject->new(name => 'Users', filename => $conf{filename}, pbot => $conf{pbot});
$self->{pbot}->{commands}->register(sub { $self->cmd_login(@_) }, "login", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_login(@_) }, "login", 0);
$self->{pbot}->{commands}->register(sub { $self->cmd_logout(@_) }, "logout", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_logout(@_) }, "logout", 0);
@ -121,11 +121,11 @@ sub cmd_login {
my $name = $self->{user_index}->{$user_channel}->{$user_hostmask}; my $name = $self->{user_index}->{$user_channel}->{$user_hostmask};
my $u = $self->{users}->get_data($name); my $u = $self->{storage}->get_data($name);
my $channel_text = $user_channel eq 'global' ? '' : " for $user_channel"; my $channel_text = $user_channel eq 'global' ? '' : " for $user_channel";
if ($u->{loggedin}) { if ($u->{loggedin}) {
return "/msg $context->{nick} You are already logged into " . $self->{users}->get_key_name($name) . " ($user_hostmask)$channel_text."; return "/msg $context->{nick} You are already logged into " . $self->{storage}->get_key_name($name) . " ($user_hostmask)$channel_text.";
} }
my $result = $self->login($user_channel, $user_hostmask, $arguments); my $result = $self->login($user_channel, $user_hostmask, $arguments);
@ -140,12 +140,12 @@ sub cmd_logout {
my $name = $self->{user_index}->{$user_channel}->{$user_hostmask}; my $name = $self->{user_index}->{$user_channel}->{$user_hostmask};
my $u = $self->{users}->get_data($name); my $u = $self->{storage}->get_data($name);
my $channel_text = $user_channel eq 'global' ? '' : " for $user_channel"; my $channel_text = $user_channel eq 'global' ? '' : " for $user_channel";
return "/msg $context->{nick} You are not logged into " . $self->{users}->get_key_name($name) . " ($user_hostmask)$channel_text." if not $u->{loggedin}; return "/msg $context->{nick} You are not logged into " . $self->{storage}->get_key_name($name) . " ($user_hostmask)$channel_text." if not $u->{loggedin};
$self->logout($user_channel, $user_hostmask); $self->logout($user_channel, $user_hostmask);
return "/msg $context->{nick} Logged out of " . $self->{users}->get_key_name($name) . " ($user_hostmask)$channel_text."; return "/msg $context->{nick} Logged out of " . $self->{storage}->get_key_name($name) . " ($user_hostmask)$channel_text.";
} }
sub cmd_users { sub cmd_users {
@ -185,14 +185,14 @@ sub cmd_users {
$seen_names{$name} = 1; $seen_names{$name} = 1;
$text .= $sep; $text .= $sep;
my $has_cap = 0; my $has_cap = 0;
foreach my $key ($self->{users}->get_keys($name)) { foreach my $key ($self->{storage}->get_keys($name)) {
if ($self->{pbot}->{capabilities}->exists($key)) { if ($self->{pbot}->{capabilities}->exists($key)) {
$has_cap = 1; $has_cap = 1;
last; last;
} }
} }
$text .= '+' if $has_cap; $text .= '+' if $has_cap;
$text .= $self->{users}->get_key_name($name); $text .= $self->{storage}->get_key_name($name);
$sep = " "; $sep = " ";
} }
$sep = "; "; $sep = "; ";
@ -211,7 +211,7 @@ sub cmd_useradd {
my $u; my $u;
foreach my $channel (sort split /\s*,\s*/, lc $channels) { foreach my $channel (sort split /\s*,\s*/, lc $channels) {
$u = $self->{pbot}->{users}->find_user($channel, $context->{hostmask}); $u = $self->find_user($channel, $context->{hostmask});
if (not defined $u) { if (not defined $u) {
return "You do not have a user account for $channel; cannot add users to that channel.\n"; return "You do not have a user account for $channel; cannot add users to that channel.\n";
@ -234,7 +234,7 @@ sub cmd_useradd {
} }
} }
$self->{pbot}->{users}->add_user($name, $channels, $hostmasks, $capabilities, $password); $self->add_user($name, $channels, $hostmasks, $capabilities, $password);
return "User added."; return "User added.";
} }
@ -244,7 +244,7 @@ sub cmd_userdel {
if (not length $context->{arguments}) { return "Usage: userdel <username>"; } if (not length $context->{arguments}) { return "Usage: userdel <username>"; }
my $u = $self->find_user($context->{from}, $context->{hostmask}); my $u = $self->find_user($context->{from}, $context->{hostmask});
my $t = $self->{users}->get_data($context->{arguments}); my $t = $self->{storage}->get_data($context->{arguments});
if ($self->{pbot}->{capabilities}->userhas($t, 'botowner') and not $self->{pbot}->{capabilities}->userhas($u, 'botowner')) { if ($self->{pbot}->{capabilities}->userhas($t, 'botowner') and not $self->{pbot}->{capabilities}->userhas($u, 'botowner')) {
return "Only botowners may delete botowner user accounts."; return "Only botowners may delete botowner user accounts.";
@ -267,7 +267,7 @@ sub cmd_userset {
my $channel = $context->{from}; my $channel = $context->{from};
my $u = $self->find_user($channel, $context->{hostmask}, 1); my $u = $self->find_user($channel, $context->{hostmask}, 1);
my $target = $self->{users}->get_data($name); my $target = $self->{storage}->get_data($name);
if (not $u) { if (not $u) {
$channel = 'global' if $channel !~ /^#/; $channel = 'global' if $channel !~ /^#/;
@ -294,7 +294,7 @@ sub cmd_userset {
return "To set the $key capability your user account must also have it." unless $self->{pbot}->{capabilities}->userhas($u, 'botowner'); return "To set the $key capability your user account must also have it." unless $self->{pbot}->{capabilities}->userhas($u, 'botowner');
} }
my $result = $self->{users}->set($name, $key, $value); my $result = $self->{storage}->set($name, $key, $value);
print "result [$result]\n"; print "result [$result]\n";
$result =~ s/^password: .*;?$/password: <private>;/m; $result =~ s/^password: .*;?$/password: <private>;/m;
@ -322,7 +322,7 @@ sub cmd_userunset {
my $channel = $context->{from}; my $channel = $context->{from};
my $u = $self->find_user($channel, $context->{hostmask}, 1); my $u = $self->find_user($channel, $context->{hostmask}, 1);
my $target = $self->{users}->get_data($name); my $target = $self->{storage}->get_data($name);
if (not $u) { if (not $u) {
$channel = 'global' if $channel !~ /^#/; $channel = 'global' if $channel !~ /^#/;
@ -347,7 +347,7 @@ sub cmd_userunset {
return "To unset the $key capability your user account must also have it." unless $self->{pbot}->{capabilities}->userhas($u, 'botowner'); return "To unset the $key capability your user account must also have it." unless $self->{pbot}->{capabilities}->userhas($u, 'botowner');
} }
return $self->{users}->unset($name, $key); return $self->{storage}->unset($name, $key);
} }
sub cmd_my { sub cmd_my {
@ -369,7 +369,7 @@ sub cmd_my {
$hostmask = "$context->{nick}!$context->{user}\@" . $self->{pbot}->{antiflood}->address_to_mask($context->{host}); $hostmask = "$context->{nick}!$context->{user}\@" . $self->{pbot}->{antiflood}->address_to_mask($context->{host});
$name = $context->{nick}; $name = $context->{nick};
$u = $self->{users}->get_data($name); $u = $self->{storage}->get_data($name);
if ($u) { if ($u) {
$self->{pbot}->{logger}->log("Adding additional hostmask $hostmask to user account $name\n"); $self->{pbot}->{logger}->log("Adding additional hostmask $hostmask to user account $name\n");
$u->{hostmasks} .= ",$hostmask"; $u->{hostmasks} .= ",$hostmask";
@ -412,7 +412,7 @@ sub cmd_my {
$result = "Usage: my <key> [value]; "; $result = "Usage: my <key> [value]; ";
} }
$result .= $self->{users}->set($name, $key, $value); $result .= $self->{storage}->set($name, $key, $value);
$result =~ s/^password: .*;?$/password: <private>;/m; $result =~ s/^password: .*;?$/password: <private>;/m;
return $result; return $result;
} }
@ -477,14 +477,14 @@ sub add_user {
} }
$self->{pbot}->{logger}->log("Adding new user (caps: $capabilities): name: $name hostmasks: $hostmasks channels: $channels\n"); $self->{pbot}->{logger}->log("Adding new user (caps: $capabilities): name: $name hostmasks: $hostmasks channels: $channels\n");
$self->{users}->add($name, $data, $dont_save); $self->{storage}->add($name, $data, $dont_save);
$self->rebuild_user_index; $self->rebuild_user_index;
return $data; return $data;
} }
sub remove_user { sub remove_user {
my ($self, $name) = @_; my ($self, $name) = @_;
my $result = $self->{users}->remove($name); my $result = $self->{storage}->remove($name);
$self->rebuild_user_index; $self->rebuild_user_index;
return $result; return $result;
} }
@ -492,15 +492,15 @@ sub remove_user {
sub load { sub load {
my $self = shift; my $self = shift;
$self->{users}->load; $self->{storage}->load;
$self->rebuild_user_index; $self->rebuild_user_index;
my $i = 0; my $i = 0;
foreach my $name (sort $self->{users}->get_keys) { foreach my $name (sort $self->{storage}->get_keys) {
$i++; $i++;
my $password = $self->{users}->get_data($name, 'password'); my $password = $self->{storage}->get_data($name, 'password');
my $channels = $self->{users}->get_data($name, 'channels'); my $channels = $self->{storage}->get_data($name, 'channels');
my $hostmasks = $self->{users}->get_data($name, 'hostmasks'); my $hostmasks = $self->{storage}->get_data($name, 'hostmasks');
if (not defined $channels or not defined $hostmasks or not defined $password) { if (not defined $channels or not defined $hostmasks or not defined $password) {
Carp::croak "User $name is missing critical data\n"; Carp::croak "User $name is missing critical data\n";
} }
@ -510,7 +510,7 @@ sub load {
sub save { sub save {
my ($self) = @_; my ($self) = @_;
$self->{users}->save; $self->{storage}->save;
} }
sub rebuild_user_index { sub rebuild_user_index {
@ -519,9 +519,9 @@ sub rebuild_user_index {
$self->{user_index} = {}; $self->{user_index} = {};
$self->{user_cache} = {}; $self->{user_cache} = {};
foreach my $name ($self->{users}->get_keys) { foreach my $name ($self->{storage}->get_keys) {
my $channels = $self->{users}->get_data($name, 'channels'); my $channels = $self->{storage}->get_data($name, 'channels');
my $hostmasks = $self->{users}->get_data($name, 'hostmasks'); my $hostmasks = $self->{storage}->get_data($name, 'hostmasks');
my @c = split /\s*,\s*/, $channels; my @c = split /\s*,\s*/, $channels;
my @h = split /\s*,\s*/, $hostmasks; my @h = split /\s*,\s*/, $hostmasks;
@ -607,7 +607,7 @@ sub find_user {
return undef if not defined $found_channel; return undef if not defined $found_channel;
my $name = $self->{user_index}->{$found_channel}->{$found_hostmask}; my $name = $self->{user_index}->{$found_channel}->{$found_hostmask};
$self->cache_user($found_channel, $hostmask, $name, $found_hostmask); $self->cache_user($found_channel, $hostmask, $name, $found_hostmask);
return wantarray ? ($self->{users}->get_data($name), $name) : $self->{users}->get_data($name); return wantarray ? ($self->{storage}->get_data($name), $name) : $self->{storage}->get_data($name);
} }
sub find_admin { sub find_admin {
@ -636,8 +636,8 @@ sub login {
$user->{loggedin} = 1; $user->{loggedin} = 1;
my ($user_chan, $user_hostmask) = $self->find_user_account($channel, $hostmask); my ($user_chan, $user_hostmask) = $self->find_user_account($channel, $hostmask);
my $name = $self->{user_index}->{$user_chan}->{$user_hostmask}; my $name = $self->{user_index}->{$user_chan}->{$user_hostmask};
$self->{pbot}->{logger}->log("$hostmask logged into " . $self->{users}->get_key_name($name) . " ($hostmask)$channel_text.\n"); $self->{pbot}->{logger}->log("$hostmask logged into " . $self->{storage}->get_key_name($name) . " ($hostmask)$channel_text.\n");
return "Logged into " . $self->{users}->get_key_name($name) . " ($hostmask)$channel_text."; return "Logged into " . $self->{storage}->get_key_name($name) . " ($hostmask)$channel_text.";
} }
sub logout { sub logout {

View File

@ -28,10 +28,16 @@ sub unload {
sub rejoin_channel { sub rejoin_channel {
my ($self, $channel) = @_; my ($self, $channel) = @_;
$self->{rejoins}->{$channel}->{rejoins} = 0 if not exists $self->{rejoins}->{$channel};
if (not exists $self->{rejoins}->{$channel}) {
$self->{rejoins}->{$channel}->{rejoins} = 0;
}
my $delay = $self->{pbot}->{registry}->get_array_value($channel, 'rejoin_delay', $self->{rejoins}->{$channel}->{rejoins}); my $delay = $self->{pbot}->{registry}->get_array_value($channel, 'rejoin_delay', $self->{rejoins}->{$channel}->{rejoins});
$delay = $self->{pbot}->{registry}->get_array_value('autorejoin', 'rejoin_delay', $self->{rejoins}->{$channel}->{rejoins}) if not defined $delay;
if (not defined $delay) {
$delay = $self->{pbot}->{registry}->get_array_value('autorejoin', 'rejoin_delay', $self->{rejoins}->{$channel}->{rejoins});
}
$self->{pbot}->{interpreter}->add_botcmd_to_command_queue($channel, "join $channel", $delay); $self->{pbot}->{interpreter}->add_botcmd_to_command_queue($channel, "join $channel", $delay);
@ -42,25 +48,44 @@ sub rejoin_channel {
sub on_kick { sub on_kick {
my ($self, $event_type, $event) = @_; my ($self, $event_type, $event) = @_;
my ($nick, $user, $host, $target, $channel, $reason) =
($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to, $event->{event}->{args}[0], $event->{event}->{args}[1]); my ($nick, $user, $host, $target, $channel, $reason) = (
$event->{event}->nick,
$event->{event}->user,
$event->{event}->host,
$event->{event}->to,
$event->{event}->{args}[0],
$event->{event}->{args}[1],
);
return 0 if not $self->{pbot}->{channels}->is_active($channel); return 0 if not $self->{pbot}->{channels}->is_active($channel);
return 0 if $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}->{noautorejoin}; return 0 if $self->{pbot}->{channels}->{storage}->get_data($channel, 'noautorejoin');
if ($target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { $self->rejoin_channel($channel); } if ($target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
return 0; $self->rejoin_channel($channel);
}
return 1;
} }
sub on_part { sub on_part {
my ($self, $event_type, $event) = @_; my ($self, $event_type, $event) = @_;
my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to);
my ($nick, $user, $host, $channel) = (
$event->{event}->nick,
$event->{event}->user,
$event->{event}->host,
$event->{event}->to,
);
return 0 if not $self->{pbot}->{channels}->is_active($channel); return 0 if not $self->{pbot}->{channels}->is_active($channel);
return 0 if $self->{pbot}->{channels}->{channels}->{hash}->{lc $channel}->{noautorejoin}; return 0 if $self->{pbot}->{channels}->{storage}->get_data($channel, 'noautorejoin');
if ($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { $self->rejoin_channel($channel); } if ($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
return 0; $self->rejoin_channel($channel);
}
return 1;
} }
1; 1;

View File

@ -59,7 +59,7 @@ sub cmd_date {
# check for user timezone metadata # check for user timezone metadata
if (defined $user_override) { if (defined $user_override) {
my $userdata = $self->{pbot}->{users}->{users}->get_data($user_override); my $userdata = $self->{pbot}->{users}->{storage}->get_data($user_override);
if (not defined $userdata) { if (not defined $userdata) {
return "No such user account $user_override. They may use the `my` command to create a user account and set their `timezone` user metadata." return "No such user account $user_override. They may use the `my` command to create a user account and set their `timezone` user metadata."

View File

@ -218,7 +218,7 @@ sub plang_builtin_userget {
my ($self, $plang, $context, $name, $arguments) = @_; my ($self, $plang, $context, $name, $arguments) = @_;
my ($username) = ($arguments->[0], $arguments->[1]); my ($username) = ($arguments->[0], $arguments->[1]);
my $user = $self->{pbot}->{users}->{users}->get_data($username->[1]); my $user = $self->{pbot}->{users}->{storage}->get_data($username->[1]);
if (not defined $user) { if (not defined $user) {
return [['TYPE', 'Null'], undef]; return [['TYPE', 'Null'], undef];

View File

@ -51,7 +51,7 @@ sub cmd_weather {
$arguments = "@opt_args"; $arguments = "@opt_args";
if (defined $user_override) { if (defined $user_override) {
my $userdata = $self->{pbot}->{users}->{users}->get_data($user_override); my $userdata = $self->{pbot}->{users}->{storage}->get_data($user_override);
return "No such user account $user_override." if not defined $userdata; return "No such user account $user_override." if not defined $userdata;
return "User account does not have `location` set." if not exists $userdata->{location}; return "User account does not have `location` set." if not exists $userdata->{location};
$arguments = $userdata->{location}; $arguments = $userdata->{location};

View File

@ -80,7 +80,7 @@ sub cmd_wttr {
if (defined $options{u}) { if (defined $options{u}) {
my $username = delete $options{u}; my $username = delete $options{u};
my $userdata = $self->{pbot}->{users}->{users}->get_data($username); my $userdata = $self->{pbot}->{users}->{storage}->get_data($username);
return "No such user account $username." if not defined $userdata; return "No such user account $username." if not defined $userdata;
return "User account does not have `location` set." if not exists $userdata->{location}; return "User account does not have `location` set." if not exists $userdata->{location};
$arguments = $userdata->{location}; $arguments = $userdata->{location};