Project

General

Profile

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

Mr. BS, 05/10/2016 10:07 PM

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

    
3
; Hackjob full-palette Random Nick Color script for AdiIRC
4
; Generate consistent but random, full-palette colors for nicks & set custom colors as you please
5
;
6
; Version 1.2 - Fork v0.1.5 by Pereba
7
;
8
;
9
; *Now allows storage of custom colors!
10
;		Usage: /setCustomColor <Nick> <Hex Color Code> - Example: /setCustomColor JohnDoe F854A7
11
;				/delCustomColor <Nick> - Example: /delCustomColor JohnDoe
12
;
13
; *Colors are now calculated once and stored as needed for both random and custom colors
14
;	This decreases CPU time (especially on bouncer playback) for each line displayed
15
; 	Custom colors persist between sessions (stored as rcolorscustom in your AdiIRC folder)
16
;
17
; *Buffer playback from bouncers is now properly supported without mangling output
18
;
19
; **NOTE: The built-in "Use Random Nick Colors" (Options -> Nick Colors) must be disabled for this script to work 
20
; **NOTE: Any nick colors set in the AdiIRC options menu override random or custom colors set by this script
21
;
22
; Thanks to pereba for the original inspiration script and kr0n for troubleshooting help, as well as 
23
; introducing me to hashtables :)
24
;
25
; For any of the output strings, if you don't want to show usermodes, you can replace $nick($chan, $nick).pnick
26
;  with just plain $nick
27
;
28
; If you're curious, $chr(61442) is a special AdiIRC character that interprets the following string as a hex 
29
; color code and allows for colorizing text
30
;
31
; If the script is acting weird for you, consider updating to the latest release or beta of AdiIRC; 
32
; some of this code relies on features or bufixes in later versions
33
;
34
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35
;
36
; This is the initialization section, it handles actions to take when the script is loaded for 
37
; the first time or reloaded, 
38
;
39
;
40
; whenever the script is loaded for the first time or reloaded, call /savereload, 
41
; which saves the rcolors and rcolorscustom hashtables to disk, clears them from memory, 
42
; then reloads them--this also handles reloading them from disk when AdiIRC first starts
43
;
44
on *:LOAD:savereload
45
on *:START:{
46
  hadd -m rcolors 0bgcolor $color(34)
47
  savereload
48
}
49
;
50
; save & overwrite the rcolors & rcolorscustom hashtables to disk on exit
51
;
52
on *:Exit:{
53
hsave -o rcolors rcolors
54
hsave -o rcolorscustom rcolorscustom
55
}
56
; dump all cached colors when the options screen is loaded; this ensures no stale colors are used
57
; if the background color is changed, since they might not be easy enough to see
58
on *:OPTIONS:{
59
  if ($hget(rcolors,0bgcolor) != $color(34)) {
60
    reset
61
  }
62
  if ($readini($adiircini,n,NickColors,NickColorsEntireLine) == True) {
63
    set -e %rcolors_ColorEntireLine True
64
  }
65
  else {
66
    unset %rcolors_ColorEntireLine
67
  }
68
}
69

    
70
;
71
; This section responds to normal in-channel text events
72
;
73
on &^*:TEXT:*:#:{
74
;
75
; Stop here if user turned off script
76
;
77
if (%rcolors_disabled) return
78
;
79
; Disable script on blacklisted networks/channels
80
;
81
if ($network $+ . $+ # isin %rcolors_blacklist) return
82
;
83
; Check if message is ZNC buffer playback and use values accordingly
84
; ZNC buffer playback has different message content than a normal message and needs different handling
85
;
86
  var %time $spacefix($asctime($iif($msgstamp, $v1, $ctime), $timestampfmt))
87
  var %pnick $iif($nick(#,$nick).cnick, $v1, $nick)
88
  ;;$nick($chan, $nick).pnick
89
; build the echo string
90
  ;;;echo -vrlmbfw2 # %time $replace($replace($prefixuser, $chr(32), $chr(160)), $ $+ pnick, $+($chr(61442), $getcolor, %pnick, $chr(3)))  $1-
91
  
92
  var %linecolor $chr(3) $+ $chr(61442) $+ $getcolor
93
  var %prefixuser $replace($prefixuser,$!pnick,%pnick,$chr(32),$chr(160))
94
  var %msg $msgx
95
  ; check if message triggered a highlight to use respective color in echo
96
  var %h $highlight($iif($1- !isnum,$v1))
97

    
98
  ; Color entire prefixuser or just the nick? follow user preference:
99
  if (%rcolors_ColorEntirePrefixUser) {
100
    var %prefixuser %linecolor $+ $replace($prefixuser,$!pnick,%pnick,$chr(32),$chr(160)) $+ $chr(3)
101
  }
102
  else {
103
    var %prefixuser $replace($prefixuser,$!pnick,%linecolor $+ %pnick $+ $chr(3),$!nick,%linecolor $+ %pnick $+ $chr(3),$chr(32),$chr(160))
104
  }
105
  
106
  ; If Options -> Nick Colors -> Color entire line is enabled:
107
  if (%rcolors_ColorEntireLine && !%h) {
108
    %prefixuser = %prefixuser $+ %linecolor
109
    %msg = $regsubex(%msg,$patLine,%linecolor)
110
    if (%rcolors_ColorTimestamp) { %time = %linecolor $+ $regsubex(%time,$patLine,%linecolor) $+ $chr(3) }
111
  }
112
  
113
  %msg = %time %prefixuser %msg
114
  echox -vrlmbfw2 # %msg
115
  halt
116
}
117
;
118
; This section handles ACTIONs, like /me or /emote commands
119
; Mostly the same as PRIVMSG but with the output string adjusted to properly display these types of messages
120
;
121
on &^*:ACTION:*:#:{
122
  ;
123
  ; Stop here if user turned off script
124
  ;
125
  if (%rcolors_disabled) return
126
  var %time $spacefix($asctime($iif($msgstamp, $v1, $ctime), $timestampfmt))
127
  var %pnick $iif($nick(#,$nick).cnick, $v1, $nick)
128
  var %msg %time $replace($replace($prefixemote, $chr(32), $chr(160)), $ $+ pnick, $+($chr(61442), $getcolor, %pnick, $chr(3))) $msgx
129
;build the echo string  
130
  echox -vrlmbfw2c action # %msg
131
  halt 
132
}
133

    
134
;
135
; User own text
136
;
137
on *:INPUT:#: {
138
  ;
139
  ; Stop here if user turned off script
140
  ;
141
  if (%rcolors_disabled) return
142
  
143
  if (($left($1,1) != /) || ($ctrlenter) || ($regex($1,/^(\/{1,4})(me|action)/i)) && ($status == connected) {
144
    var %time $spacefix($asctime($iif($msgstamp, $v1, $ctime), $timestampfmt))
145
    var %pnick $iif($nick(#,$nick).cnick, $v1, $nick)
146
    var %linecolor $chr(3) $+ $chr(61442) $+ $getcolor   
147
    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))
148
    var %msg %msgxraw
149
    
150
    ; Color entire prefixuser or just the nick? follow user preference:
151
    if (%rcolors_ColorEntirePrefixUser) {
152
      var %prefixuser %linecolor $+ $replace($iif($regml(2),$prefixemote,$prefixuser),$!pnick,%pnick,$chr(32),$chr(160)) $+ $chr(3)
153
    }
154
    else {
155
      var %prefixuser $replace($iif($regml(2),$prefixemote,$prefixuser),$!pnick,%linecolor $+ %pnick $+ $chr(3),$!nick,%linecolor $+ %pnick $+ $chr(3),$chr(32),$chr(160))
156
    }
157

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

    
165
    ; Action VS regular message
166
    if ($regml(2)) {
167
      var %msgx %time %prefixuser $+ $chr(3) %msgxraw, %text PRIVMSG $active : $+ $chr(1) $+ ACTION %msgxraw $+ $chr(1)
168
      echox -vw2c action # %msgx
169
    }
170
    else {
171
      var %msgx %time %prefixuser %msg, %text PRIVMSG $active : $+ %msgxraw
172
      echox -vw2c own # %msgx
173
    }
174
    .rawx %text
175
    halt
176
  }
177
}
178

    
179
;
180
; Coloring nicklist
181
;
182
on me:*:join:#:{
183
  ; If enabled continue
184
  if (%rcolors_nicklist) {
185
    .timer 1 3 clinergb #
186
  }
187
}
188

    
189
on *:JOIN:#:{
190
  ; If enabled continue
191
  if (%rcolors_nicklist) {
192
    cline -b $rgb( [ $hex2rgb($iif(%rcolors_nicklistbg == 1, $getDarkColor($nick), $getBrightColor($nick))) ] ) $nick
193
  }
194
}
195
; credits @ http://forums.mirc.com/ubbthreads.php/topics/153480/HEX_=%3E_RGB?
196
alias hex2rgb {
197
  $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))
198
}
199

    
200
alias -l clinergb {
201
  if ($istok(%rcolors_blacklist,$network $+ . $+ $1,32)) {
202
    var %rcolors_disabled 1
203
  }
204
  var %n $nick($1,0)
205
  while (%n) {
206
    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)
207
    dec %n
208
  }
209
}
210

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

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

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

    
223
alias -l getcolor {
224
; Initialize %color as neutral grey in case we end up with nothing else to return
225
  var %color = 888888
226
; Check if nick has a custom color set in AdiIRC options; if it does, return that color
227
  if ($nick(#, $nick).color > 1) {
228
    var %color = $getHexOfColor($nick(#, $nick).color))
229
    return %color
230
}
231
; Check if nick has a script-custom color; if it does, return that color
232
  else if ($hget(rcolorscustom, $nick)) {
233
    var %color = $hget(rcolorscustom, $nick)
234
    return %color
235
    }
236
; Check if nick has a cached color, if it does, return that color
237
  else if ($hget(rcolors, $nick)) {
238
    var %color = $hget(rcolors, $nick)
239
    return %color
240
  }
241
; If no cached or custom colors are found, roll for a new color and add it to the cache
242
  else {
243
    var %color $iif(%rcolors_bg == 1, $getDarkColor, $getBrightColor)
244
    hadd -m rcolors $nick %color
245
    return %color
246
  }
247
; If something fails, return %color as originally set to 888888
248
  return %color
249
}
250

    
251
;
252
;
253
;
254
; This is the alias for generating bright colors
255
;
256
alias -l getBrightColor {
257
;
258
; 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
259
;
260
  ;;;var %nickSeedNum = $base($right($md5($nick),8),16,10)
261
  var %nickSeedNum = $base($right($md5($iif($1,$1,$nick)),8),16,10)
262
;
263
; 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
264
; for whatever reason (I'm not a mathematician) tends to "favor" returning numbers close to 255 (brighter colors)
265
;
266
  var %dec1 = $calc((%nickSeedNum * 7793) % 251)
267
  var %dec2 = $calc((%nickSeedNum * 5153)  % 241)
268
  var %dec3 = $calc((%nickSeedNum * 3623) % 239)
269
;
270
; Take the average of the RGB values 
271
;
272
  var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)
273
;
274
; Generate colors until you get one that is "bright" (average RGB value > 128)
275
; If you find these colors are too dark or bright, you can adjust the %decaverage <= 128
276
;
277
  while (%decaverage <= 128) {
278
    var %dec1 = $calc((%dec1 * 7793) % 251)
279
    var %dec2 = $calc((%dec2 * 5153) % 241)
280
    var %dec3 = $calc((%dec3 * 3623) % 239)
281
    var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)
282
  }
283
;
284
; call $RGBToHex to turn the RGB Value into a hex color code and return that code
285
;
286
  var %brightColorReturn = $RGBToHex(%dec1,%dec2,%dec3)
287
  return %brightColorReturn
288
}
289
;
290
; This is the alias for generating dark colors
291
; It's the same as $getBrightColor but looks for colors that are "dark", or have
292
; average RGB value < 128 - Again you can tweak the %decaverage <= 128 if they're too dark or bright
293
;
294
alias -l getDarkColor {
295
  ;var %nickSeedNum = $base($right($md5($nick),8),16,10)
296
  var %nickSeedNum = $base($right($md5($iif($1,$1,$nick)),8),16,10)
297
  var %dec1 = $calc((%nickSeedNum * 7793) % 113)
298
  var %dec2 = $calc((%nickSeedNum * 5153) % 127)
299
  var %dec3 = $calc((%nickSeedNum * 3623) % 131)
300
  var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)
301

    
302
  while (%decaverage >= 128) {
303
    var %dec1 = $calc((%dec1 * 7793) % 113)
304
    var %dec2 = $calc((%dec2 * 5153) % 127)
305
    var %dec3 = $calc((%dec3 * 3623) % 131)
306
    var %decaverage = $calc((%dec1 + %dec2 + %dec3)/3)
307
  }
308
  var %darkColorReturn = $RGBToHex(%dec1,%dec2,%dec3)
309
  return %darkColorReturn
310
}
311
;
312
; This is the alias for converting RGB values to Hex, used here for getting hex strings to put 
313
; after $chr(61442) - see top if you're not sure what this character is
314
;
315
; it takes in 3 numbers from 0-255, converts them to hex numbers, 
316
; then returns them as a single string, EG $RGBToHex(255,255,255) or "White" returns FFFFFF
317
;
318
alias -l RGBToHex {
319
  var %RtoHex = $base($1,10,16,2)
320
  var %GtoHex = $base($2,10,16,2)
321
  var %BtoHex = $base($3,10,16,2)
322
  var %HexCodeReturn = %RToHex $+ %GToHex $+ %BToHex
323
  return %HexCodeReturn
324
}
325
;
326
; This is the alias for determining if your background is bright
327
;
328
; Average RGB of 100 seems to work well for determining if background is light or dark,
329
; but if you find the script is using colors that aren't showing well you might want to 
330
; adjust this
331
;
332
alias -l isBackgroundBright {
333
;
334
; get the backgound color
335
;
336
  var %bgRGB = $rgb($iif($1,$color(27),$color(34)))
337
;
338
; strip out the commas and replace them with the + sign
339
;
340
  var %bgRGB = $replace(%bgRGB,$chr(44),$chr(43))
341
;
342
; evaluate the string from above
343
;
344
  var %bgRGBAverage = $calc((%bgRGB)/3)
345
;
346
; check if the average RGB value of the background is > 100; 
347
; return 1 if it is (bright) or 0 if it isn't (dark)
348
;
349
  if (%bgRGBAverage >= 100) { 
350
    return 1
351
  }
352
  else return 0
353
}
354

    
355
;
356
; This is the alias that gets the hex value of numbered config colors 
357
; https://dev.adiirc.com/projects/adiirc/wiki/Extra_Colors
358
;
359
; It is used in this script only to keep nicks with custom colors set using 
360
; those colors instead of picking random colors
361
;
362
alias -l getHexOfColor {
363
;
364
; get the specified color's R,G,B value
365
  var %colorToGet = $rgb($color($1))
366
;
367
; tokenize the string returned above with commas ($chr(44)) as delimiter; pass those values into the $RGBToHex alias and return the value
368
  tokenize 44 %colorToGet
369
  return $RGBToHex($1,$2,$3)
370
}
371
;
372
; This is the alias for setting custom nick colors, it takes a Nick and a hex color code as arguments
373
; EXAMPLE /setCustomColor JohnDoe f854a7
374
;
375
alias setCustomColor {
376
; typing just /setcustomcolor returns rudimentary help
377
; otherwise write the nick+color to hash table rcolorscustom and save to disk
378
   $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)
379
   
380
   hadd -m rcolorscustom $1 $2
381
   hsave -o rcolorscustom rcolorscustom
382
}
383
;
384
; This is the alias for deleting custom nick colors, it takes only a nick as an argument
385
; EXAMPLE /delCustomColor JohnDoe
386
alias delCustomColor {
387
; typing just /delcustomcolor returns rudimentary help
388
; otherwise remove nick+color from hash table rcolorscustom and save to disk
389
   $iif($1, echo -at Trying to remove custom color for $1, /echo -at Usage: /delCustomColor  <Nick> Example: /delCustomColor JohnDoe)
390
   hdel rcolorscustom $1
391
   hsave -o rcolorscustom rcolorscustom
392
}
393
;
394
; This is the alias for clearing all cached random colors
395
; It empties the rcolors hashtable, then saves the empty table back to the disk
396
; It is generally used in this script for ensuring that colors adjust accordingly to background color changes
397
;
398
alias -l reset {
399
; Remove all cached colors
400
  if ($hget(rcolors)) {
401
    .hdel -w rcolors *
402
	savereload
403
  }  
404
; Check if background is light or dark and set %rcolors_bg accordingly
405
  ;;;set %rcolors_bg $isBackgroundBright
406
  set %rcolors_bg $iif($var(%rcolors_forcestyle,1).value != $null,$v1,$isBackgroundBright)
407
  rcolors_resetnicklist
408
}
409
alias -l rcolors_resetnicklist {
410
  set %rcolors_nicklistbg $iif($var(%rcolors_nickliststyle,1).value != $null,$v1,$isBackgroundBright(nicklist))
411
}
412
;
413
; This is the alias for saving & reloading cached & custom colors to disk. It is primarily used on first run, or when
414
; settings are changed and need to be stored
415
; 
416

    
417
alias savereload {
418
; check if the rcolors hashtable exists, if it does, save it to disk, purge all entries from memory and reload it.
419
; it also checks if the hashtable is too large (more than 1000 entries) and purges it if that's the case
420
; if the hashtable is purged, colors will be recalculated and entered the next time a person speaks
421
	if ($hget(rcolors)) {
422
		if ($hget(rcolors,0).item > 1000) {
423
			.hdel -w rcolors *
424
		}
425
		hsave -o rcolors rcolors
426
		.hdel -w rcolors *
427
		hload rcolors rcolors
428
	}
429
    else { 
430
		hmake rcolors 100
431
	}
432
; same as above, but with rcolorscustom
433
; rcolorscustom will also never be auto-cleared  
434
   if ($hget(rcolorscustom)) {
435
	hsave -o rcolorscustom rcolorscustom
436
	.hdel -w rcolorscustom *
437
	hload rcolorscustom rcolorscustom
438
	}
439
            else { 
440
            hmake rcolorscustom 100
441
            }
442
                      
443
}
444

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

    
452
menu menubar {
453
  RGB Random Nick Colors
454
  .$iif(!%rcolors_disabled,$style(1)) Enabled:$iif(%rcolors_disabled,unset %rcolors_disabled,set %rcolors_disabled 1) | $iif(%rcolors_nicklist,scid -a resetNicklist)
455
  .-
456
  .Color messages style
457
  ..$iif(%rcolors_forcestyle == $null,$style(1)) Auto:unset %rcolors_forcestyle | reset
458
  ..$iif(%rcolors_forcestyle == 0,$style(1)) Bright:set %rcolors_forcestyle 0 | reset
459
  ..$iif(%rcolors_forcestyle == 1,$style(1)) Dark:set %rcolors_forcestyle 1 | reset
460
  .Color entire prefix user
461
  ..$iif(%rcolors_ColorEntirePrefixUser,$style(1)) Yes:set %rcolors_ColorEntirePrefixUser True
462
  ..$iif(%rcolors_ColorEntirePrefixUser != True,$style(1)) No:unset %rcolors_ColorEntirePrefixUser
463
  .Color entire message
464
  ..$iif(%rcolors_ColorEntireLine,$style(1)) Yes:.setconfig NickColors NickColorsEntireLine True | set %rcolors_ColorEntireLine True
465
  ..$iif(%rcolors_ColorEntireLine != True,$style(1)) No:.setconfig NickColors NickColorsEntireLine False | unset %rcolors_ColorEntireLine False
466
  .└ Including timestamp
467
  ..$iif(%rcolors_ColorTimestamp,$style(1)) Yes:set %rcolors_ColorTimestamp True
468
  ..$iif(%rcolors_ColorTimestamp != True,$style(1)) No:unset %rcolors_ColorTimestamp
469
  .-
470
  .$iif(%rcolors_nicklist,$style(1)) Enable nicklist colors:$iif(%rcolors_nicklist,unset %rcolors_nicklist,set %rcolors_nicklist True) | scid -a resetNicklist
471
  .Color nicklist style
472
  ..$iif(%rcolors_nickliststyle == $null,$style(1)) Auto:unset %rcolors_nickliststyle | rcolors_resetnicklist | scid -a resetNicklist
473
  ..$iif(%rcolors_nickliststyle == 0,$style(1)) Bright:set %rcolors_nickliststyle 0 | rcolors_resetnicklist | scid -a resetNicklist
474
  ..$iif(%rcolors_nickliststyle == 1,$style(1)) Dark:set %rcolors_nickliststyle 1 | rcolors_resetnicklist | scid -a resetNicklist
475
}
(6-6/10)