diff options
author | David Phillips <david@sighup.nz> | 2018-04-10 15:06:10 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-04-10 15:06:29 +1200 |
commit | bb1808b1ef92af9a14a073f2e14973ac132b7e7e (patch) | |
tree | 5cf3fb9174e07242ed258ae327d3506df1a5355c /plugin | |
parent | 5aad7b27d5145d4f459ab36d3ffe4a576d3f4ea6 (diff) | |
download | idalius-bb1808b1ef92af9a14a073f2e14973ac132b7e7e.tar.xz |
Add command modules, map command
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/antiflood.pm | 3 | ||||
-rw-r--r-- | plugin/map.pm | 34 | ||||
-rw-r--r-- | plugin/timezone.pm | 36 | ||||
-rw-r--r-- | plugin/tittilate.pm | 3 | ||||
-rw-r--r-- | plugin/url_title.pm | 3 |
5 files changed, 58 insertions, 21 deletions
diff --git a/plugin/antiflood.pm b/plugin/antiflood.pm index 7eb5b7f..a44c07c 100644 --- a/plugin/antiflood.pm +++ b/plugin/antiflood.pm @@ -14,7 +14,8 @@ my %lastmsg = (); sub configure { my $self = $_[0]; - my $cref = $_[1]; + my $cmdref = $_[1]; + my $cref = $_[2]; %config = %$cref; return $self; } diff --git a/plugin/map.pm b/plugin/map.pm new file mode 100644 index 0000000..f8cb256 --- /dev/null +++ b/plugin/map.pm @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +package plugin::map; + +use strict; +use warnings; + +my %config; +my $run_command; + + +sub configure { + my $self = shift; + my $cmdref = shift; + my $cref = shift; + %config = %$cref; + $run_command = shift; + + $cmdref->("map", sub { $self->map(@_); } ); + + return $self; +} + +sub map { + my ($self, $logger, $who, $where, $rest, @arguments) = @_; + my ($command, $subjects) = ($rest =~ /^(.+?)\s+(.*)$/); + + return "[]" unless $subjects; + + my @array = map { $run_command->("$command $_", $who, $where) } (split /,/, $subjects); + + return "[" . (join ", ", @array). "]"; +} +1; diff --git a/plugin/timezone.pm b/plugin/timezone.pm index ecbbd73..8807d54 100644 --- a/plugin/timezone.pm +++ b/plugin/timezone.pm @@ -11,30 +11,30 @@ my %config; sub configure { my $self = $_[0]; - my $cref = $_[1]; + my $cmdref = $_[1]; + my $cref = $_[2]; %config = %$cref; + + $cmdref->("time", sub { $self->time(@_); } ); + return $self; } -sub message { - my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_; - - my $requester = ( split /!/, $who )[0]; +sub time { + my ($self, $logger, $who, $where, $rest, @arguments) = @_; + my $requester = ( split /!/, $who)[0]; my @known_zones = (keys %{$config{timezone}}); - if ($what =~ /^%time\s/) { - if ($what =~ /^%time\s+(.+?)\s*$/) { - my $nick = $1; - if (grep {$_ eq $nick} @known_zones) { - my $d = DateTime->now(); - $d->set_time_zone($config{timezone}->{$nick}); - return "$requester: $nick\'s clock reads $d"; - } else { - return "$requester: I don't know what timezone $nick is in"; - } - } else { - return "$requester: Syntax: %time [nick]"; - } + + return "Syntax: time [nick]" unless @arguments == 1; + + my $nick = $arguments[0]; + if (grep {$_ eq $nick} @known_zones) { + my $d = DateTime->now(); + $d->set_time_zone($config{timezone}->{$nick}); + return "$requester: $nick\'s clock reads $d"; + } else { + return "$requester: I don't know what timezone $nick is in"; } } 1; diff --git a/plugin/tittilate.pm b/plugin/tittilate.pm index 7a1ecd5..4df6b07 100644 --- a/plugin/tittilate.pm +++ b/plugin/tittilate.pm @@ -9,7 +9,8 @@ my %config; sub configure { my $self = $_[0]; - my $cref = $_[1]; + my $cmdref = $_[1]; + my $cref = $_[2]; %config = %$cref; return $self; } diff --git a/plugin/url_title.pm b/plugin/url_title.pm index 9d96410..32995fd 100644 --- a/plugin/url_title.pm +++ b/plugin/url_title.pm @@ -12,7 +12,8 @@ my %config; sub configure { my $self = $_[0]; - my $cref = $_[1]; + my $cmdref = $_[1]; + my $cref = $_[2]; %config = %$cref; return $self; } |