aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'Plugin')
-rw-r--r--Plugin/Admin.pm183
-rw-r--r--Plugin/Echo.pm2
-rw-r--r--Plugin/Map.pm2
-rw-r--r--Plugin/Ping.pm2
-rw-r--r--Plugin/Source.pm26
-rw-r--r--Plugin/Timezone.pm2
6 files changed, 213 insertions, 4 deletions
diff --git a/Plugin/Admin.pm b/Plugin/Admin.pm
new file mode 100644
index 0000000..2a2a691
--- /dev/null
+++ b/Plugin/Admin.pm
@@ -0,0 +1,183 @@
+#!/usr/bin/env perl
+
+package Plugin::Admin;
+
+use strict;
+use warnings;
+
+my %config;
+
+sub configure {
+ my $self = $_[0];
+ my $cmdref = $_[1];
+ my $cref = $_[2];
+ %config = %$cref;
+
+ $cmdref->("say", sub { $self->say(@_); } );
+ $cmdref->("action", sub { $self->action(@_); } );
+
+ $cmdref->("nick", sub { $self->nick(@_); } );
+ $cmdref->("join", sub { $self->join_channel(@_); } );
+ $cmdref->("part", sub { $self->part(@_); } );
+ $cmdref->("mode", sub { $self->mode(@_); } );
+ $cmdref->("kick", sub { $self->kick(@_); } );
+ $cmdref->("topic", sub { $self->topic(@_); } );
+ $cmdref->("reconnect", sub { $self->reconnect(@_); } );
+
+ $cmdref->("ignore", sub { $self->ignore(@_); } );
+ $cmdref->("don't ignore", sub { $self->do_not_ignore(@_); } );
+ $cmdref->("who are you ignoring?", sub { $self->dump_ignore(@_); } );
+
+ return $self;
+}
+
+sub is_admin {
+ my $who = shift;
+ 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";
+ }
+ return $is_admin;
+}
+
+sub nick {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: nick <new nick>" unless @arguments == 1;
+
+ $irc->yield(nick => $arguments[0]);
+}
+
+sub say {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: say <channel> <msg>" unless @arguments >= 2;
+
+ # Strip nick/channel from message
+ $rest =~ s/^(.*?\s)//;
+
+ $irc->yield(privmsg => $arguments[0] => $rest);
+}
+
+sub action {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: action <channel> <action text>" unless @arguments >= 2;
+
+ # Strip nick/channel from message
+ $rest =~ s/^(.*?\s)//;
+
+ $irc->yield(ctcp => $arguments[0] => "ACTION $rest");
+}
+
+sub join_channel {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: join <channel1> [channel2 ...]" unless @arguments >= 1;
+
+ $irc->yield(join => $_) for @arguments;
+}
+
+sub part {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: part <channel1> [channel2 ...] [partmsg]" unless @arguments >= 1;
+
+ my $nick = (split /!/, $who)[0];
+ my ($chan_str, $reason) = split /\s+(?!#)/, $rest, 2;
+ my @channels = split /\s+/, $chan_str;
+ $reason = "Commanded by $nick" unless $reason;
+ $irc->yield(part => @channels => $reason);
+}
+
+sub mode {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: mode <everything>" unless @arguments > 0;
+
+ # FIXME should use $where if it's a channel (?)
+ $irc->yield(mode => $rest);
+}
+
+sub kick {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: kick <channel> <nick> [reason]" unless @arguments >= 2;
+
+ # FIXME should use $where if it's a channel (?)
+ my ($channel, $kickee, undef, $reason) = $rest =~ /^(\S+)\s(\S+)((?:\s)(.*))?$/;
+ if ($channel and $kickee) {
+ my $nick = (split /!/, $who)[0];
+ $reason = "Requested by $nick" unless $reason;
+ $irc->yield(kick => $channel => $kickee => $reason);
+ }
+}
+
+sub topic {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: topic <new topic>" unless @arguments >= 2;
+
+ # Strip nick/channel from message
+ $rest =~ s/^(.*?\s)//;
+
+ # FIXME use $where if it's a channel
+ $irc->yield(topic => $arguments[0] => $rest);
+}
+
+sub reconnect {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+
+ my $reason = $rest;
+ $irc->yield(quit => $reason);
+}
+
+sub ignore {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: ignore <nick>" unless @arguments == 1;
+
+ push @{$config{ignore}}, $arguments[0];
+
+ return "Ignoring $arguments[0]";
+}
+
+sub do_not_ignore {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return unless is_admin($who);
+ return "Syntax: don't ignore <nick>" unless @arguments == 1;
+
+ my $target = $arguments[0];
+
+ 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.";
+ }
+}
+
+sub dump_ignore {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+
+ return "Syntax: who are you ignoring?" unless @arguments == 0;
+
+ # FIXME special case for empty ignore
+ return "I am ignoring: " . join ", ", @{$config{ignore}};
+}
+
+
+1;
diff --git a/Plugin/Echo.pm b/Plugin/Echo.pm
index 9b23af8..5f2c53a 100644
--- a/Plugin/Echo.pm
+++ b/Plugin/Echo.pm
@@ -19,7 +19,7 @@ sub configure {
}
sub echo {
- my ($self, $logger, $who, $where, $rest, @arguments) = @_;
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
return $rest;
}
diff --git a/Plugin/Map.pm b/Plugin/Map.pm
index 9ca8cef..4bd65a6 100644
--- a/Plugin/Map.pm
+++ b/Plugin/Map.pm
@@ -22,7 +22,7 @@ sub configure {
}
sub map {
- my ($self, $logger, $who, $where, $rest, @arguments) = @_;
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
my ($command, $subjects) = ($rest =~ /^(.+?)\s+(.*)$/);
return "[]" unless $subjects;
diff --git a/Plugin/Ping.pm b/Plugin/Ping.pm
index d935512..de6fd8e 100644
--- a/Plugin/Ping.pm
+++ b/Plugin/Ping.pm
@@ -17,7 +17,7 @@ sub configure {
}
sub ping {
- my ($self, $logger, $who, $where, $rest, @arguments) = @_;
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
my $nick = (split /!/, $who)[0];
return "$nick: pong";
}
diff --git a/Plugin/Source.pm b/Plugin/Source.pm
new file mode 100644
index 0000000..940fc2f
--- /dev/null
+++ b/Plugin/Source.pm
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+package Plugin::Source;
+
+use strict;
+use warnings;
+
+my %config;
+
+sub configure {
+ my $self = shift;
+ my $cmdref = shift;
+ my @source_commands = ("guts", "help", "source");
+ $cmdref->($_, sub { $self->source(@_); }) for @source_commands;
+ return $self;
+}
+
+sub source {
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
+ my @urls = (
+ "https://git.nah.nz/idalius/",
+ "https://gitlab.com/dphillips/idalius");
+ my $help_message = "My guts can be browsed at: ";
+ return $help_message . join " ", @urls;
+}
+1;
diff --git a/Plugin/Timezone.pm b/Plugin/Timezone.pm
index a536ed6..eb953a1 100644
--- a/Plugin/Timezone.pm
+++ b/Plugin/Timezone.pm
@@ -21,7 +21,7 @@ sub configure {
}
sub time {
- my ($self, $logger, $who, $where, $rest, @arguments) = @_;
+ my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_;
my $requester = (split /!/, $who)[0];
my @known_zones = (keys %{$config{timezone}});