mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 23:39:24 +01:00
Add some comments about priority levels
This commit is contained in:
parent
354f278cb2
commit
9890ca99ee
@ -22,6 +22,14 @@ sub initialize {
|
||||
}
|
||||
|
||||
# add an event handler
|
||||
#
|
||||
# priority ranges from 0 to 100. 0 is the highest priority, i.e. an handler with
|
||||
# priority 0 will handle events first. 100 is the lowest priority and will handle
|
||||
# events last. priority defaults to 50 if ommited.
|
||||
#
|
||||
# NickList reserves 0 and 100 to ensure its list is populated by JOINs, etc,
|
||||
# before any handlers need to consult its list, or depopulated by PARTs, QUITs,
|
||||
# KICKs, etc, after any other handlers need to consult its list.
|
||||
sub register_handler {
|
||||
my ($self, $event_name, $subref, $priority) = @_;
|
||||
|
||||
@ -108,13 +116,13 @@ sub dispatch_event {
|
||||
# that it decided not to handle this event.
|
||||
my $handler_result = eval { $handler->{subref}->($event_name, $event_data) };
|
||||
|
||||
# update $dispatch_result only when handler result is a defined
|
||||
# value so we remember if any handlers have handled this event.
|
||||
$dispatch_result = $handler_result if defined $handler_result;
|
||||
|
||||
# check for exception
|
||||
if (my $exception = $@) {
|
||||
$self->{pbot}->{logger}->log("Exception in event handler: $exception");
|
||||
} else {
|
||||
# update $dispatch_result only when handler result is a defined
|
||||
# value so we remember if any handlers have handled this event.
|
||||
$dispatch_result = $handler_result if defined $handler_result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,19 +34,26 @@ sub initialize {
|
||||
$self->{pbot}->{commands}->register(sub { $self->cmd_nicklist(@_) }, "nicklist", 1);
|
||||
|
||||
# handlers for various IRC events
|
||||
|
||||
# TODO: track mode changes to update user flags
|
||||
# Update: turns out that IRCHandler's on_mode() is doing this already -- we need to make that
|
||||
# emit a mode-change event or some such and register a handler for it here.
|
||||
|
||||
# lowest priority so these get handled by NickList before any other handlers
|
||||
# (all other handlers should be given a priority > 0)
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.namreply', sub { $self->on_namreply(@_) }, 0 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.join', sub { $self->on_join(@_) }, 0 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_activity(@_) }, 0 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_activity(@_) }, 0 );
|
||||
|
||||
# highest priority so these get handled by NickList after all other handlers
|
||||
# (all other handlers should be given a priority < 100)
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_part(@_) }, 100 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.quit', sub { $self->on_quit(@_) }, 100 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) }, 100 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.nick', sub { $self->on_nickchange(@_) }, 100 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_activity(@_) }, 0 );
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_activity(@_) }, 0 );
|
||||
|
||||
# handlers for the bot itself joining/leaving channels
|
||||
# handlers for the bot itself joining/leaving channels (lowest priority)
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('pbot.join', sub { $self->on_self_join(@_) }, 0);
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('pbot.part', sub { $self->on_self_part(@_) }, 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user