Skip to content

Commit 720d593

Browse files
weechatterflashcode
authored andcommitted
query_blocker.pl 1.8: add argument "-all" for del, replace hook_completion_list_add by completion_list_add
The script now requires WeeChat ≥ 2.9.
1 parent e07c338 commit 720d593

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

perl/query_blocker.pl

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@
3838
#
3939
# -----------------------------------------------------------------------------
4040
# History:
41+
# 2025-05-26: nils_2@libera.#weechat
42+
# version 1.8:
43+
# ADD: new argument '-all' for del (idea PeGaSuS)
44+
# IMP: hook_completion_list_add() to completion_list_add()
45+
#
4146
# 2025-03-02: nils_2@libera.#weechat
4247
# version 1.7:
4348
# ADD: use of print_date_tags to set an tag for query_blocker messages, new option msg_tag (idea PeGaSuS)
49+
#
4450
# 2023-06-29: nils_2@libera.#weechat
4551
# version 1.6:
4652
# FIX: nick was not correctly parsed when message has tags.
@@ -132,11 +138,11 @@
132138

133139
my $SCRIPT = 'query_blocker';
134140
my $AUTHOR = 'rettub <rettub@gmx.net>';
135-
my $VERSION = '1.7';
141+
my $VERSION = '1.8';
136142
my $LICENSE = 'GPL3';
137143
my $DESCRIPTION = 'Simple blocker for private message (i.e. spam)';
138144
my $COMMAND = "query_blocker"; # new command name
139-
my $ARGS_HELP = "<on> | <off> | <status> | <list [last]> | <add [nick_1 [... [nick_n]]]> | <del nick_1 [... [nick_n]]> | <reload> | <blocked [clear]>";
145+
my $ARGS_HELP = "<on> | <off> | <status> | <list [last]> | <add [nick_1 [... [nick_n]]]> | <del nick_1 [... [nick_n][-all]]> | <reload> | <blocked [clear]>";
140146
my %help_desc = ( "block_queries" => "to enable or disable $COMMAND (default: 'off')",
141147
"quiet" => "will send auto reply about blocking, but don't send any notice to you. (default: 'off')",
142148
"show_deny_message" => "show you the deny message, sent to user. (default: 'off')",
@@ -160,13 +166,13 @@
160166
If you send a private message to a user, his nick will be added to the whitelist.
161167
162168
Arguments:
163-
on/off: toggle blocking of queries.
164-
status: show blocking status.
165-
list [last]: show whitelist, use last to show the nick blocked last.
166-
add/del [nicks]: add/delete nick(s) to/from whitelist. (if no nick is given, 'add' will use the last blocked one).
167-
('nicks' is a list of nicks seperated by spaces).
168-
reload: reload whitelist (useful if you changed the file-location i.e. to use a common file).
169-
blocked [clear]: list blocked nicks. If arg 'clear' is given all blocked nicks will be removed.
169+
on/off: toggle blocking of queries.
170+
status: show blocking status.
171+
list [last]: show whitelist, use last to show the nick blocked last.
172+
add/del [nicks][-all]: add/delete nick(s) to/from whitelist. (if no nick is given, 'add' will use the last blocked one).
173+
('nicks' is a list of nicks seperated by spaces) ('-all' will delete whitelist and save empty list to disk).
174+
reload: reload whitelist (useful if you changed the file-location i.e. to use a common file).
175+
blocked [clear]: list blocked nicks. If arg 'clear' is given all blocked nicks will be removed.
170176
171177
Script Options:
172178
ignore_auto_message: $help_desc{ignore_auto_message}
@@ -614,14 +620,14 @@ sub qb_unhook {
614620
sub query_blocker_completion_del_cb{
615621
my ($data, $completion_item, $buffer, $completion) = @_;
616622
foreach ( sort { "\L$a" cmp "\L$b" } keys %Allowed ) {
617-
weechat::hook_completion_list_add($completion, $_,1, weechat::WEECHAT_LIST_POS_SORT);
623+
weechat::completion_list_add($completion, $_,1, weechat::WEECHAT_LIST_POS_SORT);
618624
}
619625
return weechat::WEECHAT_RC_OK;
620626
}
621627
sub query_blocker_completion_add_cb{
622628
my ($data, $completion_item, $buffer, $completion) = @_;
623629
foreach (reverse keys %Blocked) {
624-
weechat::hook_completion_list_add($completion, $_,1, weechat::WEECHAT_LIST_POS_SORT);
630+
weechat::completion_list_add($completion, $_,1, weechat::WEECHAT_LIST_POS_SORT);
625631
}
626632
return weechat::WEECHAT_RC_OK;
627633
}
@@ -726,17 +732,23 @@ sub query_blocker {
726732
} elsif ( $cmd eq 'add' ) {
727733
_add($arg,1);
728734
}elsif ( $cmd eq 'del' and defined $arg ) {
729-
foreach ( split( / +/, $arg ) ) {
730-
if (exists $Allowed{$_} ) {
731-
delete $Allowed{$_};
732-
my ($server,$nick) = split(/\./,$_);
733-
weechat::print( '', "Nick removed from whitelist: '".
734-
weechat::color(weechat::config_color(weechat::config_get("weechat.color.chat_server"))).$server .
735-
weechat::color('reset') . "." .
736-
irc_nick_find_color($nick) . $nick .
737-
weechat::color('reset') . "'");
738-
} else {
739-
weechat::print( '', "Can't remove nick, not in whitelist: '" . irc_nick_find_color($_) . $_ . weechat::color('reset') . "'");
735+
if ( $arg eq '-all' ) {
736+
%Allowed = (); # empty hash with all whitelist nick
737+
weechat::print( '', "Nicks removed from whitelist");
738+
}
739+
else {
740+
foreach ( split( / +/, $arg ) ) {
741+
if (exists $Allowed{$_} ) {
742+
delete $Allowed{$_};
743+
my ($server,$nick) = split(/\./,$_);
744+
weechat::print( '', "Nick removed from whitelist: '".
745+
weechat::color(weechat::config_color(weechat::config_get("weechat.color.chat_server"))).$server .
746+
weechat::color('reset') . "." .
747+
irc_nick_find_color($nick) . $nick .
748+
weechat::color('reset') . "'");
749+
} else {
750+
weechat::print( '', "Can't remove nick, not in whitelist: '" . irc_nick_find_color($_) . $_ . weechat::color('reset') . "'");
751+
}
740752
}
741753
}
742754
whitelist_save();

0 commit comments

Comments
 (0)