diff options
author | David Phillips <david@sighup.nz> | 2019-07-12 21:14:58 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2019-07-12 23:19:11 +1200 |
commit | a22d539075597a686f04a79d960c2047c83ab389 (patch) | |
tree | 88bd681ad3200a20a1e173f8b39da27212b8e283 /Plugin/Topic.pm | |
parent | c757da74b4131562f23d7b5275aaf981891fe882 (diff) | |
download | idalius-a22d539075597a686f04a79d960c2047c83ab389.tar.xz |
Topic: Add topic reporting plugin
Diffstat (limited to 'Plugin/Topic.pm')
-rw-r--r-- | Plugin/Topic.pm | 44 |
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; |