diff options
author | Ryan Kavanagh <rak@debian.org> | 2018-03-21 11:39:59 -0400 |
---|---|---|
committer | Ryan Kavanagh <rak@debian.org> | 2018-03-21 11:51:13 -0400 |
commit | 8c0412269bd4a90145ec74cca00b337c571d3fb8 (patch) | |
tree | 52d9b34e77f4f0d00465a246b6af8f30395311c3 /.irssi/scripts/nickcolor.pl | |
parent | irssi (diff) |
Update irssi config
Diffstat (limited to '')
-rw-r--r-- | .irssi/scripts/nickcolor.pl | 122 |
1 files changed, 115 insertions, 7 deletions
diff --git a/.irssi/scripts/nickcolor.pl b/.irssi/scripts/nickcolor.pl index ff9915d..95b7b63 100644 --- a/.irssi/scripts/nickcolor.pl +++ b/.irssi/scripts/nickcolor.pl @@ -1,24 +1,36 @@ use strict; use Irssi 20020101.0250 (); -use vars qw($VERSION %IRSSI); -$VERSION = "2"; +use vars qw($VERSION %IRSSI); +$VERSION = "2.1"; %IRSSI = ( - authors => "Timo Sirainen, Ian Peters, David Leadbeater", - contact => "tss\@iki.fi", + authors => "Timo Sirainen, Ian Peters, David Leadbeater, Bruno Cattáneo", + contact => "tss\@iki.fi", name => "Nick Color", description => "assign a different color for each nick", license => "Public Domain", url => "http://irssi.org/", - changed => "Sun 15 Jun 19:10:44 BST 2014", + changed => "Mon 08 Jan 21:28:53 BST 2018", ); # Settings: # nickcolor_colors: List of color codes to use. # e.g. /set nickcolor_colors 2 3 4 5 6 7 9 10 11 12 13 # (avoid 8, as used for hilights in the default theme). +# +# nickcolor_enable_prefix: Enables prefix for same nick. +# +# nickcolor_enable_truncate: Enables nick truncation. +# +# nickcolor_prefix_text: Prefix text for succesive messages. +# e.g. /set nickcolor_prefix_text - +# +# nickcolor_truncate_value: Truncate nick value. +# e.g. /set nickcolor_truncate_value -7 +# This will truncate nicknames at 7 characters and make them right aligned my %saved_colors; my %session_colors = {}; +my %saved_nicks; # To store each channel's last nickname sub load_colors { open my $color_fh, "<", "$ENV{HOME}/.irssi/saved_colors"; @@ -75,9 +87,21 @@ sub simple_hash { return $counter; } +# process public (others) messages sub sig_public { my ($server, $msg, $nick, $address, $target) = @_; + my $enable_prefix = Irssi::settings_get_bool('nickcolor_enable_prefix'); + my $enable_truncate = Irssi::settings_get_bool('nickcolor_enable_truncate'); + my $prefix_text = Irssi::settings_get_str('nickcolor_prefix_text'); + my $truncate_value = Irssi::settings_get_int('nickcolor_truncate_value'); + + # Reference for server/channel + my $tagtarget = "$server->{tag}/$target"; + + # Set default nick truncate value to 0 if option is disabled + $truncate_value = 0 if (!$enable_truncate); + # Has the user assigned this nick a color? my $color = $saved_colors{$nick}; @@ -93,7 +117,84 @@ sub sig_public { } $color = sprintf "\003%02d", $color; - $server->command('/^format pubmsg {pubmsgnick $2 {pubnick ' . $color . '$0}}$1'); + + # Optional: We check if it's the same nickname for current target + if ($saved_nicks{$tagtarget} eq $nick && $enable_prefix) + { + # Grouped message + Irssi::command('/^format pubmsg ' . $prefix_text . '$1'); + } + else + { + # Normal message + Irssi::command('/^format pubmsg {pubmsgnick $2 {pubnick ' . $color . '$[' . $truncate_value . ']0}}$1'); + + # Save nickname for next message + $saved_nicks{$tagtarget} = $nick; + } + +} + +# process public (me) messages +sub sig_me { + my ($server, $msg, $target) = @_; + my $nick = $server->{nick}; + + my $enable_prefix = Irssi::settings_get_bool('nickcolor_enable_prefix'); + my $enable_truncate = Irssi::settings_get_bool('nickcolor_enable_truncate'); + my $prefix_text = Irssi::settings_get_str('nickcolor_prefix_text'); + my $truncate_value = Irssi::settings_get_int('nickcolor_truncate_value'); + + # Reference for server/channel + my $tagtarget = "$server->{tag}/$target"; + + # Set default nick truncate value to 0 if option is disabled + $truncate_value = 0 if (!$enable_truncate); + + # Optional: We check if it's the same nickname for current target + if ($saved_nicks{$tagtarget} eq $nick && $enable_prefix) + { + # Grouped message + Irssi::command('/^format own_msg ' . $prefix_text . '$1'); + } + else + { + # Normal message + Irssi::command('/^format own_msg {ownmsgnick $2 {ownnick $[' . $truncate_value . ']0}}$1'); + + # Save nickname for next message + $saved_nicks{$tagtarget} = $nick; + } + +} + +# process public (others) actions +sub sig_action_public { + my ($server, $msg, $nick, $address, $target) = @_; + + my $enable_prefix = Irssi::settings_get_bool('nickcolor_enable_prefix'); + + # Reference for server/channel + my $tagtarget = "$server->{tag}/$target"; + + # Empty current target nick if prefix option is enabled + $saved_nicks{$tagtarget} = '' if ($enable_prefix); + +} + +# process public (me) actions +sub sig_action_me { + my ($server, $msg, $target) = @_; + my $nick = $server->{nick}; + + my $enable_prefix = Irssi::settings_get_bool('nickcolor_enable_prefix'); + + # Reference for server/channel + my $tagtarget = "$server->{tag}/$target"; + + # Empty current target nick if prefix option is enabled + $saved_nicks{$tagtarget} = '' if ($enable_prefix); + } sub cmd_color { @@ -125,7 +226,7 @@ sub cmd_color { } elsif ($op eq "list") { Irssi::print ("\nSaved Colors:"); foreach my $nick (keys %saved_colors) { - Irssi::print (chr (3) . "$saved_colors{$nick}$nick" . + Irssi::print (chr (3) . sprintf("%02d", $saved_colors{$nick}) . "$nick" . chr (3) . "1 ($saved_colors{$nick})"); } } elsif ($op eq "preview") { @@ -139,7 +240,14 @@ sub cmd_color { load_colors; Irssi::settings_add_str('misc', 'nickcolor_colors', '2 3 4 5 6 7 9 10 11 12 13'); +Irssi::settings_add_bool('misc', 'nickcolor_enable_prefix', 0); +Irssi::settings_add_bool('misc', 'nickcolor_enable_truncate', 0); +Irssi::settings_add_str('misc', 'nickcolor_prefix_text' => '- '); +Irssi::settings_add_int('misc', 'nickcolor_truncate_value' => 0); Irssi::command_bind('color', 'cmd_color'); Irssi::signal_add('message public', 'sig_public'); +Irssi::signal_add('message own_public', 'sig_me'); +Irssi::signal_add('message irc action', 'sig_action_public'); +Irssi::signal_add('message irc own_action', 'sig_action_me'); Irssi::signal_add('event nick', 'sig_nick'); |