1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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} || "(unknown)";
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;
|