Skip to content

Instantly share code, notes, and snippets.

@kinostl
Last active August 29, 2019 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinostl/67e7c5c852b24891f48d304432183a4a to your computer and use it in GitHub Desktop.
Save kinostl/67e7c5c852b24891f48d304432183a4a to your computer and use it in GitHub Desktop.
Assign a three color chevron for each nick
use strict;
use Irssi 20020101.0250 ();
use Digest::MD5 qw(md5_hex);
use vars qw($VERSION %IRSSI);
$VERSION = "1.0";
%IRSSI = (
authors => "minty_cream#4261",
contact => "minty_cream#4261",
name => "Nick Flag",
description => "Assign a three color chevron for each nick",
license => "Public Domain",
url => "http://irssi.org/",
changed => "Thu 29 Aug 2019 06:02:43 AM UTC",
);
my %session_colors = {};
my %colors = (
'0'=> '%K',
'1'=> '%R',
'2'=> '%G',
'3'=> '%Y',
'4'=> '%B',
'5'=> '%M',
'6'=> '%C',
'7'=> '%W',
'8'=> '%K',
'9'=> '%R',
'a'=> '%G',
'b'=> '%Y',
'c'=> '%B',
'd'=> '%M',
'e'=> '%C',
'f'=> '%W',
);
my $sep = ">";
my $prevnick = "";
sub get_flag {
#my $offset = ($_[1]//0)*3;
my ($string) = substr md5_hex($_[0]), 0, 3;
chomp $string;
return map { $colors{$_} } split //, $string;
}
# process public (others) messages
sub sig_public {
my ($server, $msg, $nick, $address, $target) = @_;
my @color = get_flag $nick;
my $flag1 = $color[0].$sep;
my $flag2 = $color[1].$sep;
my $flag3 = $color[2].$sep;
if($nick eq $prevnick){
Irssi::command('/^format pubmsg '.$flag1.$flag2.$flag3.'%N $1');
Irssi::command('/^format pubmsg_hilight'.$flag1.$flag2.$flag3.'%N $1');
}else{
$prevnick = $nick;
Irssi::command('/^format pubmsg {pubmsgnick $2 {pubnick $[-10]0}}'.$flag1.$flag2.$flag3.'%N $1');
Irssi::command('/^format pubmsg_hilight {pubmsghinick $0 $3 $[-10]1}'.$flag1.$flag2.$flag3.'%N $2');
}
}
# process public (me) messages
sub sig_me {
if("---" eq $prevnick){
Irssi::command('/^format own_msg '.$sep.$sep.$sep.' $1');
}else{
$prevnick = "---";
Irssi::command('/^format own_msg {ownmsgnick $2 {ownnick $[-10]0}}'.$sep.$sep.$sep.' $1');
}
}
# process public (others) actions
sub sig_action_public {
my ($server, $msg, $nick, $address, $target) = @_;
my @color = get_flag $nick;
my $flag1 = $color[0].$sep;
my $flag2 = $color[1].$sep;
my $flag3 = $color[2].$sep;
if($nick eq $prevnick){
Irssi::command('/^format pubmsg_me '.$flag1.$flag2.$flag3.'%N $1');
}else{
$prevnick = $nick;
Irssi::command('/^format pubmsg_me {pubmsgmenick $2 {menick $[-10]0}}'.$flag1.$flag2.$flag3.'%N $1');
}
}
Irssi::signal_add('message public', 'sig_public');
Irssi::signal_add('message own_public', 'sig_me');
Irssi::signal_add('message irc action', 'sig_action_public');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment