From 2b0201343fd59eb0124dd0f2dea1e9f438cc3dbf Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 23 Jul 2021 18:26:45 -0700 Subject: [PATCH] Progress on polishing things --- lib/PBot/Core/Capabilities.pm | 6 +++++- lib/PBot/Core/Channels.pm | 9 ++++++++- lib/PBot/Core/Factoids.pm | 14 +++++++++----- lib/PBot/Core/Handlers.pm | 10 ++++------ lib/PBot/Core/Interpreter.pm | 2 +- lib/PBot/Core/ProcessManager.pm | 4 ++-- lib/PBot/Core/Registry.pm | 6 +++++- lib/PBot/Core/Users.pm | 7 ++++++- 8 files changed, 40 insertions(+), 18 deletions(-) diff --git a/lib/PBot/Core/Capabilities.pm b/lib/PBot/Core/Capabilities.pm index 2409632e..4386bc92 100644 --- a/lib/PBot/Core/Capabilities.pm +++ b/lib/PBot/Core/Capabilities.pm @@ -17,7 +17,11 @@ sub initialize { my $filename = $conf{filename} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/capabilities'; # capabilities hash table - $self->{caps} = PBot::Storage::HashObject->new(name => 'Capabilities', filename => $filename, pbot => $self->{pbot}); + $self->{caps} = PBot::Storage::HashObject->new( + pbot => $self->{pbot}, + name => 'Capabilities', + filename => $filename, + ); # load capabilities $self->{caps}->load; diff --git a/lib/PBot/Core/Channels.pm b/lib/PBot/Core/Channels.pm index 69f7376d..106d72ce 100644 --- a/lib/PBot/Core/Channels.pm +++ b/lib/PBot/Core/Channels.pm @@ -12,7 +12,13 @@ use PBot::Imports; sub initialize { my ($self, %conf) = @_; - $self->{storage} = PBot::Storage::HashObject->new(pbot => $self->{pbot}, name => 'Channels', filename => $conf{filename}); + + $self->{storage} = PBot::Storage::HashObject->new( + pbot => $self->{pbot}, + name => 'Channels', + filename => $conf{filename} + ); + $self->{storage}->load; } @@ -25,6 +31,7 @@ sub join { foreach my $channel (split /,/, $channels) { $channel = lc $channel; + $self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', {channel => $channel}); delete $self->{pbot}->{chanops}->{is_opped}->{$channel}; diff --git a/lib/PBot/Core/Factoids.pm b/lib/PBot/Core/Factoids.pm index df38f085..88705bd6 100644 --- a/lib/PBot/Core/Factoids.pm +++ b/lib/PBot/Core/Factoids.pm @@ -65,7 +65,11 @@ sub initialize { $self->{pbot} = $self->{pbot}; - $self->{storage} = PBot::Storage::DualIndexSQLiteObject->new(name => 'Factoids', filename => $filename, pbot => $self->{pbot}); + $self->{storage} = PBot::Storage::DualIndexSQLiteObject->new( + pbot => $self->{pbot}, + name => 'Factoids', + filename => $filename, + ); $self->{pbot}->{registry}->add_default('text', 'factoids', 'default_rate_limit', 15); $self->{pbot}->{registry}->add_default('text', 'factoids', 'max_name_length', 100); @@ -1144,7 +1148,7 @@ sub interpreter { # if multiple channels have this keyword, then ask user to disambiguate if (@chanlist> 1) { - return undef if $context->{referenced}; + return undef if $context->{embedded}; return $ref_from . "Factoid `$original_keyword` exists in " . join(', ', @chanlist) . "; use `fact $original_keyword` to choose one."; } @@ -1170,7 +1174,7 @@ sub interpreter { # found factfind matches if ($matches !~ m/^No factoids/) { - return undef if $context->{referenced}; + return undef if $context->{embedded}; return "No such factoid '$original_keyword'; $matches"; } @@ -1184,7 +1188,7 @@ sub interpreter { # /msg the caller if nothing similiar was found $context->{send_msg_to_caller} = 1 if $matches eq 'none'; - $context->{send_msg_to_caller} = 1 if $context->{referenced}; + $context->{send_msg_to_caller} = 1 if $context->{embedded}; my $msg_caller = ''; $msg_caller = "/msg $context->{nick} " if $context->{send_msg_to_caller}; @@ -1210,7 +1214,7 @@ sub interpreter { $context->{channel_name} = $channel_name; $context->{trigger_name} = $trigger_name; - return undef if $context->{referenced} and $self->{storage}->get_data($channel, $keyword, 'noembed'); + return undef if $context->{embedded} and $self->{storage}->get_data($channel, $keyword, 'noembed'); if ($self->{storage}->get_data($channel, $keyword, 'locked_to_channel')) { if ($context->{ref_from} ne "") { # called from another channel diff --git a/lib/PBot/Core/Handlers.pm b/lib/PBot/Core/Handlers.pm index 51e10e35..3a504219 100644 --- a/lib/PBot/Core/Handlers.pm +++ b/lib/PBot/Core/Handlers.pm @@ -15,16 +15,14 @@ use PBot::Utils::LoadModules qw/load_modules/; sub initialize { my ($self, %conf) = @_; - # register all the handlers in the Handlers directory - $self->register_handlers(%conf); + # load the handlers in the Handlers directory + $self->load_handlers(%conf); } -# registers all the handler files in the Handlers directory - -sub register_handlers { +sub load_handlers { my ($self, %conf) = @_; - $self->{pbot}->{logger}->log("Registering handlers:\n"); + $self->{pbot}->{logger}->log("Loading handlers:\n"); load_modules($self, 'PBot::Core::Handlers'); } diff --git a/lib/PBot/Core/Interpreter.pm b/lib/PBot/Core/Interpreter.pm index 2bfc40a1..a1ac2e9a 100644 --- a/lib/PBot/Core/Interpreter.pm +++ b/lib/PBot/Core/Interpreter.pm @@ -214,7 +214,7 @@ sub process_line { } # set $context object's embedded flag - $context->{referenced} = $embedded; + $context->{embedded} = $embedded; # interpret all parsed commands foreach $command (@commands) { diff --git a/lib/PBot/Core/ProcessManager.pm b/lib/PBot/Core/ProcessManager.pm index 261acd0f..22d975d1 100644 --- a/lib/PBot/Core/ProcessManager.pm +++ b/lib/PBot/Core/ProcessManager.pm @@ -171,8 +171,8 @@ sub process_pipe_reader { $context->{result} = "No output."; } - # don't output unnecessary result if command was referenced within a message - if ($context->{referenced}) { + # don't output unnecessary result if command was embedded within a message + if ($context->{embedded}) { return if $context->{result} =~ m/(?:no results)/i; } diff --git a/lib/PBot/Core/Registry.pm b/lib/PBot/Core/Registry.pm index 0c184e66..9aaf9e78 100644 --- a/lib/PBot/Core/Registry.pm +++ b/lib/PBot/Core/Registry.pm @@ -18,7 +18,11 @@ sub initialize { my $filename = $conf{filename} // Carp::croak("Missing filename configuration item in " . __FILE__); # registry is stored as a dual-index hash object - $self->{storage} = PBot::Storage::DualIndexHashObject->new(name => 'Registry', filename => $filename, pbot => $self->{pbot}); + $self->{storage} = PBot::Storage::DualIndexHashObject->new( + pbot => $self->{pbot}, + name => 'Registry', + filename => $filename, + ); # registry triggers are processed when a registry entry is modified $self->{triggers} = {}; diff --git a/lib/PBot/Core/Users.pm b/lib/PBot/Core/Users.pm index a62141c7..d0e6039c 100644 --- a/lib/PBot/Core/Users.pm +++ b/lib/PBot/Core/Users.pm @@ -13,7 +13,12 @@ use PBot::Imports; sub initialize { my ($self, %conf) = @_; - $self->{storage} = PBot::Storage::HashObject->new(name => 'Users', filename => $conf{filename}, pbot => $conf{pbot}); + $self->{storage} = PBot::Storage::HashObject->new( + pbot => $conf{pbot}, + name => 'Users', + filename => $conf{filename}, + ); + $self->{user_index} = {}; $self->{user_cache} = {};