mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 05:49:27 +01:00
Rename irc.onemode
to irc.modeflag
- rename track_mode to on_modeflag - consistently return undef or 1 from handlers
This commit is contained in:
parent
108c2924cc
commit
f4dbb68221
@ -21,7 +21,7 @@ sub initialize {
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.quietlist', sub { $self->on_quietlist_entry(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.endofbanlist', sub { $self->compare_banlist(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.endofquietlist', sub { $self->compare_quietlist(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.onemode', sub { $self->track_mode(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.modeflag', sub { $self->on_modeflag(@_) });
|
||||
|
||||
$self->{mute_char} = $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char');
|
||||
}
|
||||
@ -44,7 +44,7 @@ sub get_banlist {
|
||||
$event->{conn}->sl("mode $channel +b$mute_char");
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_banlist_entry {
|
||||
@ -58,7 +58,7 @@ sub on_banlist_entry {
|
||||
my $ago = concise ago(gettimeofday - $timestamp);
|
||||
$self->{pbot}->{logger}->log("Ban List: [banlist entry] $channel: $target banned by $source $ago.\n");
|
||||
$self->{temp_banlist}->{$channel}->{'+b'}->{$target} = [$source, $timestamp];
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_quietlist_entry {
|
||||
@ -73,7 +73,7 @@ sub on_quietlist_entry {
|
||||
$self->{pbot}->{logger}->log("Ban List: [quietlist entry] $channel: $target quieted by $source $ago.\n");
|
||||
my $mute_char = $self->{mute_char};
|
||||
$self->{temp_banlist}->{$channel}->{"+$mute_char"}->{$target} = [$source, $timestamp];
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
# irc.endofbanlist
|
||||
@ -118,6 +118,7 @@ sub compare_banlist {
|
||||
|
||||
$self->{pbot}->{banlist}->{banlist}->save if keys %{$self->{temp_banlist}->{$channel}->{'+b'}};
|
||||
delete $self->{temp_banlist}->{$channel}->{'+b'};
|
||||
return 1;
|
||||
}
|
||||
|
||||
# irc.endofquietlist
|
||||
@ -147,10 +148,10 @@ sub compare_quietlist {
|
||||
|
||||
$self->{pbot}->{banlist}->{quietlist}->save if keys %{$self->{temp_banlist}->{$channel}->{"+$mute_char"}};
|
||||
delete $self->{temp_banlist}->{$channel}->{"+$mute_char"};
|
||||
return 1;
|
||||
}
|
||||
|
||||
# irc.onemode
|
||||
sub track_mode {
|
||||
sub on_modeflag {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
|
||||
my ($source, $channel, $mode, $mask) = (
|
||||
@ -254,6 +255,8 @@ sub track_mode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -15,9 +15,9 @@ use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('pbot.join', sub { $self->on_self_join(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('pbot.part', sub { $self->on_self_part(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.onemode', sub { $self->track_mode(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('pbot.join', sub { $self->on_self_join(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('pbot.part', sub { $self->on_self_part(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.modeflag', sub { $self->on_modeflag(@_) });
|
||||
}
|
||||
|
||||
sub on_self_join {
|
||||
@ -30,6 +30,8 @@ sub on_self_join {
|
||||
if ($self->{pbot}->{channels}->{storage}->get_data($channel, 'permop')) {
|
||||
$self->{pbot}->{chanops}->gain_ops($channel);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_self_part {
|
||||
@ -37,9 +39,10 @@ sub on_self_part {
|
||||
my $channel = $event->{channel};
|
||||
delete $self->{pbot}->{chanops}->{is_opped}->{$channel};
|
||||
delete $self->{pbot}->{chanops}->{op_requested}->{$channel};
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub track_mode {
|
||||
sub on_modeflag {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
|
||||
my ($source, $channel, $mode, $target) = (
|
||||
@ -73,6 +76,8 @@ sub track_mode {
|
||||
$self->{pbot}->{logger}->log("ChanOps: $source performed unhandled mode '$mode' on me\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -29,7 +29,7 @@ sub initialize {
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.topic', sub { $self->on_topic (@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.topicinfo', sub { $self->on_topicinfo (@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.channelcreate', sub { $self->on_channelcreate (@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.onemode', sub { $self->track_mode (@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.modeflag', sub { $self->on_modeflag (@_) });
|
||||
}
|
||||
|
||||
sub on_mode {
|
||||
@ -46,27 +46,27 @@ sub on_mode {
|
||||
($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host);
|
||||
|
||||
my $i = 0;
|
||||
my ($modifier, $char, $mode, $target);
|
||||
my ($modifier, $flag, $mode, $target);
|
||||
|
||||
my $source = "$nick!$user\@$host";
|
||||
|
||||
# split combined modes
|
||||
while ($mode_string =~ m/(.)/g) {
|
||||
$char = $1;
|
||||
$flag = $1;
|
||||
|
||||
if ($char eq '-' or $char eq '+') {
|
||||
$modifier = $char;
|
||||
if ($flag eq '-' or $flag eq '+') {
|
||||
$modifier = $flag;
|
||||
next;
|
||||
}
|
||||
|
||||
$mode = $modifier . $char;
|
||||
$mode = $modifier . $flag;
|
||||
$target = $event->{event}->{args}->[++$i];
|
||||
|
||||
$self->{pbot}->{logger}->log("Mode $channel [$mode" . (length $target ? " $target" : '') . "] by $source\n");
|
||||
|
||||
# dispatch a single mode event
|
||||
# dispatch a single mode flag event
|
||||
$self->{pbot}->{event_dispatcher}->dispatch_event(
|
||||
'irc.onemode',
|
||||
'irc.modeflag',
|
||||
{
|
||||
source => $source,
|
||||
channel => $channel,
|
||||
@ -79,7 +79,7 @@ sub on_mode {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub track_mode {
|
||||
sub on_modeflag {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
|
||||
my ($source, $channel, $mode, $target) = (
|
||||
@ -92,19 +92,20 @@ sub track_mode {
|
||||
# disregard mode set on user instead of channel
|
||||
return if defined $target and length $target;
|
||||
|
||||
my ($modifier, $char) = split //, $mode;
|
||||
my ($modifier, $flag) = split //, $mode;
|
||||
|
||||
my $modes = $self->{pbot}->{channels}->get_meta($channel, 'MODE') // '';
|
||||
|
||||
if ($modifier eq '+') {
|
||||
$modes = '+' if not length $modes;
|
||||
$modes .= $char if $modes !~ /\Q$char/;
|
||||
$modes .= $flag if $modes !~ /\Q$flag/;
|
||||
} else {
|
||||
$modes =~ s/\Q$char//g;
|
||||
$modes =~ s/\Q$flag//g;
|
||||
$modes = '' if $modes eq '+';
|
||||
}
|
||||
|
||||
$self->{pbot}->{channels}->{storage}->set($channel, 'MODE', $modes, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_join {
|
||||
|
@ -23,7 +23,7 @@ sub initialize {
|
||||
$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);
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.onemode', sub { $self->track_mode(@_) }, 0);
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.modeflag', sub { $self->on_modeflag(@_) }, 0);
|
||||
|
||||
# lowest priority so these get handled by NickList after all other handlers
|
||||
# (all other handlers should be given a priority < 100)
|
||||
@ -64,7 +64,7 @@ sub on_namreply {
|
||||
if ($nick =~ m/\%/) { $self->{pbot}->{nicklist}->set_meta($channel, $stripped_nick, '+h', 1); }
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_activity {
|
||||
@ -74,7 +74,7 @@ sub on_activity {
|
||||
|
||||
$self->{pbot}->{nicklist}->update_timestamp($channel, $nick);
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_join {
|
||||
@ -89,7 +89,7 @@ sub on_join {
|
||||
$self->{pbot}->{nicklist}->set_meta($channel, $nick, 'host', $host);
|
||||
$self->{pbot}->{nicklist}->set_meta($channel, $nick, 'join', gettimeofday);
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_part {
|
||||
@ -99,7 +99,7 @@ sub on_part {
|
||||
|
||||
$self->{pbot}->{nicklist}->remove_nick($channel, $nick);
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_quit {
|
||||
@ -113,7 +113,7 @@ sub on_quit {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_kick {
|
||||
@ -123,7 +123,7 @@ sub on_kick {
|
||||
|
||||
$self->{pbot}->{nicklist}->remove_nick($channel, $nick);
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_nickchange {
|
||||
@ -141,10 +141,10 @@ sub on_nickchange {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub track_mode {
|
||||
sub on_modeflag {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
|
||||
my ($source, $channel, $mode, $target) = (
|
||||
@ -154,6 +154,7 @@ sub track_mode {
|
||||
$event->{target},
|
||||
);
|
||||
|
||||
# disregard mode set on channel
|
||||
return if not defined $target or not length $target;
|
||||
|
||||
my ($modifier, $char) = split //, $mode;
|
||||
@ -163,19 +164,21 @@ sub track_mode {
|
||||
} else {
|
||||
$self->{pbot}->{nicklist}->set_meta($channel, $target, $mode, 1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_self_join {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
# clear nicklist to remove any stale nicks before repopulating with namreplies
|
||||
$self->{pbot}->{nicklist}->remove_channel($event->{channel});
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_self_part {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
$self->{pbot}->{nicklist}->remove_channel($event->{channel});
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -37,6 +37,7 @@ sub on_init {
|
||||
my (@args) = ($event->args);
|
||||
shift @args;
|
||||
$self->{pbot}->{logger}->log("*** @args\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_welcome {
|
||||
|
@ -61,7 +61,8 @@ sub on_join {
|
||||
$u->{loggedin} = 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_departure {
|
||||
@ -69,7 +70,7 @@ sub on_departure {
|
||||
my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to);
|
||||
($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host);
|
||||
$self->{pbot}->{users}->decache_user($channel, "$nick!$user\@$host");
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_kick {
|
||||
@ -77,13 +78,13 @@ sub on_kick {
|
||||
my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{args}[0]);
|
||||
($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host);
|
||||
$self->{pbot}->{users}->decache_user($channel, "$nick!$user\@$host");
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub on_self_part {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
delete $self->{pbot}->{users}->{user_cache}->{lc $event->{channel}};
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4333,
|
||||
BUILD_REVISION => 4334,
|
||||
BUILD_DATE => "2021-08-01",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user