From 9fada0f82c77dd64a8d233b61c2819dcb774243c Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 22 Oct 2025 21:38:37 -0700 Subject: [PATCH] Plugin/Example: add more examples --- lib/PBot/Plugin/Example.pm | 24 +++++++++++++++++++++++- lib/PBot/VERSION.pm | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/PBot/Plugin/Example.pm b/lib/PBot/Plugin/Example.pm index ba499d9f..63744e9c 100644 --- a/lib/PBot/Plugin/Example.pm +++ b/lib/PBot/Plugin/Example.pm @@ -2,7 +2,7 @@ # # Purpose: Example plugin boilerplate. -# SPDX-FileCopyrightText: 2015-2023 Pragmatic Software +# SPDX-FileCopyrightText: 2015-2025 Pragmatic Software # 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; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 1237030a..227c3eb1 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -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", };