# list.pl by ArZa : Sort the output of /list command # This program is free software: you can modify/redistribute it under the terms of # GNU General Public License by Free Software Foundation, either version 3 or later # which you can get from . # This program is distributed in the hope that it will be useful, but without any warranty. weechat::register("list", "ArZa", "0.1", "GPL3", "Sort the output of /list command", "", ""); weechat::hook_command_run("/list", "list_run", ""); weechat::hook_modifier("irc_color_decode", "list_handle", ""); our $server; sub list_run { my ($data, $buffer, $command) = @_; $server=weechat::buffer_get_string($buffer, "localvar_server"); weechat::hook_hsignal ("irc_redirection_sig_list", "list_get", ""); weechat::hook_hsignal_send("irc_redirect_command", { "server" => "$server", "pattern" => "list", "signal" => "sig" }); weechat::hook_signal_send("irc_input_send", weechat::WEECHAT_HOOK_SIGNAL_STRING,"$server;;2;;$command"); return weechat::WEECHAT_RC_OK_EAT; } sub list_get { my %hashtable=%{$_[2]}; weechat::hook_modifier_exec("irc_color_decode", 1, $hashtable{"output"}); return weechat::WEECHAT_RC_OK; } sub list_handle { my @list=split(/\n/, $_[3]); if(@list>500){ weechat::print("", "Too long list :P"); return 1; } my $buffer=weechat::buffer_search("irc", "server.$server"); shift(@list); pop(@list); foreach my $line (@list) { $line=~s/(\S+) (\S+) (\S+) (\S+) (\S+) :(.*)/$5: $4 $6/; } @list = sort { ($b=~/(\d+)/)[0] <=> ($a=~/(\d+)/)[0] } @list; weechat::print($buffer, weechat::prefix('network')."Users Channel Topic"); foreach my $line (@list) { $line=~/(\S+) (\S+) (.*)/; weechat::print($buffer, weechat::prefix('network').weechat::color('bold')."$1 ".weechat::color('darkgray')."$2".weechat::color('default')." $3"); } weechat::print($buffer, weechat::prefix('network')."End of /LIST"); }