diff options
author | David Phillips <david@sighup.nz> | 2018-09-03 16:14:22 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-09-03 16:14:22 +1200 |
commit | 65694d185582c9a6558ea8bfee99e56a5721540b (patch) | |
tree | 9d6d3da4dd8eb15daff1c645b02cd84d123548e8 | |
parent | 14c1d55b97d61de7eb48acd4a5b745e2ba5e977a (diff) | |
download | idalius-65694d185582c9a6558ea8bfee99e56a5721540b.tar.xz |
Configurable modules
-rw-r--r-- | Plugin/Antiflood.pm | 2 | ||||
-rw-r--r-- | Plugin/URL_Title.pm | 2 | ||||
-rw-r--r-- | bot.conf.example | 3 | ||||
-rw-r--r-- | config_file.pm | 7 | ||||
-rwxr-xr-x | idalius.pl | 40 |
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]; @@ -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(\®ister_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", \®ister_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; |