aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Topic.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Plugin/Topic.pm')
-rw-r--r--Plugin/Topic.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/Plugin/Topic.pm b/Plugin/Topic.pm
new file mode 100644
index 0000000..ce3c782
--- /dev/null
+++ b/Plugin/Topic.pm
@@ -0,0 +1,44 @@
+package Plugin::Topic;
+
+use strict;
+use warnings;
+
+my %channel_topics;
+
+sub configure {
+ my $self = shift;
+ my $cmdref = shift;
+ shift; # run_command
+
+ $cmdref->($self, "topic", sub { $self->topic(@_); } );
+
+ return $self;
+}
+
+sub topic {
+ my ($self, $irc, $logger, $who, $where, $ided, $rest, $no_reenter, @arguments) = @_;
+ $where = $where->[0] if ref($where) eq "ARRAY";
+
+ # use current channel unless one is specified
+ my $channel = @arguments ? $arguments[0] : $where;
+ return "Syntax: topic [channel]" unless $channel =~ m/^#.*$/;
+
+ my $topic = $channel_topics{$channel} || "(no topic)";
+ return "Topic for $channel: $topic";
+}
+
+sub on_topic {
+ my ($self, $logger, $who, $where, $topic, $irc) = @_;
+ $channel_topics{$where} = $topic;
+}
+
+sub on_331_rpl_notopic {
+ my ($self, $logger, $where, $irc) = @_;
+ delete $channel_topics{$where};
+}
+
+sub on_332_rpl_topic {
+ my ($self, $logger, $where, $topic, $irc) = @_;
+ $channel_topics{$where} = $topic;
+}
+1;