From 4d9b3f09a7c9e26bf5a28a4c24389a291914f860 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 21 Dec 2019 15:26:01 -0800 Subject: [PATCH] Plugins are now autoloaded via entries listed in the Plugin/autoload file --- PBot/Plugins.pm | 9 ++++++++- Plugins/{_Example.pm => Example.pm} | 4 ++-- Plugins/README | 8 +++----- Plugins/autoload | 11 +++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) rename Plugins/{_Example.pm => Example.pm} (91%) create mode 100644 Plugins/autoload diff --git a/PBot/Plugins.pm b/PBot/Plugins.pm index b28d3555..63959b86 100644 --- a/PBot/Plugins.pm +++ b/PBot/Plugins.pm @@ -52,7 +52,14 @@ sub autoload { $self->{pbot}->{logger}->log("Loading plugins ...\n"); my $plugin_count = 0; - my @plugins = glob "$path/*.pm"; + my $fh; + if (not open $fh, "<$path/autoload") { + $self->{pbot}->{logger}->log("warning: file $path/autoload does not exist; skipping autoloading of Plugins\n"); + return; + } + + chomp(my @plugins = <$fh>); + close $fh; foreach my $plugin (sort @plugins) { $plugin = basename $plugin; diff --git a/Plugins/_Example.pm b/Plugins/Example.pm similarity index 91% rename from Plugins/_Example.pm rename to Plugins/Example.pm index aa77cd2c..789d6e7e 100644 --- a/Plugins/_Example.pm +++ b/Plugins/Example.pm @@ -2,7 +2,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -package Plugins::_Example; +package Plugins::Example; use warnings; use strict; @@ -44,7 +44,7 @@ sub on_public { return 0; } - $self->{pbot}->{logger}->log("_Example plugin: got message from $nick!$user\@$host: $msg\n"); + $self->{pbot}->{logger}->log("Example plugin: got message from $nick!$user\@$host: $msg\n"); return 0; } diff --git a/Plugins/README b/Plugins/README index 857ddefe..c164ef79 100644 --- a/Plugins/README +++ b/Plugins/README @@ -1,8 +1,6 @@ Loadable plugins live here. -All files not beginning with an underscore will be automatically loaded -at bot start-up. +All files listed in the `autoload` file will be loaded at bot start-up. -Plugins (including those starting with an underscore) can be manually loaded -or unloaded with the `plug` and `unplug` commands. Use `pluglist` to list -loaded plugins. +Plugins can be manually loaded or unloaded with the `plug` and `unplug` +commands. Use `pluglist` to list loaded plugins. diff --git a/Plugins/autoload b/Plugins/autoload new file mode 100644 index 00000000..7a722f42 --- /dev/null +++ b/Plugins/autoload @@ -0,0 +1,11 @@ +ActionTrigger.pm +AntiAway.pm +AntiKickAutoRejoin.pm +AntiNickSpam.pm +AntiRepeat.pm +AntiTwitter.pm +AutoRejoin.pm +Counter.pm +Quotegrabs.pm +RemindMe.pm +UrlTitles.pm