mirror of
https://github.com/pragma-/pbot.git
synced 2025-11-13 21:17:30 +01:00
Plugin/Example: add more examples
This commit is contained in:
parent
2f958ccf80
commit
9fada0f82c
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Purpose: Example plugin boilerplate.
|
# 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
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package PBot::Plugin::Example;
|
package PBot::Plugin::Example;
|
||||||
@ -11,15 +11,28 @@ use parent 'PBot::Plugin::Base';
|
|||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
sub initialize($self, %conf) {
|
sub initialize($self, %conf) {
|
||||||
|
# an event handler
|
||||||
$self->{pbot}->{event_dispatcher}->register_handler(
|
$self->{pbot}->{event_dispatcher}->register_handler(
|
||||||
'irc.public',
|
'irc.public',
|
||||||
sub { $self->on_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) {
|
sub unload($self) {
|
||||||
# perform plugin clean-up here
|
# perform plugin clean-up here
|
||||||
|
$self->{pbot}->{commands}->remove('thing');
|
||||||
$self->{pbot}->{event_dispatcher}->remove_handler('irc.public');
|
$self->{pbot}->{event_dispatcher}->remove_handler('irc.public');
|
||||||
|
$self->{pbot}->{event_queue}->dequeue('Recurring event');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub on_public($self, $event_type, $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
|
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;
|
1;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4921,
|
BUILD_REVISION => 4922,
|
||||||
BUILD_DATE => "2025-10-22",
|
BUILD_DATE => "2025-10-22",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user