3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-05 03:29:33 +01:00
pbot/lib/PBot/Plugin/Example.pm

39 lines
997 B
Perl
Raw Normal View History

2021-06-19 06:23:34 +02:00
# File: Example.pm
#
# Purpose: Example plugin boilerplate.
2021-07-11 00:00:22 +02:00
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
2021-07-14 04:45:56 +02:00
package PBot::Plugin::Example;
use parent 'PBot::Plugin::Base';
2021-06-19 06:23:34 +02:00
use PBot::Imports;
sub initialize {
2020-02-15 23:38:32 +01:00
my ($self, %conf) = @_;
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
}
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');
}
sub on_public {
2020-02-15 23:38:32 +01:00
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 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");
return 0;
}
2020-02-15 23:38:32 +01:00
$self->{pbot}->{logger}->log("Example plugin: got message from $nick!$user\@$host: $msg\n");
return 0;
}
1;