Project

General

Profile

RE: [Script] Full-Pallette Random Nick Color Script 1.2 » Full-Pallette Random Nick Color Script fork v0.1.4.ini

Mr. BS, 05/07/2016 02:20 AM

 
; https://dev.adiirc.com/boards/5/topics/308

; Hackjob full-palette Random Nick Color script for AdiIRC
; Generate consistent but random, full-palette colors for nicks & set custom colors as you please
;
; Version 1.2 - Fork v0.1.4 by Pereba
;
;
; *Now allows storage of custom colors!
; Usage: /setCustomColor <Nick> <Hex Color Code> - Example: /setCustomColor JohnDoe F854A7
; /delCustomColor <Nick> - Example: /delCustomColor JohnDoe
;
; *Colors are now calculated once and stored as needed for both random and custom colors
; This decreases CPU time (especially on bouncer playback) for each line displayed
; Custom colors persist between sessions (stored as rcolorscustom in your AdiIRC folder)
;
; *Buffer playback from bouncers is now properly supported without mangling output
;
; **NOTE: The built-in "Use Random Nick Colors" (Options -> Nick Colors) must be disabled for this script to work
; **NOTE: Any nick colors set in the AdiIRC options menu override random or custom colors set by this script
;
; Thanks to pereba for the original inspiration script and kr0n for troubleshooting help, as well as
; introducing me to hashtables :)
;
; For any of the output strings, if you don't want to show usermodes, you can replace $nick($chan, $nick).pnick
; with just plain $nick
;
; If you're curious, $chr(61442) is a special AdiIRC character that interprets the following string as a hex
; color code and allows for colorizing text
;
; If the script is acting weird for you, consider updating to the latest release or beta of AdiIRC;
; some of this code relies on features or bufixes in later versions
;
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This is the initialization section, it handles actions to take when the script is loaded for
; the first time or reloaded,
;
;
; whenever the script is loaded for the first time or reloaded, call /savereload,
; which saves the rcolors and rcolorscustom hashtables to disk, clears them from memory,
; then reloads them--this also handles reloading them from disk when AdiIRC first starts
;
on *:LOAD:savereload
on *:START:{
hadd -m rcolors 0bgcolor $color(34)
savereload
}
;
; save & overwrite the rcolors & rcolorscustom hashtables to disk on exit
;
on *:Exit:{
hsave -o rcolors rcolors
hsave -o rcolorscustom rcolorscustom
}
; dump all cached colors when the options screen is loaded; this ensures no stale colors are used
; if the background color is changed, since they might not be easy enough to see
on *:OPTIONS:{
if ($hget(rcolors,0bgcolor) != $color(34)) {
reset
}
if ($readini($adiircini,n,NickColors,NickColorsEntireLine) == True) {
set -e %rcolors_ColorEntireLine True
}
else {
unset %rcolors_ColorEntireLine
}
}

;
; This section responds to normal in-channel text events
;
on &^*:TEXT:*:#:{
;
; Stop here if user turned off script
;
if (%rcolors_disabled) return
;
; Disable script on blacklisted networks/channels
;
if ($network $+ . $+ # isin %rcolors_blacklist) return
;
; Check if message is ZNC buffer playback and use values accordingly
; ZNC buffer playback has different message content than a normal message and needs different handling
;
var %time $spacefix($asctime($iif($msgstamp, $v1, $ctime), $timestampfmt))
var %pnick $iif($nick(#,$nick).cnick, $v1, $nick)
;;$nick($chan, $nick).pnick
; build the echo string
;;;echo -vrlmbfw2 # %time $replace($replace($prefixuser, $chr(32), $chr(160)), $ $+ pnick, $+($chr(61442), $getcolor, %pnick, $chr(3))) $1-
var %linecolor $chr(3) $+ $chr(61442) $+ $getcolor
var %prefixuser $replace($prefixuser,$!pnick,%pnick,$chr(32),$chr(160))
var %msg $msgx

; Color entire prefixuser or just the nick? follow user preference:
if (%rcolors_ColorEntirePrefixUser) {
var %prefixuser %linecolor $+ $replace($prefixuser,$!pnick,%pnick,$chr(32),$chr(160)) $+ $chr(3)
}
else {
var %prefixuser $replace($prefixuser,$!pnick,%linecolor $+ %pnick $+ $chr(3),$!nick,%linecolor $+ %pnick $+ $chr(3),$chr(32),$chr(160))
}
; If Options -> Nick Colors -> Color entire line is enabled:
if (%rcolors_ColorEntireLine) {
%prefixuser = %prefixuser $+ %linecolor
%msg = $regsubex(%msg,$patLine,%linecolor)
if (%rcolors_ColorTimestamp) { %time = %linecolor $+ $regsubex(%time,$patLine,%linecolor) $+ $chr(3) }
}
%msg = %time %prefixuser %msg
echox -vrlmbfw2 # %msg
halt
}
;
; This section handles ACTIONs, like /me or /emote commands
; Mostly the same as PRIVMSG but with the output string adjusted to properly display these types of messages
;
on &^*:ACTION:*:#:{
;
; Stop here if user turned off script
;
if (%rcolors_disabled) return
var %time $spacefix($asctime($iif($msgstamp, $v1, $ctime), $timestampfmt))
var %pnick $iif($nick(#,$nick).cnick, $v1, $nick)
var %msg %time $replace($replace($prefixemote, $chr(32), $chr(160)), $ $+ pnick, $+($chr(61442), $getcolor, %pnick, $chr(3))) $msgx
;build the echo string
echox -vrlmbfw2c action # %msg
halt
}

;
; User own text
;
on *:INPUT:#: {
;
; Stop here if user turned off script
;
if (%rcolors_disabled) return
if (($left($1,1) != /) || ($ctrlenter) || ($regex($1,/^(\/{1,4})(me|action)/i)) && ($status == connected) {
var %time $spacefix($asctime($iif($msgstamp, $v1, $ctime), $timestampfmt))
var %pnick $iif($nick(#,$nick).cnick, $v1, $nick)
var %linecolor $chr(3) $+ $chr(61442) $+ $getcolor
var %msgxraw $replacex($iif($regml(1), $iif($len($regml(1)) > 1,$($mid($msgx,$calc($len($1) +2)),2),$mid($msgx,$calc($len($1) +2))), $msgx),$chr(9),$chr(160))
var %msg %msgxraw
; Color entire prefixuser or just the nick? follow user preference:
if (%rcolors_ColorEntirePrefixUser) {
var %prefixuser %linecolor $+ $replace($iif($regml(2),$prefixemote,$prefixuser),$!pnick,%pnick,$chr(32),$chr(160)) $+ $chr(3)
}
else {
var %prefixuser $replace($iif($regml(2),$prefixemote,$prefixuser),$!pnick,%linecolor $+ %pnick $+ $chr(3),$!nick,%linecolor $+ %pnick $+ $chr(3),$chr(32),$chr(160))
}

; If Options -> Nick Colors -> Color entire line is enabled: (except /action msg)
if (%rcolors_ColorEntireLine && !$regml(2)) {
%prefixuser = %prefixuser $+ %linecolor
%msg = $regsubex(new,%msgxraw,$patLine,%linecolor)
if (%rcolors_ColorTimestamp) { %time = %linecolor $+ $regsubex(time,%time,$patLine,%linecolor) $+ $chr(3) }
}

; Action VS regular message
if ($regml(2)) {
var %msgx %time %prefixuser $+ $chr(3) %msgxraw, %text PRIVMSG $active : $+ $chr(1) $+ ACTION %msgxraw $+ $chr(1)
echox -vw2c action # %msgx
}
else {
var %msgx %time %prefixuser %msg, %text PRIVMSG $active : $+ %msgxraw
echox -vw2c own # %msgx
}
.rawx %text
halt
}
}

;
; Coloring nicklist
;
on me:*:join:#:{
; If enabled continue
if (%rcolors_nicklist) {
.timer 1 3 clinergb #
}
}

on *:JOIN:#:{
; If enabled continue
if (%rcolors_nicklist) {
cline -b $rgb( [ $hex2rgb($iif(%rcolors_nicklistbg == 1, $getDarkColor($nick), $getBrightColor($nick))) ] ) $nick
}
}
; credits @ http://forums.mirc.com/ubbthreads.php/topics/153480/HEX_=%3E_RGB?
alias hex2rgb {
$iif($isid,return,echo -a) $+($base($left($1,2),16,10),$chr(44),$base($mid($1,3,2),16,10),$chr(44),$base($right($1,2),16,10))
}

alias -l clinergb {
if ($istok(%rcolors_blacklist,$network $+ . $+ $1,32)) {
var %rcolors_disabled 1
}
var %n $nick($1,0)
while (%n) {
cline $iif(%rcolors_nicklist && %rcolors_disabled != 1,-b $rgb( [ $hex2rgb($iif(%rcolors_nicklistbg == 1, $getDarkColor($nick($1,%n)), $getBrightColor($nick($1,%n)))) ] ), -r) $1 $nick($1,%n)
dec %n
}
}

alias -l resetNicklist {
tokenize 32 $regsubex($str(x,$chan(0)),/x/g,\n $chr(32))
clinergb $chan($*)
}

; credits Kin @ GeekShed
alias -l patLine return /\co|(\cc(?!\d(?:\d(?:,\d\d?)?)?))/gu

alias -l spacefix {
return $replacex($1,$chr(32),$chr(160))
}

alias -l getcolor {
; Initialize %color as neutral grey in case we end up with nothing else to return
var %color = 888888
; Check if nick has a custom color set in AdiIRC options; if it does, return that color
if ($nick(#, $nick).color > 1) {
var %color = $getHexOfColor($nick(#, $nick).color))
return %color
}
; Check if nick has a script-custom color; if it does, return that color
else if ($hget(rcolorscustom, $nick)) {
var %color = $hget(rcolorscustom, $nick)
return %color
}
; Check if nick has a cached color, if it does, return that color
else if ($hget(rcolors, $nick)) {
var %color = $hget(rcolors, $nick)
return %color
}
; If no cached or custom colors are found, roll for a new color and add it to the cache
else {
var %color $iif(%rcolors_bg == 1, $getDarkColor, $getBrightColor)
hadd -m rcolors $nick %color
return %color
}
; If something fails, return %color as originally set to 888888
return %color
}

;
;
;
; This is the alias for generating bright colors
;
alias -l getBrightColor {
;
; Generate a unique seed number by calculating the MD5 hash of a nick, interpreting the last 8 characters as a hex number, then converting that to decimal
;
;;;var %nickSeedNum = $base($right($md5($nick),8),16,10)
var %nickSeedNum = $base($right($md5($iif($1,$1,$nick)),8),16,10)
;
; Multiply by a high prime number, then take the modulus of a prime number < 255 to get 3 values for R,G,B color; this induces a bit more variety in the colors, and
; for whatever reason (I'm not a mathematician) tends to "favor" returning numbers close to 255 (brighter colors)
;
var %dec1 = $calc((%nickSeedNum * 7793) % 251)
var %dec2 = $calc((%nickSeedNum * 5153) % 241)
var %dec3 = $calc((%nickSeedNum * 3623) % 239)
;
; Take the average of the RGB values
;
var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)
;
; Generate colors until you get one that is "bright" (average RGB value > 128)
; If you find these colors are too dark or bright, you can adjust the %decaverage <= 128
;
while (%decaverage <= 128) {
var %dec1 = $calc((%dec1 * 7793) % 251)
var %dec2 = $calc((%dec2 * 5153) % 241)
var %dec3 = $calc((%dec3 * 3623) % 239)
var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)
}
;
; call $RGBToHex to turn the RGB Value into a hex color code and return that code
;
var %brightColorReturn = $RGBToHex(%dec1,%dec2,%dec3)
return %brightColorReturn
}
;
; This is the alias for generating dark colors
; It's the same as $getBrightColor but looks for colors that are "dark", or have
; average RGB value < 128 - Again you can tweak the %decaverage <= 128 if they're too dark or bright
;
alias -l getDarkColor {
;var %nickSeedNum = $base($right($md5($nick),8),16,10)
var %nickSeedNum = $base($right($md5($iif($1,$1,$nick)),8),16,10)
var %dec1 = $calc((%nickSeedNum * 7793) % 113)
var %dec2 = $calc((%nickSeedNum * 5153) % 127)
var %dec3 = $calc((%nickSeedNum * 3623) % 131)
var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)

while (%decaverage >= 128) {
var %dec1 = $calc((%dec1 * 7793) % 113)
var %dec2 = $calc((%dec2 * 5153) % 127)
var %dec3 = $calc((%dec3 * 3623) % 131)
var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)
}
var %darkColorReturn = $RGBToHex(%dec1,%dec2,%dec3)
return %darkColorReturn
}
;
; This is the alias for converting RGB values to Hex, used here for getting hex strings to put
; after $chr(61442) - see top if you're not sure what this character is
;
; it takes in 3 numbers from 0-255, converts them to hex numbers,
; then returns them as a single string, EG $RGBToHex(255,255,255) or "White" returns FFFFFF
;
alias -l RGBToHex {
var %RtoHex = $base($1,10,16,2)
var %GtoHex = $base($2,10,16,2)
var %BtoHex = $base($3,10,16,2)
var %HexCodeReturn = %RToHex $+ %GToHex $+ %BToHex
return %HexCodeReturn
}
;
; This is the alias for determining if your background is bright
;
; Average RGB of 100 seems to work well for determining if background is light or dark,
; but if you find the script is using colors that aren't showing well you might want to
; adjust this
;
alias -l isBackgroundBright {
;
; get the backgound color
;
var %bgRGB = $rgb($iif($1,$color(27),$color(34)))
;
; strip out the commas and replace them with the + sign
;
var %bgRGB = $replace(%bgRGB,$chr(44),$chr(43))
;
; evaluate the string from above
;
var %bgRGBAverage = $calc((%bgRGB)/3)
;
; check if the average RGB value of the background is > 100;
; return 1 if it is (bright) or 0 if it isn't (dark)
;
if (%bgRGBAverage >= 100) {
return 1
}
else return 0
}

;
; This is the alias that gets the hex value of numbered config colors
; https://dev.adiirc.com/projects/adiirc/wiki/Extra_Colors
;
; It is used in this script only to keep nicks with custom colors set using
; those colors instead of picking random colors
;
alias -l getHexOfColor {
;
; get the specified color's R,G,B value
var %colorToGet = $rgb($color($1))
;
; tokenize the string returned above with commas ($chr(44)) as delimiter; pass those values into the $RGBToHex alias and return the value
tokenize 44 %colorToGet
return $RGBToHex($1,$2,$3)
}
;
; This is the alias for setting custom nick colors, it takes a Nick and a hex color code as arguments
; EXAMPLE /setCustomColor JohnDoe f854a7
;
alias setCustomColor {
; typing just /setcustomcolor returns rudimentary help
; otherwise write the nick+color to hash table rcolorscustom and save to disk
$iif($1, /echo -at $+($chr(61442),$2) Set this color for nick $1, /echo -at Usage: /setCustomColor <Nick> <Hex Color Code> Example: /setCustomColor JohnDoe F854A7)
hadd -m rcolorscustom $1 $2
hsave -o rcolorscustom rcolorscustom
}
;
; This is the alias for deleting custom nick colors, it takes only a nick as an argument
; EXAMPLE /delCustomColor JohnDoe
alias delCustomColor {
; typing just /delcustomcolor returns rudimentary help
; otherwise remove nick+color from hash table rcolorscustom and save to disk
$iif($1, echo -at Trying to remove custom color for $1, /echo -at Usage: /delCustomColor <Nick> Example: /delCustomColor JohnDoe)
hdel rcolorscustom $1
hsave -o rcolorscustom rcolorscustom
}
;
; This is the alias for clearing all cached random colors
; It empties the rcolors hashtable, then saves the empty table back to the disk
; It is generally used in this script for ensuring that colors adjust accordingly to background color changes
;
alias -l reset {
; Remove all cached colors
if ($hget(rcolors)) {
.hdel -w rcolors *
savereload
}
; Check if background is light or dark and set %rcolors_bg accordingly
;;;set %rcolors_bg $isBackgroundBright
set %rcolors_bg $iif($var(%rcolors_forcestyle,1).value != $null,$v1,$isBackgroundBright)
rcolors_resetnicklist
}
alias -l rcolors_resetnicklist {
set %rcolors_nicklistbg $iif($var(%rcolors_nickliststyle,1).value != $null,$v1,$isBackgroundBright(nicklist))
}
;
; This is the alias for saving & reloading cached & custom colors to disk. It is primarily used on first run, or when
; settings are changed and need to be stored
;

alias savereload {
; check if the rcolors hashtable exists, if it does, save it to disk, purge all entries from memory and reload it.
; it also checks if the hashtable is too large (more than 1000 entries) and purges it if that's the case
; if the hashtable is purged, colors will be recalculated and entered the next time a person speaks
if ($hget(rcolors)) {
if ($hget(rcolors,0).item > 1000) {
.hdel -w rcolors *
}
hsave -o rcolors rcolors
.hdel -w rcolors *
hload rcolors rcolors
}
else {
hmake rcolors 100
}
; same as above, but with rcolorscustom
; rcolorscustom will also never be auto-cleared
if ($hget(rcolorscustom)) {
hsave -o rcolorscustom rcolorscustom
.hdel -w rcolorscustom *
hload rcolorscustom rcolorscustom
}
else {
hmake rcolorscustom 100
}
}

menu channel {
RGB Random Nick Colors
.Disable in #
..$iif($network $+ . $+ # isin %rcolors_blacklist,$style(1)) Yes:set %rcolors_blacklist $addtok(%rcolors_blacklist,$network $+ . $+ #,32) | clinergb #
..$iif($network $+ . $+ # !isin %rcolors_blacklist,$style(1)) No:set %rcolors_blacklist $deltok(%rcolors_blacklist,1,$network $+ . $+ #) | clinergb #
}

menu menubar {
RGB Random Nick Colors
.$iif(!%rcolors_disabled,$style(1)) Enabled:$iif(%rcolors_disabled,unset %rcolors_disabled,set %rcolors_disabled 1) | $iif(%rcolors_nicklist,scid -a resetNicklist)
.-
.Color messages style
..$iif(%rcolors_forcestyle == $null,$style(1)) Auto:unset %rcolors_forcestyle | reset
..$iif(%rcolors_forcestyle == 0,$style(1)) Bright:set %rcolors_forcestyle 0 | reset
..$iif(%rcolors_forcestyle == 1,$style(1)) Dark:set %rcolors_forcestyle 1 | reset
.Color entire prefix user
..$iif(%rcolors_ColorEntirePrefixUser,$style(1)) Yes:set %rcolors_ColorEntirePrefixUser True
..$iif(%rcolors_ColorEntirePrefixUser != True,$style(1)) No:unset %rcolors_ColorEntirePrefixUser
.Color entire message
..$iif(%rcolors_ColorEntireLine,$style(1)) Yes:.setconfig NickColors NickColorsEntireLine True | set %rcolors_ColorEntireLine True
..$iif(%rcolors_ColorEntireLine != True,$style(1)) No:.setconfig NickColors NickColorsEntireLine False | unset %rcolors_ColorEntireLine False
.└ Including timestamp
..$iif(%rcolors_ColorTimestamp,$style(1)) Yes:set %rcolors_ColorTimestamp True
..$iif(%rcolors_ColorTimestamp != True,$style(1)) No:unset %rcolors_ColorTimestamp
.-
.$iif(%rcolors_nicklist,$style(1)) Enable nicklist colors:$iif(%rcolors_nicklist,unset %rcolors_nicklist,set %rcolors_nicklist True) | scid -a resetNicklist
.Color nicklist style
..$iif(%rcolors_nickliststyle == $null,$style(1)) Auto:unset %rcolors_nickliststyle | rcolors_resetnicklist | scid -a resetNicklist
..$iif(%rcolors_nickliststyle == 0,$style(1)) Bright:set %rcolors_nickliststyle 0 | rcolors_resetnicklist | scid -a resetNicklist
..$iif(%rcolors_nickliststyle == 1,$style(1)) Dark:set %rcolors_nickliststyle 1 | rcolors_resetnicklist | scid -a resetNicklist
}
(5-5/10)