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