aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'Plugin')
-rw-r--r--Plugin/Admin.pm21
-rw-r--r--Plugin/Antiflood.pm7
-rw-r--r--Plugin/DevNull.pm3
-rw-r--r--Plugin/Echo.pm4
-rw-r--r--Plugin/Introspect.pm9
-rw-r--r--Plugin/Jinx.pm3
-rw-r--r--Plugin/Map.pm52
-rw-r--r--Plugin/Random.pm4
-rw-r--r--Plugin/Source.pm2
-rw-r--r--Plugin/Thanks.pm2
-rw-r--r--Plugin/Timezone.pm12
-rw-r--r--Plugin/Titillate.pm14
-rw-r--r--Plugin/URL_Title.pm12
13 files changed, 40 insertions, 105 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 {
diff --git a/Plugin/Antiflood.pm b/Plugin/Antiflood.pm
index eafa50c..77d7f17 100644
--- a/Plugin/Antiflood.pm
+++ b/Plugin/Antiflood.pm
@@ -7,14 +7,11 @@ my $message_count = 5;
my $message_period = 11;
-my %config;
my %lastmsg = ();
sub configure {
- my $self = $_[0];
- my $cmdref = $_[1];
- my $cref = $_[2];
- %config = %$cref;
+ my $self = shift;
+ my $cmdref = shift;
return $self;
}
diff --git a/Plugin/DevNull.pm b/Plugin/DevNull.pm
index b29a71a..0565aec 100644
--- a/Plugin/DevNull.pm
+++ b/Plugin/DevNull.pm
@@ -3,15 +3,12 @@ package Plugin::DevNull;
use strict;
use warnings;
-my %config;
my $run_command;
sub configure {
my $self = shift;
my $cmdref = shift;
- my $cref = shift;
$run_command = shift;
- %config = %$cref;
$cmdref->("hush", sub { $self->hush(@_); } );
$cmdref->("devnull", sub { $self->hush(@_); } );
diff --git a/Plugin/Echo.pm b/Plugin/Echo.pm
index 76a245a..2cd59fc 100644
--- a/Plugin/Echo.pm
+++ b/Plugin/Echo.pm
@@ -3,13 +3,9 @@ package Plugin::Echo;
use strict;
use warnings;
-my %config;
-
sub configure {
my $self = shift;
my $cmdref = shift;
- my $cref = shift;
- %config = %$cref;
$cmdref->("echo", sub { $self->echo(@_); } );
diff --git a/Plugin/Introspect.pm b/Plugin/Introspect.pm
index 2f42cb2..4c53984 100644
--- a/Plugin/Introspect.pm
+++ b/Plugin/Introspect.pm
@@ -3,13 +3,14 @@ package Plugin::Introspect;
use strict;
use warnings;
-my %config;
+my $root_config;
sub configure {
my $self = shift;
my $cmdref = shift;
- my $cref = shift;
- %config = %$cref;
+ shift; # run_command
+ shift; # module config
+ $root_config = shift;
$cmdref->("plugins", sub { $self->dump_plugins(@_); } );
@@ -18,6 +19,6 @@ sub configure {
sub dump_plugins {
my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
- return "Plugins: " . join ", ", @{$config{plugins}};
+ return "Plugins: " . join ", ", $root_config->{plugins};
}
1;
diff --git a/Plugin/Jinx.pm b/Plugin/Jinx.pm
index a514bb8..f1e712b 100644
--- a/Plugin/Jinx.pm
+++ b/Plugin/Jinx.pm
@@ -11,13 +11,10 @@ my %last_response;
# Last message said on the channel
my %last;
-my %config;
sub configure {
my $self = $_[0];
my $cmdref = $_[1];
- my $cref = $_[2];
- %config = %$cref;
return $self;
}
diff --git a/Plugin/Map.pm b/Plugin/Map.pm
index 665f41f..1e24f9c 100644
--- a/Plugin/Map.pm
+++ b/Plugin/Map.pm
@@ -3,15 +3,13 @@ package Plugin::Map;
use strict;
use warnings;
-my %config;
-my $run_command;
+use ListParser;
+my $run_command;
sub configure {
my $self = shift;
my $cmdref = shift;
- my $cref = shift;
- %config = %$cref;
$run_command = shift;
$cmdref->("map", sub { $self->map(@_); } );
@@ -19,50 +17,6 @@ sub configure {
return $self;
}
-sub parse_list {
- my ($input) = @_;
- my @res;
- my $i = 0;
-
- # Index of the start of the current item
- my $item_i = 0;
-
- # Level of nested lists, 1 being the minimum
- my $nest = 1;
-
- # Are we currently lexing inside a string literal?
- my $is_string = 0;
-
- return ("Error: expected [", undef) unless substr($input, $i, 1) eq "[";
- $i++;
- $item_i = $i;
-
- while ($nest != 0 && $i < length($input)) {
- my $c = substr($input, $i, 1);
-
- if ($c eq "[") {
- $nest++;
- } elsif ($c eq "]") {
- $nest--;
- }
-
- if (($nest == 1 and $c eq ",") || ($nest == 0 and $c eq "]")) {
- my $item = substr($input, $item_i, $i - $item_i);
- $item =~ s/^\s+|\s+$//g;
- push @res, $item;
- $item_i = $i+1;
- }
- $i++;
- }
-
- return ("Error: expected ], got end of line", undef) unless $nest == 0;
-
- if ($i != length($input)) {
- return ("Error: unexpected item in the bagging area (after ']')", undef);
- }
-
- return (undef, @res);
-}
sub map {
my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
@@ -70,7 +24,7 @@ sub map {
return "Syntax: map command [item1, item2, ...]" unless $command and $subjects_raw;
- my ($e, @subjects) = parse_list($subjects_raw);
+ my ($e, @subjects) = ListParser::parse_list($subjects_raw);
return $e if $e;
my @results = map { $run_command->("$command $_", $who, $where) } @subjects;
diff --git a/Plugin/Random.pm b/Plugin/Random.pm
index bd1c4d2..27332f8 100644
--- a/Plugin/Random.pm
+++ b/Plugin/Random.pm
@@ -5,13 +5,9 @@ use warnings;
use List::Util;
-my %config;
-
sub configure {
my $self = shift;
my $cmdref = shift;
- my $cref = shift;
- %config = %$cref;
$cmdref->("shuffle", sub { $self->shuffle(@_); } );
$cmdref->("choose", sub { $self->choose(@_); } );
diff --git a/Plugin/Source.pm b/Plugin/Source.pm
index dcb92e6..e3774e9 100644
--- a/Plugin/Source.pm
+++ b/Plugin/Source.pm
@@ -3,8 +3,6 @@ package Plugin::Source;
use strict;
use warnings;
-my %config;
-
sub configure {
my $self = shift;
my $cmdref = shift;
diff --git a/Plugin/Thanks.pm b/Plugin/Thanks.pm
index 431db5d..e40e3ef 100644
--- a/Plugin/Thanks.pm
+++ b/Plugin/Thanks.pm
@@ -3,8 +3,6 @@ package Plugin::Thanks;
use strict;
use warnings;
-my %config;
-
sub configure {
my $self = shift;
my $cmdref = shift;
diff --git a/Plugin/Timezone.pm b/Plugin/Timezone.pm
index 53f8f4a..b88b6b9 100644
--- a/Plugin/Timezone.pm
+++ b/Plugin/Timezone.pm
@@ -8,10 +8,10 @@ use DateTime;
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->("time", sub { $self->time(@_); } );
@@ -22,7 +22,7 @@ sub time {
my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
my $requester = (split /!/, $who)[0];
- my @known_zones = (keys %{$config{timezone}});
+ my @known_zones = (keys %{$config->{timezone}});
return "Syntax: time [nick]" unless @arguments == 1;
@@ -30,7 +30,7 @@ sub time {
my ($case_nick) = grep {/^$nick$/i} @known_zones;
if ($case_nick) {
my $d = DateTime->now();
- $d->set_time_zone($config{timezone}->{$case_nick});
+ $d->set_time_zone($config->{timezone}->{$case_nick});
my $timestr = $d->strftime("%Y-%m-%d %H:%M %Z");
return "$requester: $nick\'s clock reads $timestr";
} else {
diff --git a/Plugin/Titillate.pm b/Plugin/Titillate.pm
index 79f1a4a..5ce5eeb 100644
--- a/Plugin/Titillate.pm
+++ b/Plugin/Titillate.pm
@@ -3,20 +3,20 @@ package Plugin::Titillate;
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;
return $self;
}
sub on_message {
my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
my $gathered = "";
- my @expressions = (keys %{$config{triggers}});
+ my @expressions = (keys %{$config->{triggers}});
my $expression = join '|', @expressions;
while ($what =~ /($expression)/gi) {
my $matched = $1;
@@ -28,7 +28,7 @@ sub on_message {
last;
}
}
- $gathered .= $config{triggers}->{$key};
+ $gathered .= $config->{triggers}->{$key};
}
return $gathered;
}
diff --git a/Plugin/URL_Title.pm b/Plugin/URL_Title.pm
index 53d6326..9d20cd6 100644
--- a/Plugin/URL_Title.pm
+++ b/Plugin/URL_Title.pm
@@ -6,13 +6,13 @@ use HTTP::Tiny;
use HTML::Parser;
use utf8;
-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;
return $self;
}
@@ -75,7 +75,7 @@ sub on_message
$shorturl =~ s,/$,,g;
# truncate URL without http(s):// to configured length if needed
- $shorturl = (substr $shorturl, 0, $config{url_len}) . "…" if length ($shorturl) > $config{url_len};
+ $shorturl = (substr $shorturl, 0, $config->{url_len}) . "…" if length ($shorturl) > $config->{url_len};
my $composed_title = "$title ($shorturl)";
return $composed_title;