]>
git.sthu.org Git - shutils.git/blob - dotfiles/irssi/scripts/xchatnickcolor.pl
2 use Irssi
20020101.0250 ();
3 use vars
qw($VERSION %IRSSI);
6 authors => "Timo Sirainen, Ian Peters",
7 contact => "tss\@iki.fi",
9 description => "assign a different color for each nick",
10 license => "Public Domain",
11 url => "http://irssi.org/",
12 changed => "2002-03-04T22:47+0100"
15 # hm.. i should make it possible to use the existing one..
16 Irssi::theme_register([
17 'pubmsg_hilight', '{pubmsghinick $0 $3 $1}$2'
21 my %session_colors = {};
22 my @colors = qw/ 2 3 4 5 6 7 9 10 11 12 13 14 15/;
25 open COLORS, "$ENV{HOME}/.irssi/saved_colors";
28 # I don't know why this is necessary only inside of irssi
29 my @lines = split "\n";
30 foreach my $line (@lines) {
31 my($nick, $color) = split ":", $line;
32 $saved_colors{$nick} = $color;
40 open COLORS, ">$ENV{HOME}/.irssi/saved_colors";
42 foreach my $nick (keys %saved_colors) {
43 print COLORS "$nick:$saved_colors{$nick}\n";
49 # If someone we've colored (either through the saved colors, or the hash
50 # function) changes their nick, we'd like to keep the same color associated
51 # with them (but only in the session_colors, ie a temporary mapping).
54 my ($server, $newnick, $nick, $address) = @_;
57 $newnick = substr ($newnick, 1) if ($newnick =~ /^:/);
59 if ($color = $saved_colors{$nick}) {
60 $session_colors{$newnick} = $color;
61 } elsif ($color = $session_colors{$nick}) {
62 $session_colors{$newnick} = $color;
66 # This gave reasonable distribution values when run across
67 # /usr/share/dict/words
72 my @chars = split //, $string;
75 foreach my $char (@chars) {
76 $counter += ord $char;
79 $counter = $colors[$counter % 11];
84 # FIXME: breaks /HILIGHT etc.
86 my ($server, $msg, $nick, $address, $target) = @_;
87 my $chanrec = $server->channel_find($target);
88 return if not $chanrec;
89 my $nickrec = $chanrec->nick_find($nick);
90 return if not $nickrec;
91 my $nickmode = $nickrec->{op} ? "@" : $nickrec->{voice} ? "+" : "";
93 # Has the user assigned this nick a color?
94 my $color = $saved_colors{$nick};
96 # Have -we- already assigned this nick a color?
98 $color = $session_colors{$nick};
101 # Let's assign this nick a color
103 $color = simple_hash $nick;
104 $session_colors{$nick} = $color;
107 $color = "0".$color if ($color < 10);
108 $server->command('/^format pubmsg %b<%w$2'.chr(3).$color.'$[-11]0%b> %K|%n $1');
109 # $server->command('/^format action_public {pubaction '.chr(3).$color.'$0}$1');
113 my ($data, $server, $witem) = @_;
114 my ($op, $nick, $color) = split " ", $data;
119 Irssi::print ("No operation given");
120 } elsif ($op eq "save") {
122 } elsif ($op eq "set") {
124 Irssi::print ("Nick not given");
126 Irssi::print ("Color not given");
127 } elsif ($color < 2 || $color > 14) {
128 Irssi::print ("Color must be between 2 and 14 inclusive");
130 $saved_colors{$nick} = $color;
132 } elsif ($op eq "clear") {
134 Irssi::print ("Nick not given");
136 delete ($saved_colors{$nick});
138 } elsif ($op eq "list") {
139 Irssi::print ("\nSaved Colors:");
140 foreach my $nick (keys %saved_colors) {
141 Irssi::print (chr (3) . "$saved_colors{$nick}$nick" .
142 chr (3) . "1 ($saved_colors{$nick})");
144 } elsif ($op eq "preview") {
145 Irssi::print ("\nAvailable colors:");
146 foreach my $i (2..14) {
147 Irssi::print (chr (3) . "$i" . "Color #$i");
154 Irssi::command_bind('color', 'cmd_color');
156 Irssi::signal_add('message public', 'sig_public');
157 Irssi::signal_add('event nick', 'sig_nick');