2021-06-18 21:23:34 -07:00
|
|
|
# File: Example.pm
|
|
|
|
#
|
|
|
|
# Purpose: Example plugin boilerplate.
|
|
|
|
|
2023-02-20 21:31:52 -08:00
|
|
|
# SPDX-FileCopyrightText: 2015-2023 Pragmatic Software <pragma78@gmail.com>
|
2021-07-10 15:00:22 -07:00
|
|
|
# SPDX-License-Identifier: MIT
|
2015-09-06 22:17:07 -07:00
|
|
|
|
2021-07-13 19:45:56 -07:00
|
|
|
package PBot::Plugin::Example;
|
|
|
|
use parent 'PBot::Plugin::Base';
|
2015-09-06 22:17:07 -07:00
|
|
|
|
2021-06-18 21:23:34 -07:00
|
|
|
use PBot::Imports;
|
2015-09-06 22:17:07 -07:00
|
|
|
|
2023-04-13 17:01:23 -07:00
|
|
|
sub initialize($self, %conf) {
|
2023-01-31 05:44:34 -08:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler(
|
|
|
|
'irc.public',
|
|
|
|
sub { $self->on_public(@_) },
|
|
|
|
);
|
2015-09-06 22:17:07 -07:00
|
|
|
}
|
|
|
|
|
2023-04-13 17:01:23 -07:00
|
|
|
sub unload($self) {
|
2020-02-15 14:38:32 -08:00
|
|
|
# perform plugin clean-up here
|
|
|
|
$self->{pbot}->{event_dispatcher}->remove_handler('irc.public');
|
2015-09-06 22:17:07 -07:00
|
|
|
}
|
|
|
|
|
2023-04-13 17:01:23 -07:00
|
|
|
sub on_public($self, $event_type, $event) {
|
2023-01-31 05:44:34 -08:00
|
|
|
my ($nick, $user, $host, $msg) = (
|
|
|
|
$event->nick,
|
|
|
|
$event->user,
|
|
|
|
$event->host,
|
|
|
|
$event->args,
|
|
|
|
);
|
2019-06-26 09:34:19 -07:00
|
|
|
|
2020-02-15 14:38:32 -08:00
|
|
|
if ($event->{interpreted}) {
|
|
|
|
$self->{pbot}->{logger}->log("Message was already handled by the interpreter.\n");
|
2023-01-31 05:44:34 -08:00
|
|
|
return 0; # event not handled by plugin
|
2020-02-15 14:38:32 -08:00
|
|
|
}
|
2015-09-08 01:37:59 -07:00
|
|
|
|
2020-02-15 14:38:32 -08:00
|
|
|
$self->{pbot}->{logger}->log("Example plugin: got message from $nick!$user\@$host: $msg\n");
|
2023-01-31 05:44:34 -08:00
|
|
|
return 1; # event handled by plugin
|
2015-09-06 22:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|