Skip to content

Instantly share code, notes, and snippets.

@maddievision
Created May 2, 2013 02:54
Show Gist options
  • Save maddievision/5499851 to your computer and use it in GitHub Desktop.
Save maddievision/5499851 to your computer and use it in GitHub Desktop.
weechat nick color algo
int
irc_nick_hash_color (const char *nickname)
{
int color;
const char *ptr_nick;
if (!irc_config_nick_colors)
irc_config_set_nick_colors ();
if (irc_config_num_nick_colors == 0)
return 0;
color = 0;
ptr_nick = nickname;
while (ptr_nick && ptr_nick[0])
{
color += weechat_utf8_char_int (ptr_nick);
ptr_nick = weechat_utf8_next_char (ptr_nick);
}
return (color % irc_config_num_nick_colors);
}
#cyan,magenta,green,brown,lightblue,default,lightcyan,lightmagenta,lightgreen,blue
WC_NICK_COLORS = [10,6,3,7,12,14,11,13,9,2]
def get_nick_color(nickname):
color = sum([ord(a) for a in nickname]) if len(nickname) > 0 else 0
return WC_NICK_COLORS[color % len(WC_NICK_COLORS)]
def formatnick(nickname):
nc = get_nick_color(nickname)
return "\x03%02d%s\x03" % (nc,nickname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment