aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Plugin/Antiflood.pm2
-rw-r--r--Plugin/URL_Title.pm2
-rw-r--r--bot.conf.example3
-rw-r--r--config_file.pm7
-rwxr-xr-xidalius.pl40
5 files changed, 31 insertions, 23 deletions
diff --git a/Plugin/Antiflood.pm b/Plugin/Antiflood.pm
index c133e77..3a79d0d 100644
--- a/Plugin/Antiflood.pm
+++ b/Plugin/Antiflood.pm
@@ -23,8 +23,6 @@ sub message {
my $channel = $where->[0];
my $nick = (split /!/, $who)[0];
- return if ($config{antiflood_on} == 0);
-
my $now = time();
push @{$lastmsg{$nick}}, $now;
diff --git a/Plugin/URL_Title.pm b/Plugin/URL_Title.pm
index def7449..1cdf44d 100644
--- a/Plugin/URL_Title.pm
+++ b/Plugin/URL_Title.pm
@@ -32,8 +32,6 @@ sub message
my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
my $url;
- return if ($config{url_on} == 0);
-
# Drawn from RFC 3986Β§2
if ($what =~ /(https?:\/\/[a-z0-9\-\._~:\/\?#\[\]@\!\$&'()\*\+,;=%]+)/i) {
$url = $1;
diff --git a/bot.conf.example b/bot.conf.example
index 428b5eb..de08113 100644
--- a/bot.conf.example
+++ b/bot.conf.example
@@ -1,3 +1,4 @@
+plugins = Plugin::Titillate, Plugin::Admin, Plugin::Ping
nick = somebot
username = bot
ircname = a bot
@@ -17,9 +18,7 @@ group = nobody
triggers = 'sa+x' => '🎷 ', 'trumpet' => '🎺 ', 'snake' => '🐍 '
prefix_nick = 1
prefix = %
-antiflood_on = 0
# URL stuff
-url_on = 1
url_len = 0
diff --git a/config_file.pm b/config_file.pm
index b3bd38f..2b7b366 100644
--- a/config_file.pm
+++ b/config_file.pm
@@ -20,15 +20,14 @@ sub parse_config
'quit_msg',
'user',
'group',
- 'url_on',
'url_len',
'prefix_nick',
- 'prefix',
- 'antiflood_on');
+ 'prefix');
my @list_configs = (
'channels',
'ignore',
- 'admins');
+ 'admins',
+ 'plugins');
my @optional_configs = (
'password');
my $file = $_[0];
diff --git a/idalius.pl b/idalius.pl
index 8db549f..d1cd12e 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -9,15 +9,32 @@ use POE::Component::IRC;
use POE::Component::IRC::Plugin::NickServID;
use config_file;
use IRC::Utils qw(strip_color strip_formatting);
-use Module::Pluggable search_path => "Plugin", instantiate => 'configure';
my $config_file = "bot.conf";
my %config = config_file::parse_config($config_file);
my %laststrike = ();
my $ping_delay = 300;
-
my %commands = ();
+sub log_info {
+ # FIXME direct to a log file instead of stdout
+ my $stamp = strftime("%Y-%m-%d %H:%M:%S %z", localtime);
+ print "$stamp | @_\n";
+}
+
+eval {
+ for my $module (@{$config{plugins}}) {
+ log_info "Loading $module";
+ (my $path = $module) =~ s,::,/,g;
+ require $path . ".pm";
+ $module->configure(\&register_command, \%config, \&run_command);
+ }
+ 1;
+} or do {
+ log_info "Error: failed to load module: $@";
+};
+
+
$| = 1;
my $current_nick = $config{nick};
@@ -26,8 +43,6 @@ my $current_nick = $config{nick};
+$config{url_on};
+$config{url_len};
-my @plugin_list = plugins("dummy", \&register_command, \%config, \&run_command);
-
# New PoCo-IRC object
my $irc = POE::Component::IRC->spawn(
UseSSL => $config{usessl},
@@ -71,10 +86,10 @@ drop_priv();
$poe_kernel->run();
-sub log_info {
- # FIXME direct to a log file instead of stdout
- my $stamp = strftime("%Y-%m-%d %H:%M:%S %z", localtime);
- print "$stamp | @_\n";
+sub module_is_enabled {
+ my $module = $_[0];
+
+ return grep {$_ eq $module} @{$config{plugins}};
}
# Register a command name to a certain sub
@@ -198,13 +213,12 @@ sub irc_public {
strike_add($nick, $channel) if $output;
}
- for my $module (@plugin_list) {
- $output = "";
- if ($module->can("message")) {
+ for my $module (@{$config{plugins}}) {
+ if (module_is_enabled($module) && $module->can("message")) {
$output = $module->message(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what, $irc);
+ $irc->yield(privmsg => $where => $output) if $output;
+ strike_add($nick, $channel) if $output;
}
- $irc->yield(privmsg => $where => $output) if $output;
- strike_add($nick, $channel) if $output;
}
return;