2021-06-22 02:26:24 +02:00
|
|
|
# File: EventQueue.pm
|
2010-03-22 08:33:44 +01:00
|
|
|
#
|
2021-06-22 02:26:24 +02:00
|
|
|
# Purpose: Provides functionality to manage event subroutines which are invoked
|
2020-03-06 22:21:44 +01:00
|
|
|
# at a future time, optionally recurring.
|
2010-03-22 08:33:44 +01:00
|
|
|
#
|
2021-06-22 02:26:24 +02:00
|
|
|
# Note: PBot::EventQueue has no relation to PBot::EventDispatcher.
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
package PBot::EventQueue;
|
2020-02-08 20:04:13 +01:00
|
|
|
use parent 'PBot::Class';
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2021-06-19 06:23:34 +02:00
|
|
|
use PBot::Imports;
|
2019-07-11 03:40:53 +02:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
use Time::HiRes qw/time/;
|
|
|
|
use Time::Duration;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-02-08 20:04:13 +01:00
|
|
|
sub initialize {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, %conf) = @_;
|
2021-06-22 02:26:24 +02:00
|
|
|
|
|
|
|
# array of pending events
|
2020-03-06 22:21:44 +01:00
|
|
|
$self->{event_queue} = [];
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# register `eventqueue` bot command
|
|
|
|
$self->{pbot}->{commands}->register(sub { $self->cmd_eventqueue(@_) }, 'eventqueue', 1);
|
2020-03-06 22:21:44 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# add `can-eventqueue` capability to admin group
|
|
|
|
$self->{pbot}->{capabilities}->add('admin', 'can-eventqueue', 1);
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 23:02:51 +02:00
|
|
|
# eventqueue bot command
|
2020-05-04 22:21:35 +02:00
|
|
|
sub cmd_eventqueue {
|
|
|
|
my ($self, $context) = @_;
|
2020-03-06 22:21:44 +01:00
|
|
|
|
2021-06-22 22:56:15 +02:00
|
|
|
my $usage = "Usage: eventqueue list [filter regex] | add <relative time> <command> [-repeat] | remove <regex>";
|
2020-03-06 22:21:44 +01:00
|
|
|
|
2020-05-02 05:59:51 +02:00
|
|
|
my $command = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
|
2020-03-09 00:05:37 +01:00
|
|
|
|
|
|
|
if (not defined $command) {
|
|
|
|
return $usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($command eq 'list') {
|
|
|
|
return "No events queued." if not @{$self->{event_queue}};
|
|
|
|
|
|
|
|
my $result = eval {
|
|
|
|
my $text = "Queued events:\n";
|
2021-06-22 02:26:24 +02:00
|
|
|
|
2020-05-02 05:59:51 +02:00
|
|
|
my ($regex) = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
|
2020-03-09 00:05:37 +01:00
|
|
|
|
|
|
|
my $i = 0;
|
2020-04-06 05:33:14 +02:00
|
|
|
my $events = 0;
|
2020-03-09 00:05:37 +01:00
|
|
|
foreach my $event (@{$self->{event_queue}}) {
|
|
|
|
$i++;
|
2020-03-07 05:23:17 +01:00
|
|
|
|
2020-03-09 00:05:37 +01:00
|
|
|
if ($regex) {
|
2020-04-06 05:33:14 +02:00
|
|
|
next unless $event->{id} =~ /$regex/i;
|
2020-03-09 00:05:37 +01:00
|
|
|
}
|
2020-03-07 05:23:17 +01:00
|
|
|
|
2020-04-06 05:33:14 +02:00
|
|
|
$events++;
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
my $duration = $event->{timeout} - time;
|
|
|
|
|
|
|
|
if ($duration < 0) {
|
|
|
|
# current time has passed an event's time but the
|
|
|
|
# event hasn't left the queue yet. we'll show these
|
|
|
|
# as, e.g., "pending 5s ago"
|
|
|
|
$duration = 'pending ' . concise ago -$duration;
|
|
|
|
} else {
|
|
|
|
$duration = 'in ' . concise duration $duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
$text .= " $i) $duration: $event->{id}";
|
2020-03-09 00:05:37 +01:00
|
|
|
$text .= ' [R]' if $event->{repeating};
|
|
|
|
$text .= ";\n";
|
2020-03-07 05:23:17 +01:00
|
|
|
}
|
2020-03-06 22:21:44 +01:00
|
|
|
|
2020-04-06 05:33:14 +02:00
|
|
|
return "No events found." if $events == 0;
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
return $text . "$events events.\n";
|
2020-03-09 00:05:37 +01:00
|
|
|
};
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
if (my $error = $@) {
|
|
|
|
# strip source information to prettify error for non-developer consumption
|
2020-03-09 00:05:37 +01:00
|
|
|
$error =~ s/ at PBot.*//;
|
|
|
|
return "Bad regex: $error";
|
2020-03-07 05:23:17 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 00:05:37 +01:00
|
|
|
return $result;
|
|
|
|
}
|
2020-03-07 05:23:17 +01:00
|
|
|
|
2020-03-09 00:05:37 +01:00
|
|
|
if ($command eq 'add') {
|
2020-05-02 05:59:51 +02:00
|
|
|
my ($duration, $command) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
|
2020-03-09 00:05:37 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
if (not defined $duration or not defined $command) {
|
|
|
|
return "Usage: eventqueue add <relative time> <command> [-repeat]";
|
|
|
|
}
|
|
|
|
|
|
|
|
# convert text like "5 minutes" or "1 week" or "next tuesday" to seconds
|
|
|
|
my ($seconds, $error) = $self->{pbot}->{parsedate}->parsedate($duration);
|
2020-03-09 00:05:37 +01:00
|
|
|
return $error if defined $error;
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# check for `-repeating` at front or end of command
|
|
|
|
my $repeating = $command =~ s/^-repeat\s+|\s+-repeat$//g;
|
2020-03-09 23:24:47 +01:00
|
|
|
|
2020-03-09 00:05:37 +01:00
|
|
|
my $cmd = {
|
2021-06-22 02:26:24 +02:00
|
|
|
nick => $context->{nick},
|
|
|
|
user => $context->{user},
|
|
|
|
host => $context->{host},
|
|
|
|
hostmask => $context->{hostmask},
|
|
|
|
command => $command,
|
2020-03-09 00:05:37 +01:00
|
|
|
};
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
$self->{pbot}->{interpreter}->add_to_command_queue($context->{from}, $cmd, $seconds, $repeating);
|
|
|
|
|
2020-03-09 00:05:37 +01:00
|
|
|
return "Command added to event queue.";
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 00:05:37 +01:00
|
|
|
if ($command eq 'remove') {
|
2020-05-02 05:59:51 +02:00
|
|
|
my ($regex) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 1);
|
2021-06-22 22:56:15 +02:00
|
|
|
return "Usage: eventqueue remove <regex>" if not defined $regex;
|
|
|
|
$regex =~ s/(?<!\.)\*/.*?/g;
|
2020-03-09 00:05:37 +01:00
|
|
|
return $self->dequeue_event($regex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown command '$command'. $usage";
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 22:21:44 +01:00
|
|
|
sub find_enqueue_position {
|
2021-06-22 02:26:24 +02:00
|
|
|
my ($self, $time) = @_;
|
2020-02-15 23:38:32 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# no events in queue yet, early-return first position
|
2020-03-06 22:21:44 +01:00
|
|
|
return 0 if not @{$self->{event_queue}};
|
2020-02-15 23:38:32 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# early-return first position if event's time is less
|
|
|
|
# than first position's
|
|
|
|
if ($time < $self->{event_queue}->[0]->{timeout}) {
|
2020-03-06 22:21:44 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-02-15 23:38:32 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# early-return last position if event's time is greater
|
|
|
|
if ($time > $self->{event_queue}->[@{$self->{event_queue}} - 1]->{timeout}) {
|
2020-03-06 22:21:44 +01:00
|
|
|
return scalar @{$self->{event_queue}};
|
|
|
|
}
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# binary search to find enqueue position
|
|
|
|
|
2020-03-06 22:21:44 +01:00
|
|
|
my $lo = 0;
|
|
|
|
my $hi = scalar @{$self->{event_queue}} - 1;
|
|
|
|
|
|
|
|
while ($lo <= $hi) {
|
|
|
|
my $mid = int (($hi + $lo) / 2);
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
if ($time < $self->{event_queue}->[$mid]->{timeout}) {
|
2020-03-06 22:21:44 +01:00
|
|
|
$hi = $mid - 1;
|
2021-06-22 02:26:24 +02:00
|
|
|
} elsif ($time > $self->{event_queue}->[$mid]->{timeout}) {
|
2020-03-06 22:21:44 +01:00
|
|
|
$lo = $mid + 1;
|
|
|
|
} else {
|
2021-06-22 02:26:24 +02:00
|
|
|
while ($mid < @{$self->{event_queue}} and $self->{event_queue}->[$mid]->{timeout} == $time) {
|
|
|
|
# found a slot with the same time. we "slide" down the array
|
|
|
|
# to append this event to the end of this region of same-times.
|
2020-03-07 05:23:17 +01:00
|
|
|
$mid++;
|
|
|
|
}
|
2020-03-06 22:21:44 +01:00
|
|
|
return $mid;
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 22:21:44 +01:00
|
|
|
return $lo;
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:54:10 +02:00
|
|
|
sub replace_subref_or_enqueue_event {
|
2021-06-22 02:26:24 +02:00
|
|
|
my ($self, $subref, $interval, $id, $repeating) = @_;
|
2020-05-15 01:54:10 +02:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# find events matching id
|
2020-05-15 01:54:10 +02:00
|
|
|
my @events = grep { $_->{id} eq $id } @{$self->{event_queue}};
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# no events found, enqueue new event
|
2020-05-15 01:54:10 +02:00
|
|
|
if (not @events) {
|
2021-06-22 02:26:24 +02:00
|
|
|
$self->enqueue_event($subref, $interval, $id, $repeating);
|
2020-05-15 01:54:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# otherwise update existing events
|
2020-05-15 01:54:10 +02:00
|
|
|
foreach my $event (@events) {
|
2021-06-22 02:26:24 +02:00
|
|
|
$event->{subref} = $subref;
|
2020-05-15 01:54:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub replace_or_enqueue_event {
|
2021-06-22 02:26:24 +02:00
|
|
|
my ($self, $subref, $interval, $id, $repeating) = @_;
|
|
|
|
|
|
|
|
# remove event if it exists
|
2020-05-15 01:54:10 +02:00
|
|
|
$self->dequeue_event($id) if $self->exists($id);
|
2021-06-22 02:26:24 +02:00
|
|
|
|
|
|
|
# enqueue new event
|
|
|
|
$self->enqueue_event($subref, $interval, $id, $repeating);
|
2020-05-15 01:54:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub enqueue_event_unless_exists {
|
2021-06-22 02:26:24 +02:00
|
|
|
my ($self, $subref, $interval, $id, $repeating) = @_;
|
|
|
|
|
|
|
|
# event already exists, bail out
|
2020-05-15 01:54:10 +02:00
|
|
|
return if $self->exists($id);
|
2021-06-22 02:26:24 +02:00
|
|
|
|
|
|
|
# enqueue new event
|
|
|
|
$self->enqueue_event($subref, $interval, $id, $repeating);
|
2020-05-15 01:54:10 +02:00
|
|
|
}
|
|
|
|
|
2021-06-22 23:02:51 +02:00
|
|
|
# adds an event to the event queue
|
2020-03-06 22:21:44 +01:00
|
|
|
sub enqueue_event {
|
2021-06-22 02:26:24 +02:00
|
|
|
my ($self, $subref, $interval, $id, $repeating) = @_;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
$id //= 'an event';
|
2021-06-21 00:10:16 +02:00
|
|
|
$repeating //= 0;
|
|
|
|
$interval //= 0;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-03-06 22:21:44 +01:00
|
|
|
my $event = {
|
|
|
|
id => $id,
|
2021-06-22 02:26:24 +02:00
|
|
|
subref => $subref,
|
2020-03-06 22:21:44 +01:00
|
|
|
interval => $interval,
|
2021-06-22 02:26:24 +02:00
|
|
|
timeout => time + $interval,
|
2020-03-06 22:21:44 +01:00
|
|
|
repeating => $repeating,
|
|
|
|
};
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-03-06 22:21:44 +01:00
|
|
|
my $i = $self->find_enqueue_position($event->{timeout});
|
|
|
|
splice @{$self->{event_queue}}, $i, 0, $event;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
my $debug = $self->{pbot}->{registry}->get_value('eventqueue', 'debug') // 0;
|
2020-03-06 22:21:44 +01:00
|
|
|
if ($debug > 1) {
|
2021-06-22 02:26:24 +02:00
|
|
|
$self->{pbot}->{logger}->log("Enqueued new event $id at position $i: timeout=$event->{timeout} interval=$interval repeating=$repeating\n");
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2021-06-22 23:02:51 +02:00
|
|
|
# removes an event from the event queue, optionally invoking it.
|
|
|
|
# `id` can contain `.*` and `.*?` for wildcard-matching/globbing.
|
2020-03-06 22:21:44 +01:00
|
|
|
sub dequeue_event {
|
2020-05-15 01:54:10 +02:00
|
|
|
my ($self, $id, $execute) = @_;
|
2020-03-06 22:21:44 +01:00
|
|
|
|
2020-03-09 00:05:37 +01:00
|
|
|
my $result = eval {
|
2020-03-06 22:21:44 +01:00
|
|
|
$id = quotemeta $id;
|
|
|
|
$id =~ s/\\\.\\\*\\\?/.*?/g;
|
|
|
|
$id =~ s/\\\.\\\*/.*/g;
|
2020-04-06 05:33:14 +02:00
|
|
|
my $regex = qr/^$id$/i;
|
2020-03-09 00:05:37 +01:00
|
|
|
my $count = @{$self->{event_queue}};
|
2020-04-25 02:28:27 +02:00
|
|
|
my @removed = grep { $_->{id} =~ /$regex/i; } @{$self->{event_queue}};
|
2020-03-06 22:21:44 +01:00
|
|
|
@{$self->{event_queue}} = grep { $_->{id} !~ /$regex/i; } @{$self->{event_queue}};
|
2020-04-25 02:28:27 +02:00
|
|
|
$count -= @{$self->{event_queue}};
|
2020-05-15 01:54:10 +02:00
|
|
|
|
|
|
|
if ($execute) {
|
|
|
|
foreach my $event (@removed) {
|
|
|
|
$event->{subref}->($event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 02:28:27 +02:00
|
|
|
return "No matching events." if not $count;
|
|
|
|
return "Removed $count event" . ($count == 1 ? '' : 's') . ': ' . join(', ', map { $_->{id} } @removed);
|
2020-03-06 22:21:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if ($@) {
|
2020-03-09 00:05:37 +01:00
|
|
|
my $error = $@;
|
|
|
|
$self->{pbot}->{logger}->log("Error in dequeue_event: $error\n");
|
|
|
|
$error =~ s/ at PBot.*//;
|
|
|
|
return "$error";
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
2020-03-09 00:05:37 +01:00
|
|
|
|
|
|
|
return $result;
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 23:02:51 +02:00
|
|
|
# invoke and remove all events matching `id`, which can
|
|
|
|
# contain `.*` and `.*?` for wildcard-matching/globbing
|
2020-05-15 01:54:10 +02:00
|
|
|
sub execute_and_dequeue_event {
|
|
|
|
my ($self, $id) = @_;
|
|
|
|
return $self->dequeue_event($id, 1);
|
|
|
|
}
|
|
|
|
|
2021-06-22 23:02:51 +02:00
|
|
|
# adds an event, with repeating defaulted to enabled
|
2021-06-22 02:26:24 +02:00
|
|
|
sub enqueue {
|
|
|
|
my ($self, $subref, $interval, $id, $repeating) = @_;
|
|
|
|
$repeating //= 1;
|
|
|
|
$self->enqueue_event($subref, $interval, $id, $repeating);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 23:02:51 +02:00
|
|
|
# alias to dequeue_event, for consistency
|
2021-06-22 02:26:24 +02:00
|
|
|
sub dequeue {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, $id) = @_;
|
2020-03-06 22:21:44 +01:00
|
|
|
$self->dequeue_event($id);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2020-05-15 01:54:10 +02:00
|
|
|
sub exists {
|
|
|
|
my ($self, $id) = @_;
|
|
|
|
return scalar grep { $_->{id} eq $id } @{$self->{event_queue}};
|
|
|
|
}
|
|
|
|
|
2020-03-07 05:23:17 +01:00
|
|
|
sub update_repeating {
|
|
|
|
my ($self, $id, $repeating) = @_;
|
|
|
|
|
|
|
|
for (my $i = 0; $i < @{$self->{event_queue}}; $i++) {
|
|
|
|
if ($self->{event_queue}->[$i]->{id} eq $id) {
|
|
|
|
$self->{event_queue}->[$i]->{repeating} = $repeating;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-19 12:30:25 +02:00
|
|
|
sub update_interval {
|
2020-03-06 22:21:44 +01:00
|
|
|
my ($self, $id, $interval, $dont_enqueue) = @_;
|
2010-03-22 08:33:44 +01:00
|
|
|
|
2020-03-06 22:21:44 +01:00
|
|
|
for (my $i = 0; $i < @{$self->{event_queue}}; $i++) {
|
|
|
|
if ($self->{event_queue}->[$i]->{id} eq $id) {
|
|
|
|
if ($dont_enqueue) {
|
2021-06-22 02:26:24 +02:00
|
|
|
# update interval in-place without moving event to new place in queue
|
|
|
|
# (allows event to fire at expected time, then updates to new timeout afterwards)
|
2020-03-06 22:21:44 +01:00
|
|
|
$self->{event_queue}->[$i]->{interval} = $interval;
|
|
|
|
} else {
|
2021-06-22 02:26:24 +02:00
|
|
|
# remove and add event in new position in queue
|
2020-03-06 22:21:44 +01:00
|
|
|
my $event = splice(@{$self->{event_queue}}, $i, 1);
|
|
|
|
$self->enqueue_event($event->{subref}, $interval, $id, $event->{repeating});
|
|
|
|
}
|
2020-02-15 23:38:32 +01:00
|
|
|
last;
|
|
|
|
}
|
2014-05-19 12:30:25 +02:00
|
|
|
}
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
sub duration_until_next_event {
|
|
|
|
my ($self) = @_;
|
|
|
|
return 0 if not @{$self->{event_queue}};
|
|
|
|
return $self->{event_queue}->[0]->{timeout} - time;
|
2020-03-07 05:23:17 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 02:40:36 +02:00
|
|
|
# invokes the current events and then returns seconds until next upcoming event
|
|
|
|
sub do_events {
|
2020-03-06 22:21:44 +01:00
|
|
|
my ($self) = @_;
|
2020-03-07 05:23:17 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# early-return if no events available
|
|
|
|
return 0 if not @{$self->{event_queue}};
|
2020-03-06 22:21:44 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
my $debug = $self->{pbot}->{registry}->get_value('eventqueue', 'debug') // 0;
|
2020-03-09 03:15:15 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# repeating events to re-enqueue
|
|
|
|
my @enqueue;
|
|
|
|
|
|
|
|
for (my $i = 0; $i < @{$self->{event_queue}}; $i++) {
|
|
|
|
# we call time for a fresh time, instead of using a stale $now that
|
|
|
|
# could be well in the past depending on a previous event's duration
|
|
|
|
if (time >= $self->{event_queue}->[$i]->{timeout}) {
|
|
|
|
my $event = $self->{event_queue}->[$i];
|
|
|
|
|
|
|
|
$self->{pbot}->{logger}->log("Processing event $i: $event->{id}\n") if $debug > 1;
|
|
|
|
|
|
|
|
# call event's subref, passing event as argument
|
|
|
|
$event->{subref}->($event);
|
|
|
|
|
|
|
|
# remove event from queue
|
|
|
|
splice @{$self->{event_queue}}, $i--, 1;
|
|
|
|
|
|
|
|
# add event to re-enqueue queue if repeating
|
|
|
|
push @enqueue, $event if $event->{repeating};
|
|
|
|
} else {
|
|
|
|
# no more events ready at this time
|
|
|
|
if ($debug > 2) {
|
|
|
|
$self->{pbot}->{logger}->log("Event not ready yet: $self->{event_queue}->[$i]->{id} (timeout=$self->{event_queue}->[$i]->{timeout})\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
last;
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
2021-06-22 02:26:24 +02:00
|
|
|
}
|
2020-03-07 05:23:17 +01:00
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
# re-enqueue repeating events
|
|
|
|
foreach my $event (@enqueue) {
|
|
|
|
$self->enqueue_event($event->{subref}, $event->{interval}, $event->{id}, 1);
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 02:26:24 +02:00
|
|
|
return $self->duration_until_next_event;
|
2020-03-06 22:21:44 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
1;
|