mirror of https://git.envs.net/envs/skel.git
update weechat perl and python plugins
This commit is contained in:
parent
e11d583d8c
commit
4b338c0682
|
@ -39,36 +39,36 @@
|
|||
# : added: function weechat_config_set_desc_plugin() (only for weechat >= v0.3.5)
|
||||
# v1.1 : fixed: offline users on bitlbee were shown as away. (reported and beta-testing by javuchi)
|
||||
# v1.0 : redirection implemented (needs weechat >= 0.3.4). Now, its a real buddylist
|
||||
# : new options: "check.buddies", "callback.timeout", "use.redirection", "display.original.nick"
|
||||
# : buffer-number will be displayed behind nickname (option: "color.number")
|
||||
# : buddylist will be build instandly when switching bar-position.
|
||||
# : thanks to shariebeth for beta-testing
|
||||
# : new options: "check.buddies", "callback.timeout", "use.redirection", "display.original.nick"
|
||||
# : buffer-number will be displayed behind nickname (option: "color.number")
|
||||
# : buddylist will be build instandly when switching bar-position.
|
||||
# : thanks to shariebeth for beta-testing
|
||||
# 0.9.4 : now using irc.server_default.away_check_max_nicks and irc.server_default.away_check
|
||||
# 0.9.3 : check for JOIN signal (requested by Rupp)
|
||||
# 0.9.2 : server wasn't hidden for "default" settings
|
||||
# server will be hidden if all buddies are offline for this server (option: hide.server.if.buddies.offline (requested by TenOfTen))
|
||||
# buddies will be hidden when offline (option: hide.buddy.if.offline (requested by TenOfTen))
|
||||
# new function added: "list"
|
||||
# the buddylist will be saved in a new format : servername.nickname (old format will be recognized, too)
|
||||
# and other internal changes
|
||||
# 0.9.1 : bar could not be hidden (detrate-)
|
||||
# : error message for old datafile (bazerka)
|
||||
# server will be hidden if all buddies are offline for this server (option: hide.server.if.buddies.offline (requested by TenOfTen))
|
||||
# buddies will be hidden when offline (option: hide.buddy.if.offline (requested by TenOfTen))
|
||||
# new function added: "list"
|
||||
# the buddylist will be saved in a new format : servername.nickname (old format will be recognized, too)
|
||||
# and other internal changes
|
||||
# 0.9.1 : bar could not be hidden (detrate-)
|
||||
# : error message for old datafile (bazerka)
|
||||
# 0.9 : servername without nicks will not be displayed in buddylist
|
||||
# servername will be displayed in different color or will be hidden if not connected (option "color.server.offline")
|
||||
# buddylist bar will be hidden if you are not connected to a server (option "hide.bar")
|
||||
# servername will be displayed in different color or will be hidden if not connected (option "color.server.offline")
|
||||
# buddylist bar will be hidden if you are not connected to a server (option "hide.bar")
|
||||
# 0.8 : - major changes - (buddylist file changed!!!)
|
||||
# buddylist uses now server / nick structure
|
||||
# buddylist uses now server / nick structure
|
||||
# change entries in buddylist to : servername,nickname (e.g.: freenode,nils_2)
|
||||
# or add your buddies again with the add function.
|
||||
# or add your buddies again with the add function.
|
||||
# 0.7 : nick change will be recognize
|
||||
# 0.6 : nick wasn't set to offline, if buddy leave channel
|
||||
# 0.5 : server information will be used now instead of nicklist
|
||||
# reduction of cpu load (reported by ArcAngel and tigrmesh)
|
||||
# bar will be removed if you unload the script. (requested by bazerka)
|
||||
# help page will be displayed when you call buddylist without arguments
|
||||
# reduction of cpu load (reported by ArcAngel and tigrmesh)
|
||||
# bar will be removed if you unload the script. (requested by bazerka)
|
||||
# help page will be displayed when you call buddylist without arguments
|
||||
# 0.4 : added option "sort"
|
||||
# 0.3 : remove spaces for indenting when bar position is top/bottom
|
||||
# hook_config when settings changed.
|
||||
# hook_config when settings changed.
|
||||
# 0.2 : work-around for crash when searching nick in buffer without nicklist (function nicklist_search_nick) removed
|
||||
# 0.1 : initial release
|
||||
#
|
||||
|
@ -81,33 +81,33 @@
|
|||
|
||||
use strict;
|
||||
|
||||
my $prgname = "buddylist";
|
||||
my $version = "1.9";
|
||||
my $description = "display status from your buddies a bar-item.";
|
||||
my $prgname = "buddylist";
|
||||
my $version = "1.9";
|
||||
my $description = "display status from your buddies a bar-item.";
|
||||
|
||||
# -------------------------------[ config ]-------------------------------------
|
||||
my $default_buddylist = "%h/buddylist.txt";
|
||||
my $default_buddylist = "%h/buddylist.txt";
|
||||
my %buddylist_level = (0 => "online", 1 => "away", 2 => "offline");
|
||||
my %default_color_buddylist = ("online" => "yellow",
|
||||
"away" => "cyan",
|
||||
"offline" => "blue");
|
||||
"away" => "cyan",
|
||||
"offline" => "blue");
|
||||
|
||||
my %default_options = ( "position" => "top",
|
||||
"hide_bar" => "on", # hide buddylist bar when all servers are offline
|
||||
"hide_server" => "off", # hide server if no buddy is online on this server
|
||||
"hide_buddy" => "off", # hide buddy when offline
|
||||
"buddy_on_server" => "on", # show connected buddy (on server and not channel)
|
||||
"buddy_on_server_color" => "lightgreen", # color for buddy who is connected to server
|
||||
"sort" => "default", # sort method
|
||||
"color_default" => "default",
|
||||
"color_server_online" => "white",
|
||||
"color_server_offline" => "hide",
|
||||
"color_number" => "lightred",
|
||||
"show_query" => "on",
|
||||
"check_buddies" => "20", # delay (in seconds)
|
||||
"callback_timeout" => "60", # delay (in seconds)
|
||||
"use_redirection" => "on",
|
||||
"display_original_nick" => "off",
|
||||
my %default_options = ( "position" => "top",
|
||||
"hide_bar" => "on", # hide buddylist bar when all servers are offline
|
||||
"hide_server" => "off", # hide server if no buddy is online on this server
|
||||
"hide_buddy" => "off", # hide buddy when offline
|
||||
"buddy_on_server" => "on", # show connected buddy (on server and not channel)
|
||||
"buddy_on_server_color" => "lightgreen", # color for buddy who is connected to server
|
||||
"sort" => "default", # sort method
|
||||
"color_default" => "default",
|
||||
"color_server_online" => "white",
|
||||
"color_server_offline" => "hide",
|
||||
"color_number" => "lightred",
|
||||
"show_query" => "on",
|
||||
"check_buddies" => "20", # delay (in seconds)
|
||||
"callback_timeout" => "60", # delay (in seconds)
|
||||
"use_redirection" => "on",
|
||||
"display_original_nick" => "off",
|
||||
"display_social_net" => "on",
|
||||
"display_social_net_color"=> "yellow",
|
||||
"text_online" => "",
|
||||
|
@ -125,12 +125,12 @@ my %mouse_keys = ("\@item(buddylist):button1*"
|
|||
my %cursor_keys = ( "\@item(buddylist):q" => "hsignal:buddylist_cursor",
|
||||
"\@item(buddylist):w" => "hsignal:buddylist_cursor");
|
||||
|
||||
my $debug_redir_out = "off";
|
||||
my $debug_redir_out = "off";
|
||||
|
||||
# ------------------------------[ internal ]-----------------------------------
|
||||
my %Hooks = (); # space for my hooks
|
||||
my %buddies = (); # to store the buddylist with status for each nick
|
||||
my %nick_structure = (); # to store servername, nickname and status
|
||||
my %Hooks = (); # space for my hooks
|
||||
my %buddies = (); # to store the buddylist with status for each nick
|
||||
my %nick_structure = (); # to store servername, nickname and status
|
||||
my $default_version = 0; # minimum version (0.3.4)
|
||||
my $bar_hidden = "off"; # status of bar
|
||||
my $servertest = 0; # 0 = no server connected
|
||||
|
@ -166,7 +166,7 @@ my @buddylist_focus = ();
|
|||
# -------------------------------[ main ]-------------------------------------
|
||||
# first function called by a WeeChat-script.
|
||||
weechat::register($prgname, "Nils Görs <weechatter\@arcor.de>", $version,
|
||||
"GPL3", $description, "shutdown", "");
|
||||
"GPL3", $description, "shutdown", "");
|
||||
my $weechat_version = "";
|
||||
init();
|
||||
buddylist_read();
|
||||
|
@ -179,7 +179,7 @@ weechat::bar_new($prgname, "1", "0", "root", "", "left", "horizontal",
|
|||
weechat::hook_signal("buffer_*", "buddylist_signal_buffer", "");
|
||||
|
||||
|
||||
weechat::hook_signal("*,irc_in2_352", "from_hook_who",""); # RFC command with use,channel,status etc..
|
||||
weechat::hook_signal("*,irc_in2_352", "from_hook_who",""); # RFC command with use,channel,status etc..
|
||||
|
||||
weechat::hook_signal("*,irc_in_part", "remove_nick", "");
|
||||
weechat::hook_signal("*,irc_in_quit", "remove_nick", "");
|
||||
|
@ -192,7 +192,7 @@ weechat::hook_signal("buffer_closing", "buffer_closing", "");
|
|||
weechat::hook_signal("*,irc_in_nick", "nick_changed", "");
|
||||
weechat::hook_signal("irc_server_connected", "server_connected", "");
|
||||
weechat::hook_signal("irc_server_disconnected", "server_disconnected", "");
|
||||
weechat::hook_config("plugins.var.perl.$prgname.*", "toggled_by_set", ""); # buddylist options changed?
|
||||
weechat::hook_config("plugins.var.perl.$prgname.*", "toggled_by_set", ""); # buddylist options changed?
|
||||
weechat::hook_completion("perl_buddylist", "buddylist completion", "buddy_list_completion_cb", "");
|
||||
|
||||
weechat::hook_signal("upgrade_ended", "buddylist_upgrade_ended", "");
|
||||
|
@ -333,27 +333,27 @@ sub buffer_closing
|
|||
weechat::bar_item_update($prgname);
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
# my $infolist_buf_closing = weechat::infolist_get("buffer",$callback_data,""); # get pointer from closing buffer
|
||||
# my $infolist_buf_closing = weechat::infolist_get("buffer",$callback_data,""); # get pointer from closing buffer
|
||||
# weechat::infolist_next($infolist_buf_closing);
|
||||
# my $num_closing_buf = weechat::infolist_integer($infolist_buf_closing,"number"); # get number of closing buffer
|
||||
# my $num_closing_buf = weechat::infolist_integer($infolist_buf_closing,"number"); # get number of closing buffer
|
||||
# my $server_name = weechat::infolist_string($infolist_buf_closing,"name");
|
||||
# my $buffer_name_short = weechat::infolist_string($infolist_buf_closing,"short_name");
|
||||
# weechat::infolist_free($infolist_buf_closing);
|
||||
# $server_name =~ s/\.$buffer_name_short//;
|
||||
|
||||
# my $buffer_number = "";
|
||||
# my $str = "";
|
||||
# my $infolist_buffer = weechat::infolist_get("buffer","","*");
|
||||
# while ( weechat::infolist_next($infolist_buffer) ){
|
||||
# if ( index (weechat::infolist_string($infolist_buffer,"name"), $server_name) ne "-1" and weechat::infolist_pointer($infolist_buffer,"pointer") ne $callback_data ){
|
||||
# $buffer_number = weechat::infolist_string($infolist_buffer,"short_name"); # get short_name of buffer
|
||||
# $str .= $buffer_number . " ";
|
||||
# }
|
||||
# }
|
||||
# weechat::infolist_free($infolist_buffer);
|
||||
# $str =~ s/^\s+//g; # delete last space
|
||||
# my $buffer_number = "";
|
||||
# my $str = "";
|
||||
# my $infolist_buffer = weechat::infolist_get("buffer","","*");
|
||||
# while ( weechat::infolist_next($infolist_buffer) ){
|
||||
# if ( index (weechat::infolist_string($infolist_buffer,"name"), $server_name) ne "-1" and weechat::infolist_pointer($infolist_buffer,"pointer") ne $callback_data ){
|
||||
# $buffer_number = weechat::infolist_string($infolist_buffer,"short_name"); # get short_name of buffer
|
||||
# $str .= $buffer_number . " ";
|
||||
# }
|
||||
# }
|
||||
# weechat::infolist_free($infolist_buffer);
|
||||
# $str =~ s/^\s+//g; # delete last space
|
||||
|
||||
# foreach my $nickname ( sort keys %{$nick_structure{$server_name}} ) { # sortiert die Nicks alphabetisch
|
||||
# foreach my $nickname ( sort keys %{$nick_structure{$server_name}} ) { # sortiert die Nicks alphabetisch
|
||||
# my $status = $nick_structure{$server_name}{$nickname}{status};
|
||||
# next if ( not defined $status or $status eq "2" );
|
||||
# my $buf_name = $nick_structure{$server_name}{$nickname}{buf_name};
|
||||
|
@ -361,8 +361,8 @@ sub buffer_closing
|
|||
|
||||
# if ( index($buf_name,$buffer_name_short) ne "-1" or $buf_name ne "" or $buf_name ne "()" ){
|
||||
# $buf_name =~ s/$buffer_name_short//;
|
||||
# $buf_name =~ s/\s+$//g; # delete last space
|
||||
# if ($buf_name eq ""){ # no more buffer
|
||||
# $buf_name =~ s/\s+$//g; # delete last space
|
||||
# if ($buf_name eq ""){ # no more buffer
|
||||
# $nick_structure{$server_name}{$nickname}{buf_name} = "";
|
||||
# $nick_structure{$server_name}{$nickname}{buffer} = "";
|
||||
# }else{
|
||||
|
@ -406,32 +406,32 @@ sub build_buddylist{
|
|||
$visual = $cr if (($default_options{position} eq "left") || ($default_options{position} eq "right"));
|
||||
|
||||
# get bar position (left/right/top/bottom) and sort (default/status)
|
||||
my $option = weechat::config_get("weechat.bar.$prgname.position");
|
||||
if ($option ne ""){
|
||||
$default_options{position} = weechat::config_string($option);
|
||||
}
|
||||
my $option = weechat::config_get("weechat.bar.$prgname.position");
|
||||
if ($option ne ""){
|
||||
$default_options{position} = weechat::config_string($option);
|
||||
}
|
||||
|
||||
if ($default_options{sort} eq "status"){ # use sort option "status"
|
||||
foreach my $s ( sort keys %nick_structure ) {
|
||||
if ($default_options{sort} eq "status"){ # use sort option "status"
|
||||
foreach my $s ( sort keys %nick_structure ) {
|
||||
$bitlbee_service_separator = "";
|
||||
$bitlbee_service_separator_copy = "";
|
||||
if (keys (%{$nick_structure{$s}}) eq "0"){ # check out if nicks exists for server in nick_structure
|
||||
next; # no nick for server. jump to next server
|
||||
}
|
||||
if (keys (%{$nick_structure{$s}}) eq "0"){ # check out if nicks exists for server in nick_structure
|
||||
next; # no nick for server. jump to next server
|
||||
}
|
||||
|
||||
# sort list by status (online => away => offline) for internal use.
|
||||
my ($n) = ( sort { $nick_structure{$s}{$a}->{status} <=> $nick_structure{$s}{$b}->{status}} keys %{$nick_structure{$s}} );
|
||||
$nick_structure{$s}{$n}{bitlbee_service} = "" if ( not defined $nick_structure{$s}{$n}{bitlbee_service} );
|
||||
if ($nick_structure{$s}{$n}{status} eq "2" and $default_options{hide_server} eq "on"){ # status from first buddy in list!
|
||||
next; # first sorted buddy is offline (2)
|
||||
}
|
||||
if ($nick_structure{$s}{$n}{status} eq "2" and $default_options{hide_server} eq "on"){ # status from first buddy in list!
|
||||
next; # first sorted buddy is offline (2)
|
||||
}
|
||||
|
||||
my $color_server = get_server_status($s); # get server color
|
||||
if ($color_server eq "1"){
|
||||
next; # hide server if result = 1
|
||||
}
|
||||
my $color_server = get_server_status($s); # get server color
|
||||
if ($color_server eq "1"){
|
||||
next; # hide server if result = 1
|
||||
}
|
||||
if ($default_options{hide_servername_in_buddylist} ne "on"){
|
||||
$str .= weechat::color($color_server) . $s . ":" . $visual; # add servername ($s ;) to buddylist
|
||||
$str .= weechat::color($color_server) . $s . ":" . $visual; # add servername ($s ;) to buddylist
|
||||
}
|
||||
add_buddy_focus("","",""); # create focus for servername
|
||||
|
||||
|
@ -467,26 +467,26 @@ sub build_buddylist{
|
|||
}
|
||||
}
|
||||
|
||||
} elsif ($default_options{sort} ne "status") { # use sort option "default"
|
||||
foreach my $s ( sort keys %nick_structure ) { # sort server alphabetically
|
||||
} elsif ($default_options{sort} ne "status") { # use sort option "default"
|
||||
foreach my $s ( sort keys %nick_structure ) { # sort server alphabetically
|
||||
$bitlbee_service_separator = "";
|
||||
$bitlbee_service_separator_copy = "";
|
||||
if (keys (%{$nick_structure{$s}}) eq "0"){ # check out if nicks exists for server
|
||||
next; # no nick for server. jump to next server
|
||||
}
|
||||
# sort list by status (from online, away, offline)
|
||||
my ($n) = ( sort { $nick_structure{$s}{$a}->{status} <=> $nick_structure{$s}{$b}->{status}} keys %{$nick_structure{$s}} );
|
||||
if ($nick_structure{$s}{$n}{status} eq "2" and $default_options{hide_server} eq "on"){ # status from first buddy in list!
|
||||
next; # first sorted buddy is offline (2)
|
||||
}
|
||||
my $visual = " "; # placeholder after servername
|
||||
my $cr = "\n";
|
||||
$visual = $cr if (($default_options{position} eq "left") || ($default_options{position} eq "right"));
|
||||
if (keys (%{$nick_structure{$s}}) eq "0"){ # check out if nicks exists for server
|
||||
next; # no nick for server. jump to next server
|
||||
}
|
||||
# sort list by status (from online, away, offline)
|
||||
my ($n) = ( sort { $nick_structure{$s}{$a}->{status} <=> $nick_structure{$s}{$b}->{status}} keys %{$nick_structure{$s}} );
|
||||
if ($nick_structure{$s}{$n}{status} eq "2" and $default_options{hide_server} eq "on"){ # status from first buddy in list!
|
||||
next; # first sorted buddy is offline (2)
|
||||
}
|
||||
my $visual = " "; # placeholder after servername
|
||||
my $cr = "\n";
|
||||
$visual = $cr if (($default_options{position} eq "left") || ($default_options{position} eq "right"));
|
||||
|
||||
my $color_server = get_server_status($s); # get server color
|
||||
if ($color_server eq "1"){
|
||||
next; # hide server if result = 1
|
||||
}
|
||||
my $color_server = get_server_status($s); # get server color
|
||||
if ($color_server eq "1"){
|
||||
next; # hide server if result = 1
|
||||
}
|
||||
if ($default_options{hide_servername_in_buddylist} ne "on"){
|
||||
$str .= weechat::color($color_server) . $s . ":" . $visual; # add servername ($s ;) to buddylist
|
||||
}
|
||||
|
@ -509,34 +509,34 @@ sub build_buddylist{
|
|||
}
|
||||
}
|
||||
if ($str eq ""){
|
||||
my $network_away_check = weechat::config_integer(weechat::config_get("irc.server_default.away_check"));
|
||||
if ($network_away_check == 0 and $default_options{use_redirection} ne "on"){
|
||||
$str = "value from option \"irc.server_default.away_check\" is 0.".$visual."It has to be >= 1 or you have to use option".$visual."\"plugins.var.perl.buddylist.use.redirection = on\".";
|
||||
}else{
|
||||
my $network_away_check = weechat::config_integer(weechat::config_get("irc.server_default.away_check"));
|
||||
if ($network_away_check == 0 and $default_options{use_redirection} ne "on"){
|
||||
$str = "value from option \"irc.server_default.away_check\" is 0.".$visual."It has to be >= 1 or you have to use option".$visual."\"plugins.var.perl.buddylist.use.redirection = on\".";
|
||||
}else{
|
||||
return $str = "Not connected to a server..." if ( $servertest == 0 );
|
||||
return $str = "Searching for buddies,".$visual."please wait..." if ($network_away_check == 0);
|
||||
$str = "Please wait, building buddylist".$visual."(this could take $network_away_check minutes)...".$visual."probably there are no buddies in your".$visual."buddylist for connected server,".$visual."or you are not connected to a server".$visual."or your buddies are all offline";
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
return $str = "Searching for buddies,".$visual."please wait..." if ($network_away_check == 0);
|
||||
$str = "Please wait, building buddylist".$visual."(this could take $network_away_check minutes)...".$visual."probably there are no buddies in your".$visual."buddylist for connected server,".$visual."or you are not connected to a server".$visual."or your buddies are all offline";
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
# get status from server and color the servername (or hide it)
|
||||
sub get_server_status{
|
||||
my $server = $_[0];
|
||||
my $infolist_server = weechat::infolist_get("irc_server","",$server); # get pointer for server %s
|
||||
weechat::infolist_next($infolist_server);
|
||||
my $is_connected = weechat::infolist_integer($infolist_server,"is_connected"); # get status of connection for server (1 = connected | 0 = disconnected)
|
||||
weechat::infolist_free($infolist_server); # don't forget to free infolist ;-)
|
||||
if ($is_connected == 0){ # 0 = not connected
|
||||
if ($default_options{color_server_offline} eq "hide"){ # hide offline server?
|
||||
return 1; # yes!
|
||||
}
|
||||
$default_options{color_server_offline} = $default_options{color_default} if ($default_options{color_server_offline} eq "");
|
||||
return $default_options{color_server_offline}; # color for server offline
|
||||
}
|
||||
my $infolist_server = weechat::infolist_get("irc_server","",$server); # get pointer for server %s
|
||||
weechat::infolist_next($infolist_server);
|
||||
my $is_connected = weechat::infolist_integer($infolist_server,"is_connected"); # get status of connection for server (1 = connected | 0 = disconnected)
|
||||
weechat::infolist_free($infolist_server); # don't forget to free infolist ;-)
|
||||
if ($is_connected == 0){ # 0 = not connected
|
||||
if ($default_options{color_server_offline} eq "hide"){ # hide offline server?
|
||||
return 1; # yes!
|
||||
}
|
||||
$default_options{color_server_offline} = $default_options{color_default} if ($default_options{color_server_offline} eq "");
|
||||
return $default_options{color_server_offline}; # color for server offline
|
||||
}
|
||||
$default_options{color_server_online} = $default_options{color_default} if ($default_options{color_server_online} eq "");# fall back color if color_server = ""
|
||||
return $default_options{color_server_online}; # color for server online
|
||||
return $default_options{color_server_online}; # color for server online
|
||||
}
|
||||
|
||||
# for mouse support, create a focus list
|
||||
|
@ -611,23 +611,23 @@ $buffer_number = "" if (not defined $buffer_number);
|
|||
|
||||
# buddy changed his nick (irc_in_nick)
|
||||
sub nick_changed{
|
||||
my ($blank, $servername, $args) = @_;
|
||||
my ($blank, $servername, $args) = @_;
|
||||
|
||||
return weechat::WEECHAT_RC_OK if ( $default_options{use_redirection} eq "on" ); # do not rename nick in redirection_mode!!!
|
||||
return weechat::WEECHAT_RC_OK if ( $default_options{use_redirection} eq "on" ); # do not rename nick in redirection_mode!!!
|
||||
|
||||
|
||||
my ($server) = split(/,/, $servername); # get name from server
|
||||
$args =~ /\:(.*)\!(.*)\:(.*)/;
|
||||
my $old_nickname = $1;
|
||||
my $new_nickname = $3;
|
||||
my ($server) = split(/,/, $servername); # get name from server
|
||||
$args =~ /\:(.*)\!(.*)\:(.*)/;
|
||||
my $old_nickname = $1;
|
||||
my $new_nickname = $3;
|
||||
|
||||
if (defined $nick_structure{$server}{$old_nickname} and exists $nick_structure{$server}{$old_nickname}){
|
||||
my $status = $nick_structure{$server}{$old_nickname}{status}; # get old buddy status
|
||||
$nick_structure{$server}{$new_nickname}{status} = $status; # add /nick buddy with old status
|
||||
delete $nick_structure{$server}{$old_nickname}; # delete old buddyname
|
||||
if (defined $nick_structure{$server}{$old_nickname} and exists $nick_structure{$server}{$old_nickname}){
|
||||
my $status = $nick_structure{$server}{$old_nickname}{status}; # get old buddy status
|
||||
$nick_structure{$server}{$new_nickname}{status} = $status; # add /nick buddy with old status
|
||||
delete $nick_structure{$server}{$old_nickname}; # delete old buddyname
|
||||
|
||||
weechat::bar_item_update($prgname);
|
||||
}
|
||||
weechat::bar_item_update($prgname);
|
||||
}
|
||||
}
|
||||
|
||||
sub add_nick{
|
||||
|
@ -683,8 +683,8 @@ sub from_hook_who{
|
|||
|
||||
# add buddy to my structure
|
||||
sub add_to_nicktable{
|
||||
my ($servername, $nickname, $status) = @_;
|
||||
$nick_structure{$servername}{$nickname}{status} = $status; # create structure
|
||||
my ($servername, $nickname, $status) = @_;
|
||||
$nick_structure{$servername}{$nickname}{status} = $status; # create structure
|
||||
}
|
||||
|
||||
# user commands
|
||||
|
@ -775,17 +775,17 @@ sub server_check{
|
|||
$servertest = 0;
|
||||
# check if at least one server is online
|
||||
|
||||
foreach my $s ( sort keys %nick_structure ) { # sort server alphabetically
|
||||
foreach my $s ( sort keys %nick_structure ) { # sort server alphabetically
|
||||
my $infolist_server = weechat::infolist_get("irc_server","",$s); # get pointer for server %s
|
||||
weechat::infolist_next($infolist_server);
|
||||
my $is_connected = weechat::infolist_integer($infolist_server,"is_connected"); # get status of connection for server (1 = connected | 0 = disconnected)
|
||||
weechat::infolist_next($infolist_server);
|
||||
my $is_connected = weechat::infolist_integer($infolist_server,"is_connected"); # get status of connection for server (1 = connected | 0 = disconnected)
|
||||
weechat::infolist_free($infolist_server); # don't forget to free infolist ;-)
|
||||
if ($is_connected == 1){
|
||||
$servertest = 1; # one server is at least online!
|
||||
last;
|
||||
}
|
||||
}
|
||||
if ( $servertest == 0 and $default_options{hide_bar} ne "off" ){ # no server with buddies
|
||||
if ($is_connected == 1){
|
||||
$servertest = 1; # one server is at least online!
|
||||
last;
|
||||
}
|
||||
}
|
||||
if ( $servertest == 0 and $default_options{hide_bar} ne "off" ){ # no server with buddies
|
||||
weechat::command("", "/bar hide " . $prgname);
|
||||
$bar_hidden = "on";
|
||||
}elsif ( $default_options{hide_bar} eq "off" ){
|
||||
|
@ -838,74 +838,74 @@ sub buddylist_read
|
|||
weechat::print("",weechat::prefix("error")."$prgname: $buddylist is not valid or uses old format (new format: servername.nickname).");
|
||||
return;
|
||||
}
|
||||
$nick_structure{$servername}{$nickname}{status} = 2 if length $_; # status offline
|
||||
$nick_structure{$servername}{$nickname}{status} = 2 if length $_; # status offline
|
||||
$nick_structure{$servername}{$nickname}{bitlbee_service} = "";
|
||||
}
|
||||
close WL;
|
||||
}
|
||||
sub buddylist_save {
|
||||
my $buddylist = weechat_dir();
|
||||
my $buddylist = weechat_dir();
|
||||
if ($buddylist eq "")
|
||||
{
|
||||
weechat::print("","Please set a valid filename : /set plugins.var.perl.buddylist.buddylist");
|
||||
return;
|
||||
}
|
||||
open (WL, ">", $buddylist) || DEBUG("write buddylist: $!");
|
||||
foreach my $s ( sort keys %nick_structure ) { # sortiert die Server alphabetisch
|
||||
foreach my $n ( sort keys %{$nick_structure{$s}} ) { # sortiert die Nicks alphabetisch
|
||||
print WL "$s.$n\n"; # save as servername.nickname
|
||||
}
|
||||
}
|
||||
close WL;
|
||||
open (WL, ">", $buddylist) || DEBUG("write buddylist: $!");
|
||||
foreach my $s ( sort keys %nick_structure ) { # sortiert die Server alphabetisch
|
||||
foreach my $n ( sort keys %{$nick_structure{$s}} ) { # sortiert die Nicks alphabetisch
|
||||
print WL "$s.$n\n"; # save as servername.nickname
|
||||
}
|
||||
}
|
||||
close WL;
|
||||
}
|
||||
|
||||
# changes in settings hooked by hook_config()?
|
||||
sub toggled_by_set{
|
||||
my ( $pointer, $option, $value ) = @_;
|
||||
my ( $pointer, $option, $value ) = @_;
|
||||
|
||||
if ($option eq "plugins.var.perl.$prgname.hide.server.if.buddies.offline"){
|
||||
$default_options{hide_server} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.hide.buddy.if.offline"){
|
||||
$default_options{hide_buddy} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.sort"){
|
||||
$default_options{sort} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.hide.bar"){
|
||||
$default_options{hide_bar} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.default"){
|
||||
$default_options{color_default} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.server"){
|
||||
$default_options{color_server_online} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.server.offline"){
|
||||
$default_options{color_server_offline} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.away"){
|
||||
$default_color_buddylist{"away"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.offline"){
|
||||
$default_color_buddylist{"offline"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.online"){
|
||||
$default_color_buddylist{"online"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.number"){
|
||||
$default_options{"color_number"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.show.query"){
|
||||
$default_options{"show_query"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.buddy.on.server"){
|
||||
$default_options{"buddy_on_server"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.buddy.on.server.color"){
|
||||
$default_options{"buddy_on_server_color"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.check.buddies"){
|
||||
$default_options{"check_buddies"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.callback.timeout"){
|
||||
$default_options{"callback_timeout"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.use.redirection"){
|
||||
$default_options{"use_redirection"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.display.original.nick"){
|
||||
$default_options{"display_original_nick"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.display.social.net"){
|
||||
if ($option eq "plugins.var.perl.$prgname.hide.server.if.buddies.offline"){
|
||||
$default_options{hide_server} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.hide.buddy.if.offline"){
|
||||
$default_options{hide_buddy} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.sort"){
|
||||
$default_options{sort} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.hide.bar"){
|
||||
$default_options{hide_bar} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.default"){
|
||||
$default_options{color_default} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.server"){
|
||||
$default_options{color_server_online} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.server.offline"){
|
||||
$default_options{color_server_offline} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.away"){
|
||||
$default_color_buddylist{"away"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.offline"){
|
||||
$default_color_buddylist{"offline"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.online"){
|
||||
$default_color_buddylist{"online"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.color.number"){
|
||||
$default_options{"color_number"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.show.query"){
|
||||
$default_options{"show_query"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.buddy.on.server"){
|
||||
$default_options{"buddy_on_server"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.buddy.on.server.color"){
|
||||
$default_options{"buddy_on_server_color"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.check.buddies"){
|
||||
$default_options{"check_buddies"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.callback.timeout"){
|
||||
$default_options{"callback_timeout"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.use.redirection"){
|
||||
$default_options{"use_redirection"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.display.original.nick"){
|
||||
$default_options{"display_original_nick"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.display.social.net"){
|
||||
$default_options{"display_social_net"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.display.social.net.color"){
|
||||
$default_options{"display_social_net_color"} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.debug.redir.out"){
|
||||
$debug_redir_out = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.text.online"){
|
||||
$debug_redir_out = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.text.online"){
|
||||
$default_options{text_online} = $value;
|
||||
}elsif ($option eq "plugins.var.perl.$prgname.text.away"){
|
||||
$default_options{text_away} = $value;
|
||||
|
@ -922,23 +922,23 @@ sub toggled_by_set{
|
|||
weechat::bar_item_update($prgname);
|
||||
|
||||
# check Hooks()
|
||||
if ($default_options{check_buddies} ne "0" and $default_options{use_redirection} eq "on"){
|
||||
if (defined $Hooks{timer} and defined $Hooks{redirect}){
|
||||
unhook_timer();
|
||||
hook_timer_and_redirect();
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
if ($default_options{check_buddies} ne "0" and $default_options{use_redirection} eq "on"){
|
||||
if (defined $Hooks{timer} and defined $Hooks{redirect}){
|
||||
unhook_timer();
|
||||
hook_timer_and_redirect();
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if ($default_options{check_buddies} eq "0" or $default_options{use_redirection} ne "on"){
|
||||
if (defined $Hooks{timer} and defined $Hooks{redirect}){
|
||||
unhook_timer();
|
||||
}
|
||||
}else{
|
||||
if (not defined $Hooks{timer} or not defined $Hooks{redirect}){
|
||||
weechat::config_set_plugin("check.buddies", "0") unless hook_timer_and_redirect(); # fall back to '0', if hook fails
|
||||
}
|
||||
}
|
||||
if ($default_options{check_buddies} eq "0" or $default_options{use_redirection} ne "on"){
|
||||
if (defined $Hooks{timer} and defined $Hooks{redirect}){
|
||||
unhook_timer();
|
||||
}
|
||||
}else{
|
||||
if (not defined $Hooks{timer} or not defined $Hooks{redirect}){
|
||||
weechat::config_set_plugin("check.buddies", "0") unless hook_timer_and_redirect(); # fall back to '0', if hook fails
|
||||
}
|
||||
}
|
||||
|
||||
weechat::bar_item_update($prgname);
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
|
@ -1161,7 +1161,7 @@ sub init{
|
|||
|
||||
# hide bar when buddylist was closed
|
||||
sub shutdown{
|
||||
weechat::command("", "/bar hide " . $prgname);
|
||||
weechat::command("", "/bar hide " . $prgname);
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
|
@ -1169,25 +1169,25 @@ sub DEBUG {weechat::print('', "***\t" . $_[0]);}
|
|||
|
||||
sub hook_timer_and_redirect{
|
||||
|
||||
if ($default_version eq 1){ # if weechat is <= 0.3.4 no hooks() will be installed. Means no redirection!
|
||||
$Hooks{redirect} = weechat::hook_hsignal("irc_redirection_buddylist_whois", "redirect_whois", ""); # install hsignal()
|
||||
if ($Hooks{redirect} eq '')
|
||||
{
|
||||
weechat::print("",weechat::prefix("error")."hook failed. can't enable hook_hsignal() for $prgname.");
|
||||
return 0;
|
||||
}
|
||||
$Hooks{timer} = weechat::hook_timer($default_options{check_buddies} * 1000 * 1, 0, 0, "call_whois_all", ""); # period * millisec(1000) * second(1) * minutes(0)
|
||||
if ($Hooks{timer} eq '')
|
||||
{
|
||||
weechat::print("",weechat::prefix("error")."hook failed. can't enable hook_timer() for $prgname.");
|
||||
if (defined $Hooks{redirect}){
|
||||
weechat::unhook($Hooks{redirect});
|
||||
delete $Hooks{redirect};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if ($default_version eq 1){ # if weechat is <= 0.3.4 no hooks() will be installed. Means no redirection!
|
||||
$Hooks{redirect} = weechat::hook_hsignal("irc_redirection_buddylist_whois", "redirect_whois", ""); # install hsignal()
|
||||
if ($Hooks{redirect} eq '')
|
||||
{
|
||||
weechat::print("",weechat::prefix("error")."hook failed. can't enable hook_hsignal() for $prgname.");
|
||||
return 0;
|
||||
}
|
||||
$Hooks{timer} = weechat::hook_timer($default_options{check_buddies} * 1000 * 1, 0, 0, "call_whois_all", ""); # period * millisec(1000) * second(1) * minutes(0)
|
||||
if ($Hooks{timer} eq '')
|
||||
{
|
||||
weechat::print("",weechat::prefix("error")."hook failed. can't enable hook_timer() for $prgname.");
|
||||
if (defined $Hooks{redirect}){
|
||||
weechat::unhook($Hooks{redirect});
|
||||
delete $Hooks{redirect};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub unhook_timer
|
||||
|
@ -1218,45 +1218,45 @@ sub call_whois_one
|
|||
sub call_whois_all{
|
||||
my $int_count = 0;
|
||||
my $foreach_count = 0;
|
||||
# sort server and check if server is online
|
||||
foreach my $server ( sort keys %nick_structure ){ # sort server (a-z)
|
||||
my $color_server = get_server_status($server); # get server status
|
||||
if ($color_server eq $default_options{color_server_offline} or $color_server eq "1"){# server is offline
|
||||
next; # goto next server
|
||||
}
|
||||
# sort nick structure and call /whois
|
||||
foreach my $nickname ( keys %{$nick_structure{$server}} ) { # sort nicks (a-z)
|
||||
if (not defined $nick_structure{$server}{$nickname}{counter} or $nick_structure{$server}{$nickname}{counter} eq 0){
|
||||
delete $nick_structure{$server}{$nickname} if ( $nickname eq ":seconds" ); # wrong parsing!?
|
||||
next if ( $nickname eq ":seconds" ); # wrong parsing!?
|
||||
$nick_structure{$server}{$nickname}{counter} = 1;
|
||||
$foreach_count = 1;
|
||||
$int_count = 1;
|
||||
# sort server and check if server is online
|
||||
foreach my $server ( sort keys %nick_structure ){ # sort server (a-z)
|
||||
my $color_server = get_server_status($server); # get server status
|
||||
if ($color_server eq $default_options{color_server_offline} or $color_server eq "1"){# server is offline
|
||||
next; # goto next server
|
||||
}
|
||||
# sort nick structure and call /whois
|
||||
foreach my $nickname ( keys %{$nick_structure{$server}} ) { # sort nicks (a-z)
|
||||
if (not defined $nick_structure{$server}{$nickname}{counter} or $nick_structure{$server}{$nickname}{counter} eq 0){
|
||||
delete $nick_structure{$server}{$nickname} if ( $nickname eq ":seconds" ); # wrong parsing!?
|
||||
next if ( $nickname eq ":seconds" ); # wrong parsing!?
|
||||
$nick_structure{$server}{$nickname}{counter} = 1;
|
||||
$foreach_count = 1;
|
||||
$int_count = 1;
|
||||
|
||||
next if ($server eq "" or $nickname eq "");
|
||||
next if ($server eq "" or $nickname eq "");
|
||||
|
||||
# calling hsignal(redirect)
|
||||
my $hash = { "server" => $server, "pattern" => "whois", "signal" => "buddylist",
|
||||
"count" => "1", "string" => $nickname, "timeout" => $default_options{callback_timeout}, "cmd_filter" => "" };
|
||||
weechat::hook_hsignal_send("irc_redirect_command", $hash);
|
||||
weechat::hook_signal_send("irc_input_send", weechat::WEECHAT_HOOK_SIGNAL_STRING, $server.";;2;;/whois ".$nickname); #server;channel;flags;tags;text
|
||||
# calling hsignal(redirect)
|
||||
my $hash = { "server" => $server, "pattern" => "whois", "signal" => "buddylist",
|
||||
"count" => "1", "string" => $nickname, "timeout" => $default_options{callback_timeout}, "cmd_filter" => "" };
|
||||
weechat::hook_hsignal_send("irc_redirect_command", $hash);
|
||||
weechat::hook_signal_send("irc_input_send", weechat::WEECHAT_HOOK_SIGNAL_STRING, $server.";;2;;/whois ".$nickname); #server;channel;flags;tags;text
|
||||
|
||||
last; # jump to end of list
|
||||
}else{
|
||||
next;
|
||||
}
|
||||
last; # jump to end of list
|
||||
}else{
|
||||
next;
|
||||
}
|
||||
|
||||
}
|
||||
last if ($foreach_count eq 1);
|
||||
}
|
||||
}
|
||||
last if ($foreach_count eq 1);
|
||||
}
|
||||
# set counter for each buddy back to zero to start count from beginning
|
||||
if ($int_count eq 0){
|
||||
$int_count = 0;
|
||||
foreach my $server ( sort keys %nick_structure ){ # sort server (a-z)
|
||||
foreach my $nickname ( sort keys %{$nick_structure{$server}} ) { # sort nicks (a-z)
|
||||
$nick_structure{$server}{$nickname}{counter} = 0;
|
||||
}
|
||||
}
|
||||
foreach my $server ( sort keys %nick_structure ){ # sort server (a-z)
|
||||
foreach my $nickname ( sort keys %{$nick_structure{$server}} ) { # sort nicks (a-z)
|
||||
$nick_structure{$server}{$nickname}{counter} = 0;
|
||||
}
|
||||
}
|
||||
$foreach_count = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1292,13 +1292,13 @@ sub redirect_whois{
|
|||
}
|
||||
|
||||
# check if buddy is online and look for visiting channels
|
||||
my $rfc_319 = "319"; # rfc number containing channels
|
||||
my ( $nickname,$channel_name ) = parse_redirect($hashtable{"server"},$rfc_319,$hashtable{"output"}); # check redirection output for channels
|
||||
return weechat::WEECHAT_RC_OK if ( $channel_name eq -1 ); # -1 = buddy not online
|
||||
my $rfc_319 = "319"; # rfc number containing channels
|
||||
my ( $nickname,$channel_name ) = parse_redirect($hashtable{"server"},$rfc_319,$hashtable{"output"}); # check redirection output for channels
|
||||
return weechat::WEECHAT_RC_OK if ( $channel_name eq -1 ); # -1 = buddy not online
|
||||
|
||||
if ($channel_name eq -2 and exists $nick_structure{$hashtable{"server"}}{$main_nickname}){
|
||||
my $sorted_numbers = check_query_buffer($hashtable{"server"},$main_nickname,"");
|
||||
$nick_structure{$hashtable{"server"}}{$main_nickname}{buffer} = "()" if ($sorted_numbers eq ""); # buddy online but not in a channel
|
||||
$nick_structure{$hashtable{"server"}}{$main_nickname}{buffer} = "()" if ($sorted_numbers eq ""); # buddy online but not in a channel
|
||||
$nick_structure{$hashtable{"server"}}{$main_nickname}{buffer} = $sorted_numbers if ($sorted_numbers ne ""); # /query buffer open
|
||||
}else{
|
||||
check_for_channels($hashtable{"server"}, $main_nickname, $channel_name);
|
||||
|
@ -1321,18 +1321,18 @@ sub check_for_channels{
|
|||
|
||||
# check out if buddy is in same channels as you are
|
||||
my @buf_count;
|
||||
$nick_structure{$server}{$nickname}{buffer} = "()"; # delete buffer number in nick_structure{buffer]
|
||||
$nick_structure{$server}{$nickname}{buffer} = "()"; # delete buffer number in nick_structure{buffer]
|
||||
|
||||
foreach (@array){
|
||||
my $buffer_pointer = weechat::buffer_search("irc", $server . "." . $_);
|
||||
if ($buffer_pointer ne ""){ # buffer exists?
|
||||
if ($buffer_pointer ne ""){ # buffer exists?
|
||||
my $buffer_number = search_buffer_number($buffer_pointer);# check if buddy is in same channels as you
|
||||
if ($buffer_number ne 0){
|
||||
push @buf_count,($buffer_number) ;
|
||||
# check if option "color.number" has valid entry and write buffer number to nick_structure
|
||||
if ($default_options{color_number} ne ""){ # color for color_number set?
|
||||
if ($default_options{color_number} ne ""){ # color for color_number set?
|
||||
@buf_count = del_double(@buf_count);
|
||||
my $sorted_numbers = join(",",sort{$a<=>$b}(@buf_count)); # channel numbers (1,2....)
|
||||
my $sorted_numbers = join(",",sort{$a<=>$b}(@buf_count)); # channel numbers (1,2....)
|
||||
$sorted_numbers = check_query_buffer($server,$nickname,$sorted_numbers);
|
||||
$nick_structure{$server}{$nickname}{buffer} = $sorted_numbers;# save buffer number in nick_structure{buffer]
|
||||
}
|
||||
|
@ -1373,48 +1373,48 @@ return $sorted_numbers;
|
|||
# search buffer
|
||||
sub search_buffer_number{
|
||||
my ( $buffer_name ) = @_;
|
||||
my $infolist_buffer = weechat::infolist_get("buffer",$buffer_name,""); # get infolist_pointer for buffer
|
||||
my $infolist_buffer = weechat::infolist_get("buffer",$buffer_name,""); # get infolist_pointer for buffer
|
||||
weechat::infolist_next($infolist_buffer);
|
||||
my $buffer_number = weechat::infolist_integer($infolist_buffer,"number"); # get buffer_number
|
||||
weechat::infolist_free($infolist_buffer); # don't forget to free infolist ;-)
|
||||
my $buffer_number = weechat::infolist_integer($infolist_buffer,"number"); # get buffer_number
|
||||
weechat::infolist_free($infolist_buffer); # don't forget to free infolist ;-)
|
||||
|
||||
return $buffer_number;
|
||||
}
|
||||
|
||||
# checks if buddy is connected to server and look for $rfc line from /whois redirection
|
||||
# :anthony.freenode.net 330 mynick 2nd_nick 1st_nick :is logged in as # [2nd_nick] is logged in as 1st_nick
|
||||
# :anthony.freenode.net 330 mynick 2nd_nick 1st_nick :is logged in as # [2nd_nick] is logged in as 1st_nick
|
||||
sub parse_redirect{
|
||||
my ( $servername,$rfc,$args ) = @_;
|
||||
|
||||
return ("",-1) if (not defined $servername or $servername eq "");
|
||||
# nick is not online
|
||||
my $rfc_401 = " 401 "; # No such nick/channel
|
||||
my $rfc_401 = " 401 "; # No such nick/channel
|
||||
$args =~ /($rfc_401)(.*?) (.*?) (.*)\n/;
|
||||
if (defined $1 and $1 eq $rfc_401 and defined $3){
|
||||
$nick_structure{$servername}{$3}{status} = 2; # buddy offline
|
||||
$nick_structure{$servername}{$3}{buffer} = ""; # clear buffer number
|
||||
$nick_structure{$servername}{$3}{buf_name} = ""; # clear name of buffer
|
||||
$nick_structure{$servername}{$3}{status} = 2; # buddy offline
|
||||
$nick_structure{$servername}{$3}{buffer} = ""; # clear buffer number
|
||||
$nick_structure{$servername}{$3}{buf_name} = ""; # clear name of buffer
|
||||
return ("",-1);
|
||||
}
|
||||
|
||||
my $rfc_301 = " 301 "; # nick :away
|
||||
my $rfc_301 = " 301 "; # nick :away
|
||||
### part for bitlbee
|
||||
# bitlbee offline check
|
||||
# :localhost 312 nils_2 nickname mail@gmail.com. :jabber network
|
||||
# :localhost 301 nils_2 nickname :User is offline
|
||||
my $rfc_312 = " 312 "; # 312 nick server :info
|
||||
my $offline_text = "(:User is offline|:Offline)\n"; # (bitlbee|bitlbee-libpurple)
|
||||
my $network = "(:msn|:jabber|:yahoo)"; # possible networks
|
||||
my $rfc_312 = " 312 "; # 312 nick server :info
|
||||
my $offline_text = "(:User is offline|:Offline)\n"; # (bitlbee|bitlbee-libpurple)
|
||||
my $network = "(:msn|:jabber|:yahoo)"; # possible networks
|
||||
my ($a1,$a2,$a3,$a4) = "";
|
||||
($a1,$a2,$a3,$a4) = ($args =~ /(.*)($rfc_312)(.*)($network)/);
|
||||
if ( defined $a4 and $a4 ne ""){
|
||||
($a1,$a2,$a3,$a4) = "";
|
||||
($a1,$a2,$a3,$a4) = ($args =~ /($rfc_301)(.*?) (.*?) ($offline_text)/);
|
||||
if ( defined $a4 and $a4 ne ""){
|
||||
$nick_structure{$servername}{$a3}{status} = 2; # buddy offline on bitlbee
|
||||
$nick_structure{$servername}{$a3}{buffer} = ""; # clear buffer number
|
||||
$nick_structure{$servername}{$a3}{buf_name} = ""; # clear name of buffer
|
||||
return ("",-1);
|
||||
$nick_structure{$servername}{$a3}{status} = 2; # buddy offline on bitlbee
|
||||
$nick_structure{$servername}{$a3}{buffer} = ""; # clear buffer number
|
||||
$nick_structure{$servername}{$a3}{buf_name} = ""; # clear name of buffer
|
||||
return ("",-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1444,70 +1444,70 @@ if ( $default_options{display_social_net} eq "on" ){
|
|||
### bitlbee part end
|
||||
|
||||
if ( $default_options{display_original_nick} eq "on" ){
|
||||
my $rfc_330 = " 330 "; # nick :is logged in as
|
||||
my $rfc_330 = " 330 "; # nick :is logged in as
|
||||
# check if nick has a different nick name (/nick blafasel)
|
||||
$args =~ /($rfc_330)(.*?) (.*?) (.*?) :(.*)\n/; # non-greedy
|
||||
$args =~ /($rfc_330)(.*?) (.*?) (.*?) :(.*)\n/; # non-greedy
|
||||
my $nickname_as = $3;
|
||||
my $nickname = $4;
|
||||
|
||||
if ( defined $nickname_as and defined $nickname and $nickname_as ne $nickname ){
|
||||
if ( exists $nick_structure{$servername}{$nickname} ){
|
||||
$args =~ /($rfc_301)/;
|
||||
if (defined $1 and $1 eq $rfc_301){ # buddy is away
|
||||
return ($nickname,-1) if (not defined $nickname or not exists $nick_structure{$servername}{$nickname}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname}{status} = 1; # buddy away
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 2 if (exists $nick_structure{$servername}{$nickname_as} ); # set alias nick to offline
|
||||
}else{
|
||||
return ($nickname,-1) if (not defined $nickname or not exists $nick_structure{$servername}{$nickname}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname}{status} = 0; # buddy is online
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 2 if (exists $nick_structure{$servername}{$nickname_as} ); # set alias nick to offline
|
||||
}
|
||||
$args =~ /($rfc_301)/;
|
||||
if (defined $1 and $1 eq $rfc_301){ # buddy is away
|
||||
return ($nickname,-1) if (not defined $nickname or not exists $nick_structure{$servername}{$nickname}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname}{status} = 1; # buddy away
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 2 if (exists $nick_structure{$servername}{$nickname_as} ); # set alias nick to offline
|
||||
}else{
|
||||
return ($nickname,-1) if (not defined $nickname or not exists $nick_structure{$servername}{$nickname}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname}{status} = 0; # buddy is online
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 2 if (exists $nick_structure{$servername}{$nickname_as} ); # set alias nick to offline
|
||||
}
|
||||
}elsif ( exists $nick_structure{$servername}{$nickname_as} ){
|
||||
$args =~ /($rfc_301)/;
|
||||
if (defined $1 and $1 eq $rfc_301){ # buddy is away
|
||||
return ($nickname_as,-1) if (not defined $nickname_as or not exists $nick_structure{$servername}{$nickname_as}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 1; # buddy away
|
||||
$nickname = $nickname_as;
|
||||
}else{
|
||||
return ($nickname_as,-1) if (not defined $nickname_as or not exists $nick_structure{$servername}{$nickname_as}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 0; # buddy is online
|
||||
$nickname = $nickname_as;
|
||||
}
|
||||
$args =~ /($rfc_301)/;
|
||||
if (defined $1 and $1 eq $rfc_301){ # buddy is away
|
||||
return ($nickname_as,-1) if (not defined $nickname_as or not exists $nick_structure{$servername}{$nickname_as}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 1; # buddy away
|
||||
$nickname = $nickname_as;
|
||||
}else{
|
||||
return ($nickname_as,-1) if (not defined $nickname_as or not exists $nick_structure{$servername}{$nickname_as}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname_as}{status} = 0; # buddy is online
|
||||
$nickname = $nickname_as;
|
||||
}
|
||||
}
|
||||
|
||||
$rfc = " " . $rfc . " "; # space at beginning and end of requested rfc
|
||||
$rfc = " " . $rfc . " "; # space at beginning and end of requested rfc
|
||||
|
||||
if ($args =~ /($rfc)(.*?) (.*?) (.*)\n/){ # non-greedy
|
||||
if (not defined $4){
|
||||
return ($nickname,-2); # buddy online but not visiting a channel
|
||||
}
|
||||
return ($nickname,$4); # return data (for example channel names)
|
||||
}else{
|
||||
return ($nickname,-2); # buddy online but not visiting a channel
|
||||
}
|
||||
if ($args =~ /($rfc)(.*?) (.*?) (.*)\n/){ # non-greedy
|
||||
if (not defined $4){
|
||||
return ($nickname,-2); # buddy online but not visiting a channel
|
||||
}
|
||||
return ($nickname,$4); # return data (for example channel names)
|
||||
}else{
|
||||
return ($nickname,-2); # buddy online but not visiting a channel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# get nick name
|
||||
my $rfc_311 = " 311 "; # nick username address * :info
|
||||
my (undef, undef, undef, $nickname2, undef) = split /\s+/, $args, 5 if ($args =~ /($rfc_311)/); # get nickname
|
||||
my $rfc_311 = " 311 "; # nick username address * :info
|
||||
my (undef, undef, undef, $nickname2, undef) = split /\s+/, $args, 5 if ($args =~ /($rfc_311)/); # get nickname
|
||||
|
||||
# check nick away....
|
||||
$args =~ /($rfc_301)/;
|
||||
if (defined $1 and $1 eq $rfc_301){ # buddy is away
|
||||
return ($nickname2,-1) if (not defined $nickname2 or not exists $nick_structure{$servername}{$nickname2}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname2}{status} = 1; # buddy away
|
||||
if (defined $1 and $1 eq $rfc_301){ # buddy is away
|
||||
return ($nickname2,-1) if (not defined $nickname2 or not exists $nick_structure{$servername}{$nickname2}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname2}{status} = 1; # buddy away
|
||||
}else{
|
||||
return ($nickname2,-1) if (not defined $nickname2 or not exists $nick_structure{$servername}{$nickname2}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname2}{status} = 0; # buddy is online
|
||||
return ($nickname2,-1) if (not defined $nickname2 or not exists $nick_structure{$servername}{$nickname2}); # does nick exists in nick_structure? NO?
|
||||
$nick_structure{$servername}{$nickname2}{status} = 0; # buddy is online
|
||||
}
|
||||
|
||||
$rfc = " " . $rfc . " "; # space at beginning and end of requested rfc
|
||||
$args =~ /($rfc)(.*?) (.*?) (.*)\n/; # non-greedy
|
||||
$rfc = " " . $rfc . " "; # space at beginning and end of requested rfc
|
||||
$args =~ /($rfc)(.*?) (.*?) (.*)\n/; # non-greedy
|
||||
if (not defined $4){
|
||||
return ($nickname2,-2); # buddy online but not visiting a channel
|
||||
return ($nickname2,-2); # buddy online but not visiting a channel
|
||||
}
|
||||
return ($nickname2,$4); # return data (for example channel names)
|
||||
return ($nickname2,$4); # return data (for example channel names)
|
||||
}
|
||||
|
||||
sub buddy_list_completion_cb{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#
|
||||
# highmon.pl - Highlight Monitoring for weechat 0.3.0
|
||||
# Version 2.5
|
||||
# Version 2.6
|
||||
#
|
||||
# Add 'Highlight Monitor' buffer/bar to log all highlights in one spot
|
||||
#
|
||||
|
@ -73,6 +73,8 @@
|
|||
# Bugs and feature requests at: https://github.com/KenjiE20/highmon
|
||||
|
||||
# History:
|
||||
# 2019-05-13, HubbeKing <hubbe128@gmail.com>
|
||||
# v2.6: -add: send "logger_backlog" signal on buffer open if logging is enabled
|
||||
# 2014-08-16, KenjiE20 <longbow@longbowslair.co.uk>:
|
||||
# v2.5: -add: clearbar command to clear bar output
|
||||
# -add: firstrun output prompt to check the help text for set up hints as they were being missed
|
||||
|
@ -306,7 +308,7 @@ sub highmon_buffer_open
|
|||
# Turn off notify, highlights
|
||||
if ($highmon_buffer ne "")
|
||||
{
|
||||
if (weechat::config_get_plugin("hotlist_show" eq "off"))
|
||||
if (weechat::config_get_plugin("hotlist_show") eq "off")
|
||||
{
|
||||
weechat::buffer_set($highmon_buffer, "notify", "0");
|
||||
}
|
||||
|
@ -317,6 +319,11 @@ sub highmon_buffer_open
|
|||
{
|
||||
weechat::buffer_set($highmon_buffer, "localvar_set_no_log", "1");
|
||||
}
|
||||
# send "logger_backlog" signal if logging is enabled to display backlog
|
||||
if (weechat::config_get_plugin("logging") eq "on")
|
||||
{
|
||||
weechat::hook_signal_send("logger_backlog", weechat::WEECHAT_HOOK_SIGNAL_POINTER, $highmon_buffer)
|
||||
}
|
||||
}
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
@ -1124,7 +1131,7 @@ sub format_buffer_name
|
|||
}
|
||||
|
||||
# Check result of register, and attempt to behave in a sane manner
|
||||
if (!weechat::register("highmon", "KenjiE20", "2.5", "GPL3", "Highlight Monitor", "", ""))
|
||||
if (!weechat::register("highmon", "KenjiE20", "2.6", "GPL3", "Highlight Monitor", "", ""))
|
||||
{
|
||||
# Double load
|
||||
weechat::print ("", "\tHighmon is already loaded");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#
|
||||
# Copyright (C) 2008-2014 Sebastien Helleu <flashcode@flashtux.org>
|
||||
# Copyright (C) 2010-2014 Nils Görs <weechatter@arcor.de>
|
||||
# Copyright (C) 2008-2017 Sebastien Helleu <flashcode@flashtux.org>
|
||||
# Copyright (C) 2010-2017 Nils Görs <weechatter@arcor.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -19,6 +19,21 @@
|
|||
#
|
||||
# History:
|
||||
#
|
||||
# 2017-04-14, nils_2 <freenode.#weechat>
|
||||
# version 4.3: add option "use_color" (https://github.com/weechat/scripts/issues/93)
|
||||
# 2016-07-08, nils_2 <weechatter@arcor.de>
|
||||
# version 4.2: add diff function
|
||||
# 2016-02-06, Sebastien Helleu <flashcode@flashtux.org>:
|
||||
# version 4.1: remove debug print
|
||||
# 2015-12-24, Sebastien Helleu <flashcode@flashtux.org>:
|
||||
# version 4.0: add support of parent options (inherited values in irc servers)
|
||||
# with WeeChat >= 1.4
|
||||
# 2015-05-16, Sebastien Helleu <flashcode@flashtux.org>:
|
||||
# version 3.9: fix cursor position when editing an option with WeeChat >= 1.2
|
||||
# 2015-05-02, arza <arza@arza.us>:
|
||||
# version 3.8: don't append "null" to /set when setting an undefined setting
|
||||
# 2015-05-01, nils_2 <weechatter@arcor.de>:
|
||||
# version 3.7: fix two perl warnings (reported by t3chguy)
|
||||
# 2014-09-30, arza <arza@arza.us>:
|
||||
# version 3.6: fix current line counter when options aren't found
|
||||
# 2014-06-03, nils_2 <weechatter@arcor.de>:
|
||||
|
@ -117,7 +132,7 @@
|
|||
use strict;
|
||||
|
||||
my $PRGNAME = "iset";
|
||||
my $VERSION = "3.6";
|
||||
my $VERSION = "4.3";
|
||||
my $DESCR = "Interactive Set for configuration options";
|
||||
my $AUTHOR = "Sebastien Helleu <flashcode\@flashtux.org>";
|
||||
my $LICENSE = "GPL3";
|
||||
|
@ -129,9 +144,11 @@ my $iset_buffer = "";
|
|||
my $wee_version_number = 0;
|
||||
my @iset_focus = ();
|
||||
my @options_names = ();
|
||||
my @options_parent_names = ();
|
||||
my @options_types = ();
|
||||
my @options_values = ();
|
||||
my @options_default_values = ();
|
||||
my @options_parent_values = ();
|
||||
my @options_is_null = ();
|
||||
my $option_max_length = 0;
|
||||
my $current_line = 0;
|
||||
|
@ -139,7 +156,7 @@ my $filter = "*";
|
|||
my $description = "";
|
||||
my $options_name_copy = "";
|
||||
my $iset_filter_title = "";
|
||||
# search modes: 0 = index() on value, 1 = grep() on value, 2 = grep() on option, 3 = grep on option & value
|
||||
# search modes: 0 = index() on value, 1 = grep() on value, 2 = grep() on option, 3 = grep on option & value, 4 = diff all, 5 = diff parts
|
||||
my $search_mode = 2;
|
||||
my $search_value = "";
|
||||
my $help_text_keys = "alt + space: toggle, +/-: increase/decrease, enter: change, ir: reset, iu: unset, v: toggle help bar";
|
||||
|
@ -189,6 +206,12 @@ sub iset_title
|
|||
$filter = "*" if ($filter eq "");
|
||||
$show_filter = $filter;
|
||||
}
|
||||
elsif ($search_mode == 4 or $search_mode == 5)
|
||||
{
|
||||
$iset_filter_title = "diff: ";
|
||||
$show_filter = "all";
|
||||
$show_filter = $search_value if $search_mode == 5;
|
||||
}
|
||||
elsif ($search_mode eq 3)
|
||||
{
|
||||
$iset_filter_title = "(option) ";
|
||||
|
@ -237,6 +260,10 @@ sub iset_create_filter
|
|||
sub iset_buffer_input
|
||||
{
|
||||
my ($data, $buffer, $string) = ($_[0], $_[1], $_[2]);
|
||||
|
||||
# string begins with space?
|
||||
return weechat::WEECHAT_RC_OK if (substr($string, 0, 1 ) eq " ");
|
||||
|
||||
if ($string eq "q")
|
||||
{
|
||||
weechat::buffer_close($buffer);
|
||||
|
@ -257,10 +284,27 @@ sub iset_buffer_input
|
|||
weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value);
|
||||
}
|
||||
}
|
||||
# show all diff values
|
||||
elsif ($string eq "d")
|
||||
{
|
||||
$search_mode = 4;
|
||||
# iset_title();
|
||||
iset_create_filter("*");
|
||||
iset_get_options("*");
|
||||
}
|
||||
elsif ( $array_count >= 2 and $cmd_array[0] eq "d")
|
||||
{
|
||||
$search_mode = 5;
|
||||
$search_value = substr($cmd_array[1], 0); # cut value_search_char
|
||||
$search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char
|
||||
iset_create_filter($search_value);
|
||||
iset_get_options($search_value);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$search_mode = 2;
|
||||
if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s")
|
||||
if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s" )
|
||||
{
|
||||
if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"})
|
||||
or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) )
|
||||
|
@ -274,7 +318,8 @@ sub iset_buffer_input
|
|||
{
|
||||
iset_create_filter($string);
|
||||
iset_get_options($search_value);
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
iset_create_filter($string);
|
||||
iset_get_options("");
|
||||
|
@ -343,9 +388,11 @@ sub iset_get_options
|
|||
$search_value = $var_value;
|
||||
@iset_focus = ();
|
||||
@options_names = ();
|
||||
@options_parent_names = ();
|
||||
@options_types = ();
|
||||
@options_values = ();
|
||||
@options_default_values = ();
|
||||
@options_parent_values = ();
|
||||
@options_is_null = ();
|
||||
$option_max_length = 0;
|
||||
my %options_internal = ();
|
||||
|
@ -361,34 +408,61 @@ sub iset_get_options
|
|||
{
|
||||
$key = sprintf("%08d", $i);
|
||||
my $name = weechat::infolist_string($infolist, "full_name");
|
||||
my $parent_name = weechat::infolist_string($infolist, "parent_name");
|
||||
next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
|
||||
my $type = weechat::infolist_string($infolist, "type");
|
||||
my $value = weechat::infolist_string($infolist, "value");
|
||||
my $default_value = weechat::infolist_string($infolist, "default_value");
|
||||
my $parent_value;
|
||||
if ($parent_name && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value"))))
|
||||
{
|
||||
$parent_value = weechat::infolist_string($infolist, "parent_value");
|
||||
}
|
||||
my $is_null = weechat::infolist_integer($infolist, "value_is_null");
|
||||
|
||||
if ($search_mode == 3)
|
||||
{
|
||||
my $value = weechat::infolist_string($infolist, "value");
|
||||
if ( grep /\Q$var_value/,lc($value) )
|
||||
{
|
||||
$options_internal{$name}{"parent_name"} = $parent_name;
|
||||
$options_internal{$name}{"type"} = $type;
|
||||
$options_internal{$name}{"value"} = $value;
|
||||
$options_internal{$name}{"default_value"} = $default_value;
|
||||
$options_internal{$name}{"parent_value"} = $parent_value;
|
||||
$options_internal{$name}{"is_null"} = $is_null;
|
||||
$option_max_length = length($name) if (length($name) > $option_max_length);
|
||||
$iset_struct{$key} = $options_internal{$name};
|
||||
push(@iset_focus, $iset_struct{$key});
|
||||
$iset_struct{$key} = $options_internal{$name};
|
||||
push(@iset_focus, $iset_struct{$key});
|
||||
}
|
||||
}
|
||||
# search for diff?
|
||||
elsif ( $search_mode == 4 or $search_mode == 5)
|
||||
{
|
||||
if ($value ne $default_value )
|
||||
{
|
||||
$options_internal{$name}{"parent_name"} = $parent_name;
|
||||
$options_internal{$name}{"type"} = $type;
|
||||
$options_internal{$name}{"value"} = $value;
|
||||
$options_internal{$name}{"default_value"} = $default_value;
|
||||
$options_internal{$name}{"parent_value"} = $parent_value;
|
||||
$options_internal{$name}{"is_null"} = $is_null;
|
||||
$option_max_length = length($name) if (length($name) > $option_max_length);
|
||||
$iset_struct{$key} = $options_internal{$name};
|
||||
push(@iset_focus, $iset_struct{$key});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$options_internal{$name}{"parent_name"} = $parent_name;
|
||||
$options_internal{$name}{"type"} = $type;
|
||||
$options_internal{$name}{"value"} = $value;
|
||||
$options_internal{$name}{"default_value"} = $default_value;
|
||||
$options_internal{$name}{"parent_value"} = $parent_value;
|
||||
$options_internal{$name}{"is_null"} = $is_null;
|
||||
$option_max_length = length($name) if (length($name) > $option_max_length);
|
||||
$iset_struct{$key} = $options_internal{$name};
|
||||
push(@iset_focus, $iset_struct{$key});
|
||||
$iset_struct{$key} = $options_internal{$name};
|
||||
push(@iset_focus, $iset_struct{$key});
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
@ -397,9 +471,11 @@ sub iset_get_options
|
|||
foreach my $name (sort keys %options_internal)
|
||||
{
|
||||
push(@options_names, $name);
|
||||
push(@options_parent_names, $options_internal{$name}{"parent_name"});
|
||||
push(@options_types, $options_internal{$name}{"type"});
|
||||
push(@options_values, $options_internal{$name}{"value"});
|
||||
push(@options_default_values, $options_internal{$name}{"default_value"});
|
||||
push(@options_parent_values, $options_internal{$name}{"parent_value"});
|
||||
push(@options_is_null, $options_internal{$name}{"is_null"});
|
||||
}
|
||||
}
|
||||
|
@ -422,9 +498,11 @@ sub iset_search_values
|
|||
{
|
||||
my ($var_value,$search_mode) = ($_[0],$_[1]);
|
||||
@options_names = ();
|
||||
@options_parent_names = ();
|
||||
@options_types = ();
|
||||
@options_values = ();
|
||||
@options_default_values = ();
|
||||
@options_parent_values = ();
|
||||
@options_is_null = ();
|
||||
$option_max_length = 0;
|
||||
my %options_internal = ();
|
||||
|
@ -433,18 +511,26 @@ sub iset_search_values
|
|||
while (weechat::infolist_next($infolist))
|
||||
{
|
||||
my $name = weechat::infolist_string($infolist, "full_name");
|
||||
my $parent_name = weechat::infolist_string($infolist, "parent_name");
|
||||
next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
|
||||
my $type = weechat::infolist_string($infolist, "type");
|
||||
my $is_null = weechat::infolist_integer($infolist, "value_is_null");
|
||||
my $value = weechat::infolist_string($infolist, "value");
|
||||
my $default_value = weechat::infolist_string($infolist, "default_value");
|
||||
my $parent_value;
|
||||
if ($parent_name && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value"))))
|
||||
{
|
||||
$parent_value = weechat::infolist_string($infolist, "parent_value");
|
||||
}
|
||||
if ($search_mode)
|
||||
{
|
||||
if ( grep /\Q$var_value/,lc($value) )
|
||||
{
|
||||
$options_internal{$name}{"parent_name"} = $parent_name;
|
||||
$options_internal{$name}{"type"} = $type;
|
||||
$options_internal{$name}{"value"} = $value;
|
||||
$options_internal{$name}{"default_value"} = $default_value;
|
||||
$options_internal{$name}{"parent_value"} = $parent_value;
|
||||
$options_internal{$name}{"is_null"} = $is_null;
|
||||
$option_max_length = length($name) if (length($name) > $option_max_length);
|
||||
}
|
||||
|
@ -454,9 +540,11 @@ sub iset_search_values
|
|||
# if ($value =~ /\Q$var_value/si)
|
||||
if (lc($value) eq $var_value)
|
||||
{
|
||||
$options_internal{$name}{"parent_name"} = $parent_name;
|
||||
$options_internal{$name}{"type"} = $type;
|
||||
$options_internal{$name}{"value"} = $value;
|
||||
$options_internal{$name}{"default_value"} = $default_value;
|
||||
$options_internal{$name}{"parent_value"} = $parent_value;
|
||||
$options_internal{$name}{"is_null"} = $is_null;
|
||||
$option_max_length = length($name) if (length($name) > $option_max_length);
|
||||
}
|
||||
|
@ -467,9 +555,11 @@ sub iset_search_values
|
|||
foreach my $name (sort keys %options_internal)
|
||||
{
|
||||
push(@options_names, $name);
|
||||
push(@options_parent_names, $options_internal{$name}{"parent_name"});
|
||||
push(@options_types, $options_internal{$name}{"type"});
|
||||
push(@options_values, $options_internal{$name}{"value"});
|
||||
push(@options_default_values, $options_internal{$name}{"default_value"});
|
||||
push(@options_parent_values, $options_internal{$name}{"parent_value"});
|
||||
push(@options_is_null, $options_internal{$name}{"is_null"});
|
||||
}
|
||||
}
|
||||
|
@ -498,9 +588,11 @@ sub iset_refresh_line
|
|||
my $color1 = weechat::color(weechat::config_color($options_iset{"color_option"}));
|
||||
my $color2 = weechat::color(weechat::config_color($options_iset{"color_type"}));
|
||||
my $color3 = "";
|
||||
my $color4 = "";
|
||||
if ($options_is_null[$y])
|
||||
{
|
||||
$color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef"}));
|
||||
$color4 = weechat::color(weechat::config_color($options_iset{"color_value"}));
|
||||
}
|
||||
elsif ($options_values[$y] ne $options_default_values[$y])
|
||||
{
|
||||
|
@ -517,6 +609,7 @@ sub iset_refresh_line
|
|||
if ($options_is_null[$y])
|
||||
{
|
||||
$color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"}));
|
||||
$color4 = weechat::color(weechat::config_color($options_iset{"color_value_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"}));
|
||||
}
|
||||
elsif ($options_values[$y] ne $options_default_values[$y])
|
||||
{
|
||||
|
@ -528,7 +621,27 @@ sub iset_refresh_line
|
|||
}
|
||||
}
|
||||
my $value = $options_values[$y];
|
||||
$value = "(undef)" if ($options_is_null[$y]);
|
||||
if (weechat::config_boolean($options_iset{"use_color"}) == 1 and $options_types[$y] eq "color")
|
||||
{
|
||||
$value = weechat::color($options_values[$y]) . $options_values[$y];
|
||||
}
|
||||
if ($options_is_null[$y])
|
||||
{
|
||||
$value = "null";
|
||||
if ($options_parent_names[$y])
|
||||
{
|
||||
if (defined $options_parent_values[$y])
|
||||
{
|
||||
my $around_parent = "";
|
||||
$around_parent = "\"" if ($options_types[$y] eq "string");
|
||||
$value .= $color1." -> ".$color4.$around_parent.$options_parent_values[$y].$around_parent;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value .= $color1." -> ".$color3."null";
|
||||
}
|
||||
}
|
||||
}
|
||||
my $strline = sprintf($format,
|
||||
$color1, $options_names[$y], $padding,
|
||||
$color2, $options_types[$y],
|
||||
|
@ -702,6 +815,39 @@ sub iset_get_option_name_index
|
|||
return -1;
|
||||
}
|
||||
|
||||
sub iset_refresh_option
|
||||
{
|
||||
my $option_name = $_[0];
|
||||
my $index = $_[1];
|
||||
my $infolist = weechat::infolist_get("option", "", $option_name);
|
||||
if ($infolist)
|
||||
{
|
||||
weechat::infolist_next($infolist);
|
||||
if (weechat::infolist_fields($infolist))
|
||||
{
|
||||
$options_parent_names[$index] = weechat::infolist_string($infolist, "parent_name");
|
||||
$options_types[$index] = weechat::infolist_string($infolist, "type");
|
||||
$options_values[$index] = weechat::infolist_string($infolist, "value");
|
||||
$options_default_values[$index] = weechat::infolist_string($infolist, "default_value");
|
||||
$options_is_null[$index] = weechat::infolist_integer($infolist, "value_is_null");
|
||||
$options_parent_values[$index] = undef;
|
||||
if ($options_parent_names[$index]
|
||||
&& (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value"))))
|
||||
{
|
||||
$options_parent_values[$index] = weechat::infolist_string($infolist, "parent_value");
|
||||
}
|
||||
iset_refresh_line($index);
|
||||
iset_title() if ($option_name eq "iset.look.show_current_line");
|
||||
}
|
||||
else
|
||||
{
|
||||
iset_full_refresh(1); # if not found, refresh fully without clearing buffer
|
||||
weechat::print_y($iset_buffer, $#options_names + 1, "");
|
||||
}
|
||||
weechat::infolist_free($infolist);
|
||||
}
|
||||
}
|
||||
|
||||
sub iset_config_cb
|
||||
{
|
||||
my ($data, $option_name, $value) = ($_[0], $_[1], $_[2]);
|
||||
|
@ -714,25 +860,14 @@ sub iset_config_cb
|
|||
if ($index >= 0)
|
||||
{
|
||||
# refresh info about changed option
|
||||
my $infolist = weechat::infolist_get("option", "", $option_name);
|
||||
if ($infolist)
|
||||
iset_refresh_option($option_name, $index);
|
||||
# refresh any other option having this changed option as parent
|
||||
foreach my $i (0 .. $#options_names)
|
||||
{
|
||||
weechat::infolist_next($infolist);
|
||||
if (weechat::infolist_fields($infolist))
|
||||
if ($options_parent_names[$i] eq $option_name)
|
||||
{
|
||||
$options_types[$index] = weechat::infolist_string($infolist, "type");
|
||||
$options_values[$index] = weechat::infolist_string($infolist, "value");
|
||||
$options_default_values[$index] = weechat::infolist_string($infolist, "default_value");
|
||||
$options_is_null[$index] = weechat::infolist_integer($infolist, "value_is_null");
|
||||
iset_refresh_line($index);
|
||||
iset_title() if ($option_name eq "iset.look.show_current_line");
|
||||
iset_refresh_option($options_names[$i], $i);
|
||||
}
|
||||
else
|
||||
{
|
||||
iset_full_refresh(1); # if not found, refresh fully without clearing buffer
|
||||
weechat::print_y($iset_buffer, $#options_names + 1, "");
|
||||
}
|
||||
weechat::infolist_free($infolist);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -807,20 +942,37 @@ sub iset_cmd_cb
|
|||
{
|
||||
# f/s option =value
|
||||
# option =value
|
||||
$search_mode = 2;
|
||||
$search_mode = 2; # grep on option
|
||||
if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s")
|
||||
{
|
||||
if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"})
|
||||
or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) )
|
||||
{
|
||||
$search_mode = 3;
|
||||
$search_mode = 3; # grep on option and value
|
||||
$search_value = substr($cmd_array[1], 1); # cut value_search_char
|
||||
$search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char
|
||||
}
|
||||
}
|
||||
|
||||
# show all diff values
|
||||
if ( $args eq "d")
|
||||
{
|
||||
$search_mode = 4;
|
||||
$search_value = "*";
|
||||
$args = $search_value;
|
||||
}
|
||||
if ( $array_count >= 2 and $cmd_array[0] eq "d")
|
||||
{
|
||||
$search_mode = 5;
|
||||
$search_value = substr($cmd_array[1], 0); # cut value_search_char
|
||||
$search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char
|
||||
$args = $search_value;
|
||||
}
|
||||
|
||||
iset_create_filter($args);
|
||||
$filter_set = 1;
|
||||
my $ptrbuf = weechat::buffer_search($LANG, $PRGNAME);
|
||||
|
||||
if ($ptrbuf eq "")
|
||||
{
|
||||
iset_init();
|
||||
|
@ -976,22 +1128,34 @@ sub iset_cmd_cb
|
|||
my $value = $options_values[$current_line];
|
||||
if ($options_is_null[$current_line])
|
||||
{
|
||||
$value = "null";
|
||||
$value = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
$quote = "\"" if ($options_types[$current_line] eq "string");
|
||||
}
|
||||
my $set_command = "/set";
|
||||
$set_command = "/mute " . $set_command if (weechat::config_boolean($options_iset{"use_mute"}) == 1);
|
||||
$value = " ".$quote.$value.$quote if ($value ne "" or $quote ne "");
|
||||
|
||||
weechat::buffer_set($iset_buffer, "input", $set_command." ".$options_names[$current_line]." ".$quote.$value.$quote);
|
||||
weechat::command($iset_buffer, "/input move_beginning_of_line");
|
||||
weechat::command($iset_buffer, "/input move_next_word");
|
||||
weechat::command($iset_buffer, "/input move_next_word");
|
||||
weechat::command($iset_buffer, "/input move_next_word") if (weechat::config_boolean($options_iset{"use_mute"}) == 1);
|
||||
weechat::command($iset_buffer, "/input move_next_char");
|
||||
weechat::command($iset_buffer, "/input move_next_char") if ($quote ne "");
|
||||
my $set_command = "/set";
|
||||
my $start_index = 5;
|
||||
if (weechat::config_boolean($options_iset{"use_mute"}) == 1)
|
||||
{
|
||||
$set_command = "/mute ".$set_command;
|
||||
$start_index += 11;
|
||||
}
|
||||
$set_command = $set_command." ".$options_names[$current_line].$value;
|
||||
my $pos_space = index($set_command, " ", $start_index);
|
||||
if ($pos_space < 0)
|
||||
{
|
||||
$pos_space = 9999;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pos_space = $pos_space + 1;
|
||||
$pos_space = $pos_space + 1 if ($quote ne "");
|
||||
}
|
||||
weechat::buffer_set($iset_buffer, "input", $set_command);
|
||||
weechat::buffer_set($iset_buffer, "input_pos", "".$pos_space);
|
||||
}
|
||||
}
|
||||
weechat::bar_item_update("isetbar_help") if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1);
|
||||
|
@ -1162,6 +1326,8 @@ sub iset_hsignal_mouse_cb
|
|||
{
|
||||
my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
|
||||
|
||||
return weechat::WEECHAT_RC_OK unless (@options_types);
|
||||
|
||||
if ($hash{"_buffer_name"} eq $PRGNAME && ($hash{"_buffer_plugin"} eq $LANG))
|
||||
{
|
||||
if ($hash{"_key"} eq "button1")
|
||||
|
@ -1349,6 +1515,10 @@ sub iset_config_init
|
|||
$iset_config_file, $section_look,
|
||||
"use_mute", "boolean", "/mute command will be used in input bar", "", 0, 0,
|
||||
"off", "off", 0, "", "", "", "", "", "");
|
||||
$options_iset{"use_color"} = weechat::config_new_option(
|
||||
$iset_config_file, $section_look,
|
||||
"use_color", "boolean", "display the color value in the corresponding color", "", 0, 0,
|
||||
"off", "off", 0, "", "", "full_refresh_cb", "", "", "");
|
||||
}
|
||||
|
||||
sub iset_config_reload_cb
|
||||
|
@ -1397,7 +1567,8 @@ $wee_version_number = weechat::info_get("version_number", "") || 0;
|
|||
iset_config_init();
|
||||
iset_config_read();
|
||||
|
||||
weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [=][=]<text>",
|
||||
weechat::hook_command($PRGNAME, "Interactive set", "d <text> || f <file> || s <section> || [=][=]<text>",
|
||||
"d <text> : show only changed options\n".
|
||||
"f file : show options for a file\n".
|
||||
"s section: show options for a section\n".
|
||||
"text : show options with 'text' in name\n".
|
||||
|
@ -1418,6 +1589,7 @@ weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [
|
|||
"text,enter : set a new filter using command line (use '*' to see all options)\n".
|
||||
"alt+'v' : toggle help bar on/off\n".
|
||||
"alt+'p' : toggle option \"show_plugin_description\" on/off\n".
|
||||
"q : as input in iset buffer to close it\n".
|
||||
"\n".
|
||||
"Mouse actions:\n".
|
||||
"wheel up/down : move cursor up/down\n".
|
||||
|
@ -1426,8 +1598,8 @@ weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [
|
|||
"right button + drag left/right: increase/decrease value (for integer or color)\n".
|
||||
"\n".
|
||||
"Examples:\n".
|
||||
" show options for file 'weechat'\n".
|
||||
" /iset f weechat\n".
|
||||
" show changed options in 'aspell' plugin\n".
|
||||
" /iset d aspell\n".
|
||||
" show options for file 'irc'\n".
|
||||
" /iset f irc\n".
|
||||
" show options for section 'look'\n".
|
||||
|
|
|
@ -43,6 +43,15 @@
|
|||
# 2014-05-22, Nathaniel Wesley Filardo <PADEBR2M2JIQN02N9OO5JM0CTN8K689P@cmx.ietfng.org>
|
||||
# version 0.2.5: Fix keyed channel support
|
||||
#
|
||||
# 2016-01-13, The fox in the shell <KellerFuchs@hashbang.sh>
|
||||
# version 0.2.6: Support keeping chan list as secured data
|
||||
#
|
||||
# 2018-08-09, Julien Palard <julien@palard.fr>
|
||||
# version 0.3.0: Support for Python 3
|
||||
#
|
||||
# 2019-09-28, fructose
|
||||
# version 0.3.1: Error on invalid arguments
|
||||
#
|
||||
# @TODO: add options to ignore certain buffers
|
||||
# @TODO: maybe add an option to enable autosaving on part/join messages
|
||||
|
||||
|
@ -51,7 +60,7 @@ import re
|
|||
|
||||
SCRIPT_NAME = "autojoin"
|
||||
SCRIPT_AUTHOR = "xt <xt@bash.no>"
|
||||
SCRIPT_VERSION = "0.2.5"
|
||||
SCRIPT_VERSION = "0.3.1"
|
||||
SCRIPT_LICENSE = "GPL3"
|
||||
SCRIPT_DESC = "Configure autojoin for all servers according to currently joined channels"
|
||||
SCRIPT_COMMAND = "autojoin"
|
||||
|
@ -71,8 +80,8 @@ if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT
|
|||
"autojoin_cb",
|
||||
"")
|
||||
|
||||
#w.hook_signal('*,irc_in2_join', 'autosave_channels_on_activity', '')
|
||||
#w.hook_signal('*,irc_in2_part', 'autosave_channels_on_activity', '')
|
||||
# w.hook_signal('*,irc_in2_join', 'autosave_channels_on_activity', '')
|
||||
# w.hook_signal('*,irc_in2_part', 'autosave_channels_on_activity', '')
|
||||
w.hook_signal('quit', 'autosave_channels_on_quit', '')
|
||||
|
||||
# Init everything
|
||||
|
@ -80,6 +89,7 @@ for option, default_value in settings.items():
|
|||
if w.config_get_plugin(option) == "":
|
||||
w.config_set_plugin(option, default_value)
|
||||
|
||||
|
||||
def autosave_channels_on_quit(signal, callback, callback_data):
|
||||
''' Autojoin current channels '''
|
||||
if w.config_get_plugin(option) != "on":
|
||||
|
@ -88,10 +98,8 @@ def autosave_channels_on_quit(signal, callback, callback_data):
|
|||
items = find_channels()
|
||||
|
||||
# print/execute commands
|
||||
for server, channels in items.iteritems():
|
||||
channels = channels.rstrip(',')
|
||||
command = "/set irc.server.%s.autojoin '%s'" % (server, channels)
|
||||
w.command('', command)
|
||||
for server, channels in items.items():
|
||||
process_server(server, channels)
|
||||
|
||||
return w.WEECHAT_RC_OK
|
||||
|
||||
|
@ -104,44 +112,66 @@ def autosave_channels_on_activity(signal, callback, callback_data):
|
|||
items = find_channels()
|
||||
|
||||
# print/execute commands
|
||||
for server, channels in items.iteritems():
|
||||
for server, channels in items.items():
|
||||
nick = w.info_get('irc_nick', server)
|
||||
|
||||
pattern = "^:%s!.*(JOIN|PART) :?(#[^ ]*)( :.*$)?" % nick
|
||||
match = re.match(pattern, callback_data)
|
||||
|
||||
if match: # check if nick is my nick. In that case: save
|
||||
channel = match.group(2)
|
||||
channels = channels.rstrip(',')
|
||||
command = "/set irc.server.%s.autojoin '%s'" % (server, channels)
|
||||
w.command('', command)
|
||||
else: # someone else: ignore
|
||||
if match: # check if nick is my nick. In that case: save
|
||||
process_server(server, channels)
|
||||
else: # someone else: ignore
|
||||
continue
|
||||
|
||||
return w.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def autojoin_cb(data, buffer, args):
|
||||
"""Old behaviour: doesn't save empty channel list"""
|
||||
"""In fact should also save open buffers with a /part'ed channel"""
|
||||
"""But I can't believe somebody would want that behaviour"""
|
||||
if args == '--run':
|
||||
run = True
|
||||
elif args != '':
|
||||
w.prnt('', 'Unexpected argument: %s' % args)
|
||||
return w.WEECHAT_RC_ERROR
|
||||
else:
|
||||
run = False
|
||||
|
||||
# Old behaviour: doesn't save empty channel list
|
||||
# In fact should also save open buffers with a /part'ed channel
|
||||
# But I can't believe somebody would want that behaviour
|
||||
items = find_channels()
|
||||
|
||||
# print/execute commands
|
||||
for server, channels in items.iteritems():
|
||||
channels = channels.rstrip(',')
|
||||
if not channels: # empty channel list
|
||||
continue
|
||||
command = '/set irc.server.%s.autojoin %s' % (server, channels)
|
||||
if args == '--run':
|
||||
w.command('', command)
|
||||
else:
|
||||
w.prnt('', command)
|
||||
for server, channels in items.items():
|
||||
process_server(server, channels, run)
|
||||
|
||||
return w.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def process_server(server, channels, run=True):
|
||||
option = "irc.server.%s.autojoin" % server
|
||||
channels = channels.rstrip(',')
|
||||
oldchans = w.config_string(w.config_get(option))
|
||||
|
||||
if not channels: # empty channel list
|
||||
return
|
||||
|
||||
# Note: re already caches the result of regexp compilation
|
||||
sec = re.match('^\${sec\.data\.(.*)}$', oldchans)
|
||||
if sec:
|
||||
secvar = sec.group(1)
|
||||
command = "/secure set %s %s" % (secvar, channels)
|
||||
else:
|
||||
command = "/set irc.server.%s.autojoin '%s'" % (server, channels)
|
||||
|
||||
if run:
|
||||
w.command('', command)
|
||||
else:
|
||||
w.prnt('', command)
|
||||
|
||||
|
||||
def find_channels():
|
||||
"""Return list of servers and channels"""
|
||||
#@TODO: make it return a dict with more options like "nicks_count etc."
|
||||
# TODO: make it return a dict with more options like "nicks_count etc."
|
||||
items = {}
|
||||
infolist = w.infolist_get('irc_server', '', '')
|
||||
# populate servers
|
||||
|
@ -155,18 +185,18 @@ def find_channels():
|
|||
keys = []
|
||||
keyed_channels = []
|
||||
unkeyed_channels = []
|
||||
items[server] = '' #init if connected but no channels
|
||||
items[server] = '' # init if connected but no channels
|
||||
infolist = w.infolist_get('irc_channel', '', server)
|
||||
while w.infolist_next(infolist):
|
||||
if w.infolist_integer(infolist, 'nicks_count') == 0:
|
||||
#parted but still open in a buffer: bit hackish
|
||||
# parted but still open in a buffer: bit hackish
|
||||
continue
|
||||
if w.infolist_integer(infolist, 'type') == 0:
|
||||
key = w.infolist_string(infolist, "key")
|
||||
if len(key) > 0:
|
||||
keys.append(key)
|
||||
keyed_channels.append(w.infolist_string(infolist, "name"))
|
||||
else :
|
||||
else:
|
||||
unkeyed_channels.append(w.infolist_string(infolist, "name"))
|
||||
items[server] = ','.join(keyed_channels + unkeyed_channels)
|
||||
if len(keys) > 0:
|
||||
|
@ -174,4 +204,3 @@ def find_channels():
|
|||
w.infolist_free(infolist)
|
||||
|
||||
return items
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@
|
|||
# It can be used for force or disable background process, using '0' forces to always grep in
|
||||
# background, while using '' (empty string) will disable it.
|
||||
#
|
||||
# * plugins.var.python.grep.timeout_secs:
|
||||
# Timeout (in seconds) for background grepping.
|
||||
#
|
||||
# * plugins.var.python.grep.default_tail_head:
|
||||
# Config option for define default number of lines returned when using --head or --tail options.
|
||||
# Can be overriden in the command with --number option.
|
||||
|
@ -66,6 +69,28 @@
|
|||
#
|
||||
# History:
|
||||
#
|
||||
# 2019-06-30, dabbill <dabbill@gmail.com>
|
||||
# and Sébastien Helleu <flashcode@flashtux.org>
|
||||
# version 0.8.2: make script compatible with Python 3
|
||||
#
|
||||
# 2018-04-10, Sébastien Helleu <flashcode@flashtux.org>
|
||||
# version 0.8.1: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
|
||||
# integer instead of a string)
|
||||
#
|
||||
# 2017-09-20, mickael9
|
||||
# version 0.8:
|
||||
# * use weechat 1.5+ api for background processing (old method was unsafe and buggy)
|
||||
# * add timeout_secs setting (was previously hardcoded to 5 mins)
|
||||
#
|
||||
# 2017-07-23, Sébastien Helleu <flashcode@flashtux.org>
|
||||
# version 0.7.8: fix modulo by zero when nick is empty string
|
||||
#
|
||||
# 2016-06-23, mickael9
|
||||
# version 0.7.7: fix get_home function
|
||||
#
|
||||
# 2015-11-26
|
||||
# version 0.7.6: fix a typo
|
||||
#
|
||||
# 2015-01-31, Nicd-
|
||||
# version 0.7.5:
|
||||
# '~' is now expaned to the home directory in the log file path so
|
||||
|
@ -96,9 +121,9 @@
|
|||
# * supress highlights when printing in grep buffer
|
||||
#
|
||||
# 2010-10-06
|
||||
# version 0.6.7: by xt <xt@bash.no>
|
||||
# version 0.6.7: by xt <xt@bash.no>
|
||||
# * better temporary file:
|
||||
# use tempfile.mkstemp. to create a temp file in log dir,
|
||||
# use tempfile.mkstemp. to create a temp file in log dir,
|
||||
# makes it safer with regards to write permission and multi user
|
||||
#
|
||||
# 2010-04-08
|
||||
|
@ -189,7 +214,12 @@
|
|||
###
|
||||
|
||||
from os import path
|
||||
import sys, getopt, time, os, re, tempfile
|
||||
import sys, getopt, time, os, re
|
||||
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except ImportError:
|
||||
import pickle
|
||||
|
||||
try:
|
||||
import weechat
|
||||
|
@ -200,20 +230,21 @@ except ImportError:
|
|||
|
||||
SCRIPT_NAME = "grep"
|
||||
SCRIPT_AUTHOR = "Elián Hanisch <lambdae2@gmail.com>"
|
||||
SCRIPT_VERSION = "0.7.5"
|
||||
SCRIPT_VERSION = "0.8.2"
|
||||
SCRIPT_LICENSE = "GPL3"
|
||||
SCRIPT_DESC = "Search in buffers and logs"
|
||||
SCRIPT_COMMAND = "grep"
|
||||
|
||||
### Default Settings ###
|
||||
settings = {
|
||||
'clear_buffer' : 'off',
|
||||
'log_filter' : '',
|
||||
'go_to_buffer' : 'on',
|
||||
'max_lines' : '4000',
|
||||
'show_summary' : 'on',
|
||||
'size_limit' : '2048',
|
||||
'default_tail_head' : '10',
|
||||
'clear_buffer' : 'off',
|
||||
'log_filter' : '',
|
||||
'go_to_buffer' : 'on',
|
||||
'max_lines' : '4000',
|
||||
'show_summary' : 'on',
|
||||
'size_limit' : '2048',
|
||||
'default_tail_head' : '10',
|
||||
'timeout_secs' : '300',
|
||||
}
|
||||
|
||||
### Class definitions ###
|
||||
|
@ -232,14 +263,14 @@ class linesDict(dict):
|
|||
def get_matches_count(self):
|
||||
"""Return the sum of total matches stored."""
|
||||
if dict.__len__(self):
|
||||
return sum(map(lambda L: L.matches_count, self.itervalues()))
|
||||
return sum(map(lambda L: L.matches_count, self.values()))
|
||||
else:
|
||||
return 0
|
||||
|
||||
def __len__(self):
|
||||
"""Return the sum of total lines stored."""
|
||||
if dict.__len__(self):
|
||||
return sum(map(len, self.itervalues()))
|
||||
return sum(map(len, self.values()))
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
@ -247,7 +278,7 @@ class linesDict(dict):
|
|||
"""Returns buffer count or buffer name if there's just one stored."""
|
||||
n = len(self.keys())
|
||||
if n == 1:
|
||||
return self.keys()[0]
|
||||
return list(self.keys())[0]
|
||||
elif n > 1:
|
||||
return '%s logs' %n
|
||||
else:
|
||||
|
@ -255,18 +286,18 @@ class linesDict(dict):
|
|||
|
||||
def items(self):
|
||||
"""Returns a list of items sorted by line count."""
|
||||
items = dict.items(self)
|
||||
items = list(dict.items(self))
|
||||
items.sort(key=lambda i: len(i[1]))
|
||||
return items
|
||||
|
||||
def items_count(self):
|
||||
"""Returns a list of items sorted by match count."""
|
||||
items = dict.items(self)
|
||||
items = list(dict.items(self))
|
||||
items.sort(key=lambda i: i[1].matches_count)
|
||||
return items
|
||||
|
||||
def strip_separator(self):
|
||||
for L in self.itervalues():
|
||||
for L in self.values():
|
||||
L.strip_separator()
|
||||
|
||||
def get_last_lines(self, n):
|
||||
|
@ -275,7 +306,7 @@ class linesDict(dict):
|
|||
if n >= total_lines:
|
||||
# nothing to do
|
||||
return
|
||||
for k, v in reversed(self.items()):
|
||||
for k, v in reversed(list(self.items())):
|
||||
l = len(v)
|
||||
if n > 0:
|
||||
if l > n:
|
||||
|
@ -372,13 +403,15 @@ def color_nick(nick):
|
|||
else:
|
||||
mode = mode_color = ''
|
||||
# nick color
|
||||
nick_color = weechat.info_get('irc_nick_color', nick)
|
||||
if not nick_color:
|
||||
# probably we're in WeeChat 0.3.0
|
||||
#debug('no irc_nick_color')
|
||||
color_nicks_number = config_int('weechat.look.color_nicks_number')
|
||||
idx = (sum(map(ord, nick))%color_nicks_number) + 1
|
||||
nick_color = wcolor(config_string('weechat.color.chat_nick_color%02d' %idx))
|
||||
nick_color = ''
|
||||
if nick:
|
||||
nick_color = weechat.info_get('irc_nick_color', nick)
|
||||
if not nick_color:
|
||||
# probably we're in WeeChat 0.3.0
|
||||
#debug('no irc_nick_color')
|
||||
color_nicks_number = config_int('weechat.look.color_nicks_number')
|
||||
idx = (sum(map(ord, nick))%color_nicks_number) + 1
|
||||
nick_color = wcolor(config_string('weechat.color.chat_nick_color%02d' %idx))
|
||||
return ''.join((prefix_c, prefix, mode_color, mode, nick_color, nick, suffix_c, suffix))
|
||||
|
||||
### Config and value validation ###
|
||||
|
@ -414,8 +447,9 @@ def get_config_log_filter():
|
|||
|
||||
def get_home():
|
||||
home = weechat.config_string(weechat.config_get('logger.file.path'))
|
||||
home = home.replace('%h', weechat.info_get('weechat_dir', ''))
|
||||
home = path.abspath(path.expanduser(home))
|
||||
return home.replace('%h', weechat.info_get('weechat_dir', ''))
|
||||
return home
|
||||
|
||||
def strip_home(s, dir=''):
|
||||
"""Strips home dir from the begging of the log path, this makes them sorter."""
|
||||
|
@ -457,7 +491,7 @@ def dir_list(dir, filter_list=(), filter_excludes=True, include_dir=False):
|
|||
return cache_dir[key]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
filter_list = filter_list or get_config_log_filter()
|
||||
dir_len = len(dir)
|
||||
if filter_list:
|
||||
|
@ -627,8 +661,8 @@ def make_regexp(pattern, matchcase=False):
|
|||
regexp = re.compile(pattern, re.IGNORECASE)
|
||||
else:
|
||||
regexp = re.compile(pattern)
|
||||
except Exception, e:
|
||||
raise Exception, 'Bad pattern, %s' %e
|
||||
except Exception as e:
|
||||
raise Exception('Bad pattern, %s' % e)
|
||||
return regexp
|
||||
|
||||
def check_string(s, regexp, hilight='', exact=False):
|
||||
|
@ -686,7 +720,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
|
|||
return s
|
||||
else:
|
||||
check = lambda s: check_string(s, regexp, hilight, exact)
|
||||
|
||||
|
||||
try:
|
||||
file_object = open(file, 'r')
|
||||
except IOError:
|
||||
|
@ -706,7 +740,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
|
|||
before_context, after_context = after_context, before_context
|
||||
|
||||
if before_context:
|
||||
before_context_range = range(1, before_context + 1)
|
||||
before_context_range = list(range(1, before_context + 1))
|
||||
before_context_range.reverse()
|
||||
|
||||
limit = tail or head
|
||||
|
@ -770,7 +804,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
|
|||
while id < after_context + offset:
|
||||
id += 1
|
||||
try:
|
||||
context_line = file_object.next()
|
||||
context_line = next(file_object)
|
||||
_context_line = check(context_line)
|
||||
if _context_line:
|
||||
offset = id
|
||||
|
@ -818,6 +852,10 @@ def grep_buffer(buffer, head, tail, after_context, before_context, count, regexp
|
|||
prefix = string_remove_color(infolist_string(infolist, 'prefix'), '')
|
||||
message = string_remove_color(infolist_string(infolist, 'message'), '')
|
||||
date = infolist_time(infolist, 'date')
|
||||
# since WeeChat 2.2, infolist_time returns a long integer
|
||||
# instead of a string
|
||||
if not isinstance(date, str):
|
||||
date = time.strftime('%F %T', time.localtime(int(date)))
|
||||
return '%s\t%s\t%s' %(date, prefix, message)
|
||||
return function
|
||||
get_line = make_get_line_funcion()
|
||||
|
@ -931,104 +969,85 @@ def show_matching_lines():
|
|||
elif size_limit == '':
|
||||
background = False
|
||||
|
||||
regexp = make_regexp(pattern, matchcase)
|
||||
|
||||
global grep_options, log_pairs
|
||||
grep_options = (head, tail, after_context, before_context,
|
||||
count, regexp, hilight, exact, invert)
|
||||
|
||||
log_pairs = [(strip_home(log), log) for log in search_in_files]
|
||||
|
||||
if not background:
|
||||
# run grep normally
|
||||
regexp = make_regexp(pattern, matchcase)
|
||||
for log in search_in_files:
|
||||
log_name = strip_home(log)
|
||||
matched_lines[log_name] = grep_file(log, head, tail, after_context, before_context,
|
||||
count, regexp, hilight, exact, invert)
|
||||
for log_name, log in log_pairs:
|
||||
matched_lines[log_name] = grep_file(log, *grep_options)
|
||||
buffer_update()
|
||||
else:
|
||||
# we hook a process so grepping runs in background.
|
||||
#debug('on background')
|
||||
global hook_file_grep, script_path, bytecode
|
||||
timeout = 1000*60*5 # 5 min
|
||||
|
||||
quotify = lambda s: '"%s"' %s
|
||||
files_string = ', '.join(map(quotify, search_in_files))
|
||||
|
||||
global tmpFile
|
||||
# we keep the file descriptor as a global var so it isn't deleted until next grep
|
||||
tmpFile = tempfile.NamedTemporaryFile(prefix=SCRIPT_NAME,
|
||||
dir=weechat.info_get('weechat_dir', ''))
|
||||
cmd = grep_process_cmd %dict(logs=files_string, head=head, pattern=pattern, tail=tail,
|
||||
hilight=hilight, after_context=after_context, before_context=before_context,
|
||||
exact=exact, matchcase=matchcase, home_dir=home_dir, script_path=script_path,
|
||||
count=count, invert=invert, bytecode=bytecode, filename=tmpFile.name,
|
||||
python=weechat.info_get('python2_bin', '') or 'python')
|
||||
|
||||
#debug(cmd)
|
||||
hook_file_grep = weechat.hook_process(cmd, timeout, 'grep_file_callback', tmpFile.name)
|
||||
global pattern_tmpl
|
||||
global hook_file_grep, grep_stdout, grep_stderr, pattern_tmpl
|
||||
grep_stdout = grep_stderr = ''
|
||||
hook_file_grep = weechat.hook_process(
|
||||
'func:grep_process',
|
||||
get_config_int('timeout_secs') * 1000,
|
||||
'grep_process_cb',
|
||||
''
|
||||
)
|
||||
if hook_file_grep:
|
||||
buffer_create("Searching for '%s' in %s worth of data..." %(pattern_tmpl,
|
||||
human_readable_size(size)))
|
||||
buffer_create("Searching for '%s' in %s worth of data..." % (
|
||||
pattern_tmpl,
|
||||
human_readable_size(size)
|
||||
))
|
||||
else:
|
||||
buffer_update()
|
||||
|
||||
# defined here for commodity
|
||||
grep_process_cmd = """%(python)s -%(bytecode)sc '
|
||||
import sys, cPickle, os
|
||||
sys.path.append("%(script_path)s") # add WeeChat script dir so we can import grep
|
||||
from grep import make_regexp, grep_file, strip_home
|
||||
logs = (%(logs)s, )
|
||||
try:
|
||||
regexp = make_regexp("%(pattern)s", %(matchcase)s)
|
||||
d = {}
|
||||
for log in logs:
|
||||
log_name = strip_home(log, "%(home_dir)s")
|
||||
lines = grep_file(log, %(head)s, %(tail)s, %(after_context)s, %(before_context)s,
|
||||
%(count)s, regexp, "%(hilight)s", %(exact)s, %(invert)s)
|
||||
d[log_name] = lines
|
||||
fd = open("%(filename)s", "wb")
|
||||
cPickle.dump(d, fd, -1)
|
||||
fd.close()
|
||||
except Exception, e:
|
||||
print >> sys.stderr, e'
|
||||
"""
|
||||
|
||||
def grep_process(*args):
|
||||
result = {}
|
||||
try:
|
||||
global grep_options, log_pairs
|
||||
for log_name, log in log_pairs:
|
||||
result[log_name] = grep_file(log, *grep_options)
|
||||
except Exception as e:
|
||||
result = e
|
||||
|
||||
return pickle.dumps(result)
|
||||
|
||||
grep_stdout = grep_stderr = ''
|
||||
def grep_file_callback(filename, command, rc, stdout, stderr):
|
||||
global hook_file_grep, grep_stderr, grep_stdout
|
||||
global matched_lines
|
||||
#debug("rc: %s\nstderr: %s\nstdout: %s" %(rc, repr(stderr), repr(stdout)))
|
||||
if stdout:
|
||||
grep_stdout += stdout
|
||||
if stderr:
|
||||
grep_stderr += stderr
|
||||
if int(rc) >= 0:
|
||||
|
||||
def set_buffer_error():
|
||||
grep_buffer = buffer_create()
|
||||
title = weechat.buffer_get_string(grep_buffer, 'title')
|
||||
title = title + ' %serror' %color_title
|
||||
weechat.buffer_set(grep_buffer, 'title', title)
|
||||
|
||||
def grep_process_cb(data, command, return_code, out, err):
|
||||
global grep_stdout, grep_stderr, matched_lines, hook_file_grep
|
||||
|
||||
grep_stdout += out
|
||||
grep_stderr += err
|
||||
|
||||
def set_buffer_error(message):
|
||||
error(message)
|
||||
grep_buffer = buffer_create()
|
||||
title = weechat.buffer_get_string(grep_buffer, 'title')
|
||||
title = title + ' %serror' % color_title
|
||||
weechat.buffer_set(grep_buffer, 'title', title)
|
||||
|
||||
if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR:
|
||||
set_buffer_error("Background grep timed out")
|
||||
hook_file_grep = None
|
||||
return WEECHAT_RC_OK
|
||||
|
||||
elif return_code >= 0:
|
||||
hook_file_grep = None
|
||||
if grep_stderr:
|
||||
set_buffer_error(grep_stderr)
|
||||
return WEECHAT_RC_OK
|
||||
|
||||
try:
|
||||
if grep_stderr:
|
||||
error(grep_stderr)
|
||||
set_buffer_error()
|
||||
#elif grep_stdout:
|
||||
#debug(grep_stdout)
|
||||
elif path.exists(filename):
|
||||
import cPickle
|
||||
try:
|
||||
#debug(file)
|
||||
fd = open(filename, 'rb')
|
||||
d = cPickle.load(fd)
|
||||
matched_lines.update(d)
|
||||
fd.close()
|
||||
except Exception, e:
|
||||
error(e)
|
||||
set_buffer_error()
|
||||
else:
|
||||
buffer_update()
|
||||
global tmpFile
|
||||
tmpFile = None
|
||||
finally:
|
||||
grep_stdout = grep_stderr = ''
|
||||
hook_file_grep = None
|
||||
data = pickle.loads(grep_stdout)
|
||||
if isinstance(data, Exception):
|
||||
raise data
|
||||
matched_lines.update(data)
|
||||
except Exception as e:
|
||||
set_buffer_error(repr(e))
|
||||
return WEECHAT_RC_OK
|
||||
else:
|
||||
buffer_update()
|
||||
|
||||
return WEECHAT_RC_OK
|
||||
|
||||
def get_grep_file_status():
|
||||
|
@ -1165,7 +1184,7 @@ def buffer_update():
|
|||
|
||||
# free matched_lines so it can be removed from memory
|
||||
del matched_lines
|
||||
|
||||
|
||||
def split_line(s):
|
||||
"""Splits log's line 's' in 3 parts, date, nick and msg."""
|
||||
global weechat_format
|
||||
|
@ -1265,12 +1284,12 @@ def buffer_input(data, buffer, input_data):
|
|||
weechat.infolist_free(infolist)
|
||||
try:
|
||||
cmd_grep_parsing(input_data)
|
||||
except Exception, e:
|
||||
error('Argument error, %s' %e, buffer=buffer)
|
||||
except Exception as e:
|
||||
error('Argument error, %s' % e, buffer=buffer)
|
||||
return WEECHAT_RC_OK
|
||||
try:
|
||||
show_matching_lines()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
error(e)
|
||||
except NameError:
|
||||
error("There isn't any previous search to repeat.", buffer=buffer)
|
||||
|
@ -1327,11 +1346,11 @@ def cmd_grep_parsing(args):
|
|||
|
||||
args = ' '.join(args) # join pattern for keep spaces
|
||||
if args:
|
||||
pattern_tmpl = args
|
||||
pattern_tmpl = args
|
||||
pattern = _tmplRe.sub(tmplReplacer, args)
|
||||
debug('Using regexp: %s', pattern)
|
||||
if not pattern:
|
||||
raise Exception, 'No pattern for grep the logs.'
|
||||
raise Exception('No pattern for grep the logs.')
|
||||
|
||||
def positive_number(opt, val):
|
||||
try:
|
||||
|
@ -1344,7 +1363,7 @@ def cmd_grep_parsing(args):
|
|||
opt = '-' + opt
|
||||
else:
|
||||
opt = '--' + opt
|
||||
raise Exception, "argument for %s must be a positive integer." %opt
|
||||
raise Exception("argument for %s must be a positive integer." % opt)
|
||||
|
||||
for opt, val in opts:
|
||||
opt = opt.strip('-')
|
||||
|
@ -1403,18 +1422,18 @@ def cmd_grep_parsing(args):
|
|||
tail = n
|
||||
|
||||
def cmd_grep_stop(buffer, args):
|
||||
global hook_file_grep, pattern, matched_lines, tmpFile
|
||||
global hook_file_grep, pattern, matched_lines
|
||||
if hook_file_grep:
|
||||
if args == 'stop':
|
||||
weechat.unhook(hook_file_grep)
|
||||
hook_file_grep = None
|
||||
s = 'Search for \'%s\' stopped.' %pattern
|
||||
|
||||
s = 'Search for \'%s\' stopped.' % pattern
|
||||
say(s, buffer)
|
||||
grep_buffer = weechat.buffer_search('python', SCRIPT_NAME)
|
||||
if grep_buffer:
|
||||
weechat.buffer_set(grep_buffer, 'title', s)
|
||||
del matched_lines
|
||||
tmpFile = None
|
||||
matched_lines = {}
|
||||
else:
|
||||
say(get_grep_file_status(), buffer)
|
||||
raise Exception
|
||||
|
@ -1439,8 +1458,8 @@ def cmd_grep(data, buffer, args):
|
|||
# parse
|
||||
try:
|
||||
cmd_grep_parsing(args)
|
||||
except Exception, e:
|
||||
error('Argument error, %s' %e)
|
||||
except Exception as e:
|
||||
error('Argument error, %s' % e)
|
||||
return WEECHAT_RC_OK
|
||||
|
||||
# find logs
|
||||
|
@ -1486,7 +1505,7 @@ def cmd_grep(data, buffer, args):
|
|||
# grepping
|
||||
try:
|
||||
show_matching_lines()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
error(e)
|
||||
return WEECHAT_RC_OK
|
||||
|
||||
|
@ -1505,8 +1524,8 @@ def cmd_logs(data, buffer, args):
|
|||
opt = opt.strip('-')
|
||||
if opt in ('size', 's'):
|
||||
sort_by_size = True
|
||||
except Exception, e:
|
||||
error('Argument error, %s' %e)
|
||||
except Exception as e:
|
||||
error('Argument error, %s' % e)
|
||||
return WEECHAT_RC_OK
|
||||
|
||||
# is there's a filter, filter_excludes should be False
|
||||
|
@ -1639,7 +1658,7 @@ if __name__ == '__main__' and import_ok and \
|
|||
If used with 'log <file>' search in all logs that matches <file>.
|
||||
-b --buffer: Search only in buffers, not in file logs.
|
||||
-c --count: Just count the number of matched lines instead of showing them.
|
||||
-m --matchcase: Don't do case insensible search.
|
||||
-m --matchcase: Don't do case insensitive search.
|
||||
-H --hilight: Colour exact matches in output buffer.
|
||||
-o --only-match: Print only the matching part of the line (unique matches).
|
||||
-v -i --invert: Print lines that don't match the regular expression.
|
||||
|
@ -1688,7 +1707,7 @@ Examples:
|
|||
'completion_grep_args', '')
|
||||
|
||||
# settings
|
||||
for opt, val in settings.iteritems():
|
||||
for opt, val in settings.items():
|
||||
if not weechat.config_is_set_plugin(opt):
|
||||
weechat.config_set_plugin(opt, val)
|
||||
|
||||
|
@ -1701,7 +1720,7 @@ Examples:
|
|||
color_summary = weechat.color('lightcyan')
|
||||
color_delimiter = weechat.color('chat_delimiters')
|
||||
color_script_nick = weechat.color('chat_nick')
|
||||
|
||||
|
||||
# pretty [grep]
|
||||
script_nick = '%s[%s%s%s]%s' %(color_delimiter, color_script_nick, SCRIPT_NAME, color_delimiter,
|
||||
color_reset)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue