|
38 | 38 | #
|
39 | 39 | # -----------------------------------------------------------------------------
|
40 | 40 | # 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 | +# |
41 | 46 | # 2025-03-02: nils_2@libera.#weechat
|
42 | 47 | # version 1.7:
|
43 | 48 | # ADD: use of print_date_tags to set an tag for query_blocker messages, new option msg_tag (idea PeGaSuS)
|
| 49 | +# |
44 | 50 | # 2023-06-29: nils_2@libera.#weechat
|
45 | 51 | # version 1.6:
|
46 | 52 | # FIX: nick was not correctly parsed when message has tags.
|
|
132 | 138 |
|
133 | 139 | my $SCRIPT = 'query_blocker';
|
134 | 140 | my $AUTHOR = 'rettub <rettub@gmx.net>';
|
135 |
| -my $VERSION = '1.7'; |
| 141 | +my $VERSION = '1.8'; |
136 | 142 | my $LICENSE = 'GPL3';
|
137 | 143 | my $DESCRIPTION = 'Simple blocker for private message (i.e. spam)';
|
138 | 144 | 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]>"; |
140 | 146 | my %help_desc = ( "block_queries" => "to enable or disable $COMMAND (default: 'off')",
|
141 | 147 | "quiet" => "will send auto reply about blocking, but don't send any notice to you. (default: 'off')",
|
142 | 148 | "show_deny_message" => "show you the deny message, sent to user. (default: 'off')",
|
|
160 | 166 | If you send a private message to a user, his nick will be added to the whitelist.
|
161 | 167 |
|
162 | 168 | 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. |
170 | 176 |
|
171 | 177 | Script Options:
|
172 | 178 | ignore_auto_message: $help_desc{ignore_auto_message}
|
@@ -614,14 +620,14 @@ sub qb_unhook {
|
614 | 620 | sub query_blocker_completion_del_cb{
|
615 | 621 | my ($data, $completion_item, $buffer, $completion) = @_;
|
616 | 622 | 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); |
618 | 624 | }
|
619 | 625 | return weechat::WEECHAT_RC_OK;
|
620 | 626 | }
|
621 | 627 | sub query_blocker_completion_add_cb{
|
622 | 628 | my ($data, $completion_item, $buffer, $completion) = @_;
|
623 | 629 | 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); |
625 | 631 | }
|
626 | 632 | return weechat::WEECHAT_RC_OK;
|
627 | 633 | }
|
@@ -726,17 +732,23 @@ sub query_blocker {
|
726 | 732 | } elsif ( $cmd eq 'add' ) {
|
727 | 733 | _add($arg,1);
|
728 | 734 | }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 | + } |
740 | 752 | }
|
741 | 753 | }
|
742 | 754 | whitelist_save();
|
|
0 commit comments