aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Admin.pm
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-09-16 23:42:35 +1200
committerDavid Phillips <david@sighup.nz>2018-09-17 00:01:48 +1200
commit5331e8ef6cdb9163e3ec6ee85491b7b286f4cbdc (patch)
tree034e3ffcd6f0f450ba2d6ee51ba54ac3feced716 /Plugin/Admin.pm
parent0352e7d89441abc913d69ce6cff551872edc1fe9 (diff)
downloadidalius-5331e8ef6cdb9163e3ec6ee85491b7b286f4cbdc.tar.xz
Overhaul config parsing
* makes plugin config more private: The config file now uses sections denoted with [Plugin::Foo] where plugin- private config can be stored. Plugins are now passed the usual, as well as a hashref for their own config section. They are also passed the config section of the core, i.e. those config options not appearing in an explicit section. Generally, these are used for bot-global options, so should be accessible to all plugins, but plugin-specific config shall be hidden * tries to improve parsing of hash-like strings and arrays The previous mechanism of using regex to pull out possible tokens was only ever meant to be temporary, and caused problems with escaping or encapsulation inside strings. I have made steps on hash parsing to allow tokens inside strings. Both array and hash parsing still to provide an escape character to escape the item separator (,)
Diffstat (limited to 'Plugin/Admin.pm')
-rw-r--r--Plugin/Admin.pm21
1 files changed, 11 insertions, 10 deletions
diff --git a/Plugin/Admin.pm b/Plugin/Admin.pm
index 02046da..f67df4d 100644
--- a/Plugin/Admin.pm
+++ b/Plugin/Admin.pm
@@ -3,13 +3,13 @@ package Plugin::Admin;
use strict;
use warnings;
-my %config;
+my $config;
sub configure {
- my $self = $_[0];
- my $cmdref = $_[1];
- my $cref = $_[2];
- %config = %$cref;
+ my $self = shift;
+ my $cmdref = shift;
+ shift; # run_command
+ $config = shift;
$cmdref->("say", sub { $self->say(@_); } );
$cmdref->("action", sub { $self->do_action(@_); } );
@@ -32,7 +32,8 @@ sub configure {
sub is_admin {
my $who = shift;
- my $is_admin = grep {$_ eq $who} @{$config{admins}};
+ print "admins are ".(join ", ", $config->{admins})."\n";
+ my $is_admin = grep {$_ eq $who} @{$config->{admins}};
if (!$is_admin) {
# Uhh log this rather than print
print "$who isn't an admin, but tried to use a command";
@@ -148,7 +149,7 @@ sub ignore {
return unless is_admin($who);
return "Syntax: ignore <nick>" unless @arguments == 1;
- push @{$config{ignore}}, $arguments[0];
+ push @{$config->{ignore}}, $arguments[0];
return "Ignoring $arguments[0]";
}
@@ -161,8 +162,8 @@ sub do_not_ignore {
my $target = $arguments[0];
- if (grep { $_ eq $target} @{$config{ignore}}) {
- @{$config{ignore}} = grep { $_ ne $target } @{$config{ignore}};
+ if (grep { $_ eq $target} @{$config->{ignore}}) {
+ @{$config->{ignore}} = grep { $_ ne $target } @{$config->{ignore}};
return "No longer ignoring $target.";
} else {
return "I wasn't ignoring $target anyway.";
@@ -175,7 +176,7 @@ sub dump_ignore {
return "Syntax: who are you ignoring?" unless @arguments == 0;
# FIXME special case for empty ignore
- return "I am ignoring: " . join ", ", @{$config{ignore}};
+ return "I am ignoring: " . join ", ", @{$config->{ignore}};
}
sub exit {