Skip to content

Commit 0f0c121

Browse files
tomteiplflashcode
authored andcommitted
buddylist 2.3: fix get_nickname function, replace hook_completion_list_add by completion_list_add instead
1 parent 7a7de5f commit 0f0c121

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

perl/buddylist.pl

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Copyright (c) 2010-2023 by Nils Görs <weechatter@arcor.de>
3+
# Copyright (c) 2025 by Kamil Wiśniewski <tomteipl@gmail.com>
34
#
45
# display the status and visited buffers of your buddies in a buddylist bar
56
#
@@ -15,7 +16,7 @@
1516
#
1617
# You should have received a copy of the GNU General Public License
1718
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18-
#
19+
# 2.3 : fix (get nickname) function and remake it to use "irc_message_parse". Fixed "completion_list_add" for compatibility with WeeChat >= 2.9
1920
# 2.2 : fix: make /whois lower-case
2021
# 2.1 : add compatibility with WeeChat >= 3.2 (XDG directories)
2122
# 2.0 : make call to bar_new compatible with WeeChat >= 2.9
@@ -38,7 +39,7 @@
3839
# 1.2.1 : fixed: bitlbee_service was not set, for new added buddy
3940
# v1.2 : added: function "hide_bar = always" (requested by: Emralegna)
4041
# : added: buddies will be separated by protocol (msn/jabber etc.pp.) on bitlbee server (requested by: ArcAngel)
41-
# : added: options "text.online", "text.away", "text.offline" (maybe usefull for color-blind people:-)
42+
# : added: options "text.online", "text.away", "text.offline" (maybe usefull for color-blind people:-)
4243
# : added: function weechat_config_set_desc_plugin() (only for weechat >= v0.3.5)
4344
# v1.1 : fixed: offline users on bitlbee were shown as away. (reported and beta-testing by javuchi)
4445
# v1.0 : redirection implemented (needs weechat >= 0.3.4). Now, its a real buddylist
@@ -72,7 +73,7 @@
7273
# 0.4 : added option "sort"
7374
# 0.3 : remove spaces for indenting when bar position is top/bottom
7475
# hook_config when settings changed.
75-
# 0.2 : work-around for crash when searching nick in buffer without nicklist (function nicklist_search_nick) removed
76+
# 0.2 : work-around for crash when searching nick in buffer without nicklist (function nicklist_search_nick) removed
7677
# 0.1 : initial release
7778
#
7879
# Development is currently hosted at
@@ -85,7 +86,7 @@
8586
use strict;
8687

8788
my $prgname = "buddylist";
88-
my $version = "2.2";
89+
my $version = "2.3";
8990
my $description = "display status from your buddies a bar-item.";
9091

9192
# -------------------------------[ config ]-------------------------------------
@@ -218,7 +219,7 @@
218219
hook_timer_and_redirect() if ($default_options{check_buddies} ne "0" and $default_options{use_redirection} eq "on");
219220

220221
weechat::hook_command($prgname, $description,
221-
"<add>[nick_1 [... nick_n]] | <del>[nick_1 [... nick_n]]",
222+
"<add>[nick_1 [... nick_n]] | <del>[nick_1 [... nick_n]]",
222223

223224
"<add> [nick(s)] add nick(s) to the buddylist\n".
224225
"<del> [nick(s)] delete nick(s) from the buddylist\n".
@@ -446,7 +447,7 @@ sub build_buddylist{
446447

447448
# sorted by status first, then bitlbee_service and nick case insensitiv at least
448449
# foreach my $n (sort { $nick_structure{$s}{$a}->{status} cmp $nick_structure{$s}{$b}->{status}} (sort {uc($a) cmp uc($b)} (sort keys(%{$nick_structure{$s}})))){
449-
450+
450451
my $status_output = "";
451452
my $status_output_copy = "";
452453
foreach my $n (sort { $nick_structure{$s}{$a}->{status} cmp $nick_structure{$s}{$b}->{status}} (sort { $nick_structure{$s}{$a}->{bitlbee_service} cmp $nick_structure{$s}{$b}->{bitlbee_service}} (sort {uc($a) cmp uc($b)} (sort keys(%{$nick_structure{$s}})) ) ) ){
@@ -1492,9 +1493,27 @@ sub parse_redirect{
14921493
}
14931494
}
14941495

1495-
# get nick name
1496-
my $rfc_311 = " 311 "; # nick username address * :info
1497-
my (undef, undef, undef, $nickname2, undef) = split /\s+/, $args, 5 if ($args =~ /($rfc_311)/); # get nickname
1496+
# get nick name ($rfc_311)
1497+
my $nickname2;
1498+
my $parsed_hash = weechat::info_get_hashtable("irc_message_parse", { "message" => $args });
1499+
if ($parsed_hash) {
1500+
my $parsed_message = $parsed_hash->{'message_without_tags'};
1501+
if ($parsed_message =~ /^\S+ 311 \S+ (\S+)/) { # gets the nickname
1502+
$nickname2 = $1;
1503+
if ($debug_redir_out eq "on") {
1504+
weechat::print("", "Parsed nickname: $nickname2"); # DEBUG
1505+
}
1506+
} else {
1507+
if ($debug_redir_out eq "on") {
1508+
weechat::print("", "Failed to extract nickname from: $parsed_message"); # DEBUG
1509+
}
1510+
}
1511+
} else {
1512+
if ($debug_redir_out eq "on") {
1513+
weechat::print("", "Failed to parse: $args"); # DEBUG
1514+
}
1515+
}
1516+
14981517

14991518
# check nick away....
15001519
$args =~ /($rfc_301)/;
@@ -1529,7 +1548,7 @@ sub buddy_list_completion_cb{
15291548
$server = $channel if ( $server eq "server"); # are we in server buffer?
15301549

15311550
foreach my $nickname ( keys %{$nick_structure{$server}} ) {
1532-
weechat::hook_completion_list_add($completion, $nickname,1, weechat::WEECHAT_LIST_POS_SORT);
1551+
weechat::completion_list_add($completion, $nickname,1, weechat::WEECHAT_LIST_POS_SORT);
15331552
}
15341553

15351554
return weechat::WEECHAT_RC_OK;

0 commit comments

Comments
 (0)