2017-03-05 21:33:31 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2015-09-06 22:17:07 -07:00
|
|
|
|
2019-12-21 15:26:01 -08:00
|
|
|
package Plugins::Example;
|
2015-09-06 22:17:07 -07:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2019-07-10 18:40:53 -07:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
|
2015-09-06 22:17:07 -07:00
|
|
|
use Carp ();
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
|
|
|
|
my ($class, %conf) = @_;
|
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
2020-02-06 01:14:08 -08:00
|
|
|
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
2020-02-03 17:19:04 -08:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
|
2015-09-06 22:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
sub unload {
|
|
|
|
my $self = shift;
|
|
|
|
# perform plugin clean-up here
|
|
|
|
# normally we'd unregister the 'irc.public' event handler; however, the
|
|
|
|
# event dispatcher will do this automatically for us when it sees there
|
|
|
|
# is no longer an existing sub.
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_public {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args);
|
2019-06-26 09:34:19 -07:00
|
|
|
|
2015-09-08 01:37:59 -07:00
|
|
|
if ($event->{interpreted}) {
|
|
|
|
$self->{pbot}->{logger}->log("Message was already handled by the interpreter.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-21 15:26:01 -08:00
|
|
|
$self->{pbot}->{logger}->log("Example plugin: got message from $nick!$user\@$host: $msg\n");
|
2015-09-06 22:17:07 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|