mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 04:22:35 +01:00
Rename LoadPackages to LoadModules
This commit is contained in:
parent
51c061f31d
commit
b990d482c1
@ -11,7 +11,7 @@ use parent 'PBot::Core::Class', 'PBot::Core::Registerable';
|
|||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
use PBot::Utils::LoadPackages qw/load_packages/;
|
use PBot::Utils::LoadModules qw/load_modules/;
|
||||||
|
|
||||||
sub initialize {
|
sub initialize {
|
||||||
my ($self, %conf) = @_;
|
my ($self, %conf) = @_;
|
||||||
@ -29,7 +29,7 @@ sub register_commands {
|
|||||||
|
|
||||||
# register commands in Commands directory
|
# register commands in Commands directory
|
||||||
$self->{pbot}->{logger}->log("Registering commands:\n");
|
$self->{pbot}->{logger}->log("Registering commands:\n");
|
||||||
load_packages($self, 'PBot::Core::Commands');
|
load_modules($self, 'PBot::Core::Commands');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub register {
|
sub register {
|
||||||
|
@ -1166,7 +1166,7 @@ sub interpreter {
|
|||||||
if ($strictnamespace) { $namespace_regex = "(?:" . (quotemeta $namespace) . '|\\.\\*)'; }
|
if ($strictnamespace) { $namespace_regex = "(?:" . (quotemeta $namespace) . '|\\.\\*)'; }
|
||||||
|
|
||||||
$context->{arguments} = quotemeta($original_keyword) . " -channel $namespace_regex";
|
$context->{arguments} = quotemeta($original_keyword) . " -channel $namespace_regex";
|
||||||
my $matches = $self->{pbot}->{commands}->{packages}->{Factoids}->cmd_factfind($context);
|
my $matches = $self->{pbot}->{commands}->{modules}->{Factoids}->cmd_factfind($context);
|
||||||
|
|
||||||
# found factfind matches
|
# found factfind matches
|
||||||
if ($matches !~ m/^No factoids/) {
|
if ($matches !~ m/^No factoids/) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# File: IRCHandlers.pm
|
# File: IRCHandlers.pm
|
||||||
#
|
#
|
||||||
# Purpose: Pipes the PBot::Core::IRC default handler through PBot::Core::EventDispatcher,
|
# Purpose: Pipes the PBot::Core::IRC default handler through PBot::Core::EventDispatcher,
|
||||||
# and loads all the packages in the IRCHandlers directory.
|
# and loads all the modules in the IRCHandlers directory.
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
@ -11,7 +11,7 @@ use parent 'PBot::Core::Class';
|
|||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
use PBot::Utils::LoadPackages;
|
use PBot::Utils::LoadModules;
|
||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ sub add_handlers {
|
|||||||
|
|
||||||
# send these events to on_init()
|
# send these events to on_init()
|
||||||
$self->{pbot}->{conn}->add_handler([251, 252, 253, 254, 255, 302],
|
$self->{pbot}->{conn}->add_handler([251, 252, 253, 254, 255, 302],
|
||||||
sub { $self->{packages}->{Server}->on_init(@_) });
|
sub { $self->{modules}->{Server}->on_init(@_) });
|
||||||
|
|
||||||
# ignore these events
|
# ignore these events
|
||||||
$self->{pbot}->{conn}->add_handler(
|
$self->{pbot}->{conn}->add_handler(
|
||||||
@ -57,7 +57,7 @@ sub register_handlers {
|
|||||||
my ($self, %conf) = @_;
|
my ($self, %conf) = @_;
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("Registering IRC handlers:\n");
|
$self->{pbot}->{logger}->log("Registering IRC handlers:\n");
|
||||||
load_packages($self, 'PBot::Core::IRCHandlers');
|
load_modules($self, 'PBot::Core::IRCHandlers');
|
||||||
}
|
}
|
||||||
|
|
||||||
# this default handler prepends 'irc.' to the event-type and then dispatches
|
# this default handler prepends 'irc.' to the event-type and then dispatches
|
||||||
|
@ -1,57 +1,57 @@
|
|||||||
# File: LoadPackages.pm
|
# File: LoadModules.pm
|
||||||
#
|
#
|
||||||
# Purpose: Loads all Perl package files in a given directory.
|
# Purpose: Loads all Perl modules in a given directory, nonrecursively
|
||||||
|
# (i.e. at one depth level).
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package PBot::Utils::LoadPackages;
|
package PBot::Utils::LoadModules;
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
|
|
||||||
# export load_packages subroutine
|
|
||||||
require Exporter;
|
require Exporter;
|
||||||
our @ISA = qw/Exporter/;
|
our @ISA = qw/Exporter/;
|
||||||
our @EXPORT = qw/load_packages/;
|
our @EXPORT = qw/load_modules/;
|
||||||
|
|
||||||
sub load_packages {
|
sub load_modules {
|
||||||
my ($self, $base) = @_;
|
my ($self, $base) = @_;
|
||||||
|
|
||||||
my $base_path = join '/', split '::', $base;
|
my $base_path = join '/', split '::', $base;
|
||||||
|
|
||||||
foreach my $inc_path (@INC) {
|
foreach my $inc_path (@INC) {
|
||||||
if (-d "$inc_path/$base_path") {
|
if (-d "$inc_path/$base_path") {
|
||||||
my @packages = glob "$inc_path/$base_path/*.pm";
|
my @modules = glob "$inc_path/$base_path/*.pm";
|
||||||
|
|
||||||
foreach my $package (sort @packages) {
|
foreach my $module (sort @modules) {
|
||||||
$self->{pbot}->{refresher}->{refresher}->refresh_module($package);
|
$self->{pbot}->{refresher}->{refresher}->refresh_module($module);
|
||||||
|
|
||||||
my $name = basename $package;
|
my $name = basename $module;
|
||||||
$name =~ s/\.pm$//;
|
$name =~ s/\.pm$//;
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log(" $name\n");
|
$self->{pbot}->{logger}->log(" $name\n");
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
require "$package";
|
require "$module";
|
||||||
|
|
||||||
my $class = $base . '::' . $name;
|
my $class = $base . '::' . $name;
|
||||||
$self->{packages}->{$name} = $class->new(pbot => $self->{pbot});
|
$self->{modules}->{$name} = $class->new(pbot => $self->{pbot});
|
||||||
$self->{pbot}->{refresher}->{refresher}->update_cache($package);
|
$self->{pbot}->{refresher}->{refresher}->update_cache($module);
|
||||||
};
|
};
|
||||||
|
|
||||||
# error loading a package
|
# error loading a module
|
||||||
if (my $exception = $@) {
|
if (my $exception = $@) {
|
||||||
$self->{pbot}->{logger}->log("Error loading $package: $exception");
|
$self->{pbot}->{logger}->log("Error loading $module: $exception");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# packages loaded successfully
|
# modules loaded successfully
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# no packages found
|
# no module found
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user