3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-10-24 12:07:33 +02:00

Plugin/Example: add more examples

This commit is contained in:
Pragmatic Software 2025-10-22 21:38:37 -07:00
parent 2f958ccf80
commit 9fada0f82c
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
2 changed files with 24 additions and 2 deletions

View File

@ -2,7 +2,7 @@
#
# Purpose: Example plugin boilerplate.
# SPDX-FileCopyrightText: 2015-2023 Pragmatic Software <pragma78@gmail.com>
# SPDX-FileCopyrightText: 2015-2025 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Plugin::Example;
@ -11,15 +11,28 @@ use parent 'PBot::Plugin::Base';
use PBot::Imports;
sub initialize($self, %conf) {
# an event handler
$self->{pbot}->{event_dispatcher}->register_handler(
'irc.public',
sub { $self->on_public(@_) },
);
# a command
$self->{pbot}->{commands}->add(
name => 'thing',
help => 'Does a thing!',
subref => sub { $self->cmd_thing(@_) },
);
# a recurring enqueued event
$self->{pbot}->{event_queue}->enqueue(sub { $self->recurring_event }, 60, 'Recurring event');
}
sub unload($self) {
# perform plugin clean-up here
$self->{pbot}->{commands}->remove('thing');
$self->{pbot}->{event_dispatcher}->remove_handler('irc.public');
$self->{pbot}->{event_queue}->dequeue('Recurring event');
}
sub on_public($self, $event_type, $event) {
@ -39,4 +52,13 @@ sub on_public($self, $event_type, $event) {
return 1; # event handled by plugin
}
sub cmd_thing($self, $context) {
my @args = $self->{pbot}->{interpreter}->split_line($context->{arguments});
# do some command with @args here
}
sub recurring_event($self) {
# do some event here
}
1;

View File

@ -25,7 +25,7 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4921,
BUILD_REVISION => 4922,
BUILD_DATE => "2025-10-22",
};