keepnick.pl: use /notify not /ison

This commit is contained in:
opal hart 2018-01-10 23:00:08 +00:00
parent b8bca885f3
commit ee68ec916a

View File

@ -11,11 +11,10 @@ my $SCRIPT_VERSION = '1.0';
my $SCRIPT_LICENCE = 'Public domain'; my $SCRIPT_LICENCE = 'Public domain';
my $SCRIPT_DESC = 'Keep your primary nickname'; my $SCRIPT_DESC = 'Keep your primary nickname';
our (%waiting, %connecting, %noison); our (%waiting, %connecting);
my %OPTIONS = ( my %OPTIONS = (
default_enable => ['Whether to enable keepnick on servers by default', '0'], default_enable => ['Whether to enable keepnick on servers by default', '0'],
check_time => ['Time between ISON checks (reload script to take effect)', '60'],
); );
@ -51,7 +50,11 @@ sub is_waiting
sub disable sub disable
{ delete $waiting{lc shift}; } {
my $server = shift;
weechat::command('', "/notify del $_ $server") for @{$waiting{$server}};
delete $waiting{$server};
}
sub enable sub enable
{ {
@ -76,6 +79,7 @@ sub enable
} }
return () if lc $target[0] eq my_nick($server); return () if lc $target[0] eq my_nick($server);
weechat::command('', "/notify add $_ $server") for @target;
$waiting{$server} = \@target; $waiting{$server} = \@target;
return @target; return @target;
} }
@ -108,45 +112,11 @@ sub try_nick
else { lc $_ eq $oldnick and do_nick($server, $_) for @confnick; } else { lc $_ eq $oldnick and do_nick($server, $_) for @confnick; }
} }
sub ison_check sub irc_notify
{ {
my $iptr = weechat::infolist_get('irc_server', '', ''); my (undef, undef, $server, $nick) = (shift, shift, shift =~ /(.*),(.*)/);
while (weechat::infolist_next($iptr)) { try_nick($server, $nick);
next unless weechat::infolist_integer($iptr, 'is_connected');
my $server = lc weechat::infolist_string($iptr, 'name');
next unless is_waiting($server);
next unless exists $noison{$server};
weechat::hook_hsignal_send('irc_redirect_command', {
server => $server,
pattern => 'ison',
signal => $SCRIPT_NAME,
timeout => weechat::config_get_plugin('check_time') - 1,
});
weechat::hook_signal_send('irc_input_send',
weechat::WEECHAT_HOOK_SIGNAL_STRING,
"$server;;;;/ison ".(join ' ', @{ $waiting{$server} }));
}
weechat::infolist_free($iptr);
return weechat::WEECHAT_RC_OK;
}
sub irc_ison
{
my %hashtable = %{ pop() };
unless ($hashtable{output}) {
$noison{lc $hashtable{server}} = 1;
return weechat::WEECHAT_RC_ERROR;
}
my %nicks = map { lc $_ => 1 }
split / +/, ($hashtable{output} =~ s/^:[^ ]* 303 [^ ]+ :?//r);
for my $confnick (is_waiting($hashtable{server})) {
next if exists $nicks{lc $confnick}; # still taken
do_nick($hashtable{server}, $confnick);
last;
}
return weechat::WEECHAT_RC_OK; return weechat::WEECHAT_RC_OK;
} }
@ -268,9 +238,7 @@ if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
weechat::hook_signal('irc_server_connecting', 'irc_connecting', ''); weechat::hook_signal('irc_server_connecting', 'irc_connecting', '');
weechat::hook_signal('irc_server_connected', 'irc_connected', ''); weechat::hook_signal('irc_server_connected', 'irc_connected', '');
weechat::hook_signal('irc_server_disconnected', 'irc_disconnect', ''); weechat::hook_signal('irc_server_disconnected', 'irc_disconnect', '');
weechat::hook_timer(weechat::config_get_plugin('check_time') * 1000, 0, 0, weechat::hook_signal('irc_notify_quit', 'irc_notify', '');
'ison_check', '');
weechat::hook_hsignal("irc_redirection_${SCRIPT_NAME}_ison", 'irc_ison', '');
my $iptr = weechat::infolist_get('irc_server', '', ''); my $iptr = weechat::infolist_get('irc_server', '', '');
enable(weechat::infolist_string($iptr, 'name')) enable(weechat::infolist_string($iptr, 'name'))