Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.99 KB | None | 0 0
  1. Crystal's Script v4.6.2 ------------
  2. ; -------------------------------------------------
  3. #gum.colour on
  4. on *:input:*: {
  5. ; Don't try to do anything if user typed a command or pasted a lot of text (or pressed ctrl+enter, see below)
  6. if (/* iswm $1) || ($inpaste) return
  7. elseif ($ctrlenter) {
  8. ; Allow easy setting of modes (if enabled). +/- modes with ctrl+enter will set them in a channel. Arguments allowed.
  9. if (%gum.colour.easymodes) && ($me ison $target) && ($regex($1-,/^(?:[+-][a-z]+)+/i)) {
  10. mode $target $1-
  11. haltdef
  12. }
  13. return
  14. }
  15. ; Don't colour messages in certain rooms to avoid annoying people and/or to your preference. This line is optional.
  16. if ($istok(#Staff #Oper #Opers #Services #Services-Log #Log #Support #Appeals #Abuse,$target,32)) return
  17. ; Stop the script if the channel blocks coloured messages (channel mode +c)
  18. ; Note the $gettok since 'c' can exist in one of the arguments. I've had trouble with that previously.
  19. if (c isincs $gettok($chan($target).mode,1,32)) return
  20. ; Point of no return! We've stopped mIRC's default actions now, so we have to send the message.
  21. haltdef
  22. ; Don't edit the following three lines. They create temporary variables from the permanent ones for simplicity.
  23. var %bg %gum.colour.background, %txt  $+ %gum.colour.text, %punc  $+ %gum.colour.punctuation
  24. var %caps  $+ %gum.colour.capitals, %nick  $+ %gum.colour.nicknames
  25. var %punc2  $+ $base($right(%punc,-1),10,10,2), %punc3 $+(%punc,$chr(44),%bg)
  26. ; Preparing various variables
  27. var %regex, %chanregex, %puncregex, %nicks, %chans, %chanlist, %i 1
  28. ; Tokenize the text instead of putting it in a variable, to avoid mIRC's variable evaluation for simple maths..
  29. tokenize 32 $remove($strip($1-,rc),)
  30. ; Create a list of channels to be matched in the text, escaped to prepare it for regex.
  31. while ($chan(%i)) {
  32. %chanlist = $+(%chanlist,|\Q,$v1,\E)
  33. inc %i
  34. }
  35. ; Set the channel regular expression (for finding channels, both in channel and PM)
  36. %chanregex = /(?<=\s|[(,+%@&~?!]|(?<!\w)[])(?=#[^\s,+%@&~]{3})( $+ $right(%chanlist,-1) $+ )(?=[[:punct:]]*[\s,]|[](?!\w))/gi
  37. ; Set a slightly different nickname regular expression for queries as opposed to channels
  38. ; Queries only match you and the nick you PM, while channels match any possible nickname (and channel) to avoid big loops
  39. if ($query($target)) %regex = /(?<=\s|\s[[{]|(?<!\w)[]|[.,'"<(+%@&~/\\])(\Q $+ $me $+ \E|\Q $+ $target $+ \E)(?=[[:punct:]]*\s|['"/\\=*@.,]|[](?!\w))/gi
  40. elseif ($chan) %regex = /(?<=\s|(?<!\w)[]|[.,'"<(+%@&~/\\])(?!\d)([^-,./:-@~ ×÷]{3,})(?=[[:punct:]]*[\s,]|[/\\=*@.,]|['"](?=\S{3,}\s|[\s,])|[](?!\w))/gi
  41. ; Prepare the symbols/capitals/smileys regular expression (for simplicity later)
  42. %puncregex = /((?i:\b[OVUX][_.]+[OVUX]\b|[:;=][A-Z]\b|\b[A-Z][:;=]\B|\b(?:X[DOP]|[DOP]X)\b|[^A-Z\s])+|[A-Z]+)/g
  43. ; If we're not sending text to a PM or channel, exit
  44. else return
  45. ; Now we'll move the channels (all known) into a variable and put ctrl+o in their place (to avoid confusion with ctrl+r)
  46. tokenize 32 $mid($regsubex(chans,/ $1- /,$iif(%gum.colour.highlightchan,%chanregex,),),3,-2)
  47. ; A simple loop to move the matched channels into the %chans variable
  48. %i = 1
  49. while ($regml(chans,%i)) {
  50. %chans = %chans $v1
  51. inc %i
  52. }
  53. ; Now we'll move the nicknames into a variable (known and potential alike) and put a ctrl+r in their place
  54. tokenize 32 $mid($regsubex(nicks,/ $1- /,$iif(%gum.colour.highlightnick,%regex,),),3,-2)
  55. ; Another simple loop to move the matched nicknames into the %nicks variable
  56. %i = 1
  57. while ($regml(nicks,%i)) {
  58. %nicks = %nicks $v1
  59. inc %i
  60. }
  61. ; If we were sending to a channel, remove potential nicknames which don't exist in the channel (and put them back into the text)
  62. ; Modified to also cater for channel matches
  63. if ($chan) {
  64. var %nn, %n $numtok(%nicks,32)
  65. while (%n) {
  66. %nn = $gettok(%nicks,%n,32)
  67. if (%nn !ison $chan) && ($me !ison %nn) {
  68. tokenize 32 $regsubex($1-,//g,$iif(\n == %n,%nn,))
  69. %nicks = $deltok(%nicks,%n,32)
  70. }
  71. dec %n
  72. }
  73. }
  74. ; Now remove those pesky extra ctrl+r characters in %nicks
  75. %nicks = $remtok(%nicks,,0,32)
  76. ; Colour capital letters, emoticons and punctuation in one line since this negates a need for workarounds of any kind
  77. tokenize 32 $regsubex($1-,%puncregex,$+($iif(\1 isalpha && !$istok(XD.DX.XO.OX.XP.PX,\1,46),%caps,$iif($left(\1,1) isnum,%punc2,$iif($left(\1,1) == $chr(44) && $mid(\1,2,1) isnum,%punc3,%punc))),\1,%txt))
  78. ; Loop through each channel, colouring it and putting it back in its original place
  79. if (%chans) tokenize 32 $regsubex($1-,//g,$+(%nick,$gettok(%chans,\n,32),%txt))
  80. ; Loop through each nickname, colouring it and putting it back in its original place
  81. if (%nicks) tokenize 32 $regsubex($1-,//g,$+(%nick,$gettok(%nicks,\n,32),%txt))
  82. ; Finalise colouring and remove unnecessary colours
  83. tokenize 32 $regsubex($+(%txt,$1-,),/(?:\d\d?(?:\x2C\d\d?)?)+/g,)
  84. tokenize 32 $regsubex($1-,/\d\d?(?:\x2C\d\d?)? /g,$chr(32) )
  85. while ($1- != $regsubex($1-,/(\d\d?)(?:\x2C\d\d?)?([^]+)(\d\d?)(?:\x2C\d\d?)?/g,$iif(\1 == \3,\1\2,\1\2\3))) tokenize 32 $v2
  86. ; Put the background colour at the start (minimise character use as much as possible, even though it's a lot of code for that)
  87. ; This prevents requiring two colour codes at the start for no reason
  88. ; Also added check to add bold character to the start (if applicable)
  89. tokenize 32 $regsubex($1-,/^(\d\d?)(?!\x2C\d)(?=(.))/,$+($iif(%gum.colour.bold,),,$base(\1,10,10,1),$chr(44),$iif(\2 isnum,$base(%bg,10,10,2),%bg)))
  90. ; Message to target
  91. msg $target $1-
  92. }
  93. #gum.colour end
  94.  
  95. ; Creating the menu for this script
  96. menu channel,query {
  97. -
  98. Gummo Colour
  99. .$iif($group(#gum.colour).status == on,Disable,Enable) $+ : {
  100. $iif($group(#gum.colour).status == on,.disable,.enable) #gum.colour
  101. echo $color(info) -a Gummo's Colour Script is now $upper($group(#gum.colour).status) $+ .
  102. }
  103. .-
  104. .$gum.colour.greyed Background
  105. ..$submenu($gum.colour.submenu(background,$1))
  106. .$gum.colour.greyed Text
  107. ..$submenu($gum.colour.submenu(text,$1))
  108. .$gum.colour.greyed Punctuation
  109. ..$submenu($gum.colour.submenu(punctuation,$1))
  110. .$gum.colour.greyed Capitals
  111. ..$submenu($gum.colour.submenu(capitals,$1))
  112. .$gum.colour.greyed Nicknames
  113. ..$submenu($gum.colour.submenu(nicknames,$1))
  114. .-
  115. .$gum.colour.greyed(%gum.colour.easymodes) Easy Modes: {
  116. %gum.colour.easymodes = $iif(%gum.colour.easymodes,$false,$true)
  117. echo $color(info) -a Easy modes (typing a mode and then pressing ctrl+enter to set) are now $iif(%gum.colour.easymodes,enabled,disabled) $+ .
  118. }
  119. .$gum.colour.greyed(%gum.colour.highlightnick) Highlight Nicks: {
  120. %gum.colour.highlightnick = $iif(%gum.colour.highlightnick,$false,$true)
  121. echo $color(info) -a Nickname highlighting is now $iif(%gum.colour.highlightnick,enabled,disabled) $+ .
  122. }
  123. .$gum.colour.greyed(%gum.colour.highlightchan) Highlight Chans: {
  124. %gum.colour.highlightchan = $iif(%gum.colour.highlightchan,$false,$true)
  125. echo $color(info) -a Channel highlighting (as opposed to nickname highlighting) is now $iif(%gum.colour.highlightchan,enabled,disabled) $+ .
  126. }
  127. .$gum.colour.greyed(%gum.colour.bold) Bold Text: {
  128. %gum.colour.bold = $iif(%gum.colour.bold,$false,$true)
  129. echo $color(info) -a Bold text is now $iif(%gum.colour.bold,enabled,disabled) $+ .
  130. }
  131. .-
  132. .$gum.colour.greyed Presets
  133. ..$submenu($gum.colour.presetmenu($1))
  134. .-
  135. .$gum.colour.greyed Reset to Defaults:if ($input(Are you really sure you want to reset to defaults? All of your current settings (other than presets) will be lost!,y,Reset to Defaults?)) gum.colour.reset -hard
  136. }
  137.  
  138. ; Special submenu for selecting a colour to save time coding
  139. alias -l gum.colour.submenu {
  140. ; The alias will never call 0, so we make a workaround
  141. var %n $2 - 1
  142. var %cmd :set % $+ gum.colour. $+ $$1
  143. if (%n isnum 0-15) return $iif($(% $+ gum.colour. $+ $1,2) == %n,$style(1)) $colourname(%n) $+ %cmd %n
  144. ; We can't put 99 here or it wouldn't work, so we'll just pretend it's 16 :)
  145. if ($1 == background) && (%n == 16) return $iif(%gum.colour.background == 99,$style(1)) $colourname(99) $+ %cmd 99
  146. }
  147.  
  148. ; Special submenu for sorted presets (from temporary list, created elsewhere
  149. alias gum.colour.presetmenu {
  150. if ($1 == 1) return Save As...:gum.colour.presetsave
  151. if ($1 == 2) return Refresh List:gum.colour.presetrefresh
  152. if ($1 == 3) return -
  153. if ($1 isnum) && ($gettok(%gum.colour.presetlist,$calc($1 - 3),44)) return $replace($v1,$chr(151),$chr(32)) $+ :gum.colour.presetload $v1
  154. }
  155.  
  156. ; Simplify the menu a little by checking whether to grey-out and/or tick the options via simple maths
  157. alias -l gum.colour.greyed {
  158. var %x 0
  159. if ($group(#gum.colour).status != on) %x = %x + 2
  160. ; Allow for a tick when a variable was speficied and evaluated to $true
  161. if ($1 == $true) %x = %x + 1
  162. return $style(%x)
  163. }
  164.  
  165. ; Alias to reset variables to defaults (hard setting replaces ALL variables, soft or unspecified only fixes variables)
  166. alias -l gum.colour.reset {
  167. var %forced $false
  168. if ($1 == -hard) %forced = $true
  169. if ((%gum.colour.background !isnum 0-15) && (%gum.colour.background != 99)) || (%forced) set %gum.colour.background 1
  170. if (%gum.colour.text !isnum 0-15) || (%forced) set %gum.colour.text 3
  171. if (%gum.colour.punctuation !isnum 0-15) || (%forced) set %gum.colour.punctuation 0
  172. if (%gum.colour.capitals !isnum 0-15) || (%forced) set %gum.colour.capitals 9
  173. if (%gum.colour.nicknames !isnum 0-15) || (%forced) set %gum.colour.nicknames 11
  174. if (%gum.colour.easymodes == $null) || (%forced) set %gum.colour.easymodes $true
  175. if (%gum.colour.highlightnick == $null) || (%forced) set %gum.colour.highlightnick $true
  176. if (%gum.colour.highlightchan == $null) || (%forced) set %gum.colour.highlightchan $true
  177. if (%gum.colour.bold == $null) || (%forced) set %gum.colour.bold $false
  178. ; Refresh the preset colours list while we're at it
  179. gum.colour.presetrefresh
  180. ; If forced (hard reset), the user will expect to know
  181. if (%forced) echo $color(info) -a Gummo's Colour Script settings reset to defaults.
  182. }
  183.  
  184. ; This alias will load the specified preset colours
  185. alias -l gum.colour.presetload {
  186. var %settings $readini(gum.colour.ini,Presets,$$1)
  187. var %names background,text,punctuation,capitals,nicknames
  188. var %i 1
  189. while ($gettok(%names,%i,44)) {
  190. set $+(%,gum.colour.,$v1) $gettok(%settings,%i,44)
  191. inc %i
  192. }
  193. ; Let the user know we just loaded a preset
  194. echo $color(info) -a Preset colour configuration $qt($replace($1,$chr(151),$chr(32))) loaded.
  195. }
  196.  
  197. ; This alias will save the current colour configuration as a preset (with confirmation for over-write)
  198. alias -l gum.colour.presetsave {
  199. var %settings, %i 1
  200. var %names background,text,punctuation,capitals,nicknames
  201. var %name $input(Please enter a name to save for this colour preset:,e,Enter Preset Name)
  202. ; Replace spaces with a special dash (ASCII 151) to enable spaces in names and remove any commas for compatibility
  203. %name = $replace(%name,$chr(32),$chr(151),$chr(44),$null)
  204. if (%name) {
  205. ; Check for identical named colour preset
  206. if (!$readini(gum.colour.ini,Presets,%name)) || ($input(There is already a preset called $qt(%name) $+ . Do you want to over-write this preset?,y,Preset Already Exists)) {
  207. while ($gettok(%names,%i,44)) {
  208. %settings = $addtok(%settings,$($+(%,gum.colour.,$v1),2),44)
  209. inc %i
  210. }
  211. ; Write the data and let the user know (delete any existing entry first to enable case-sensitive renaming)
  212. remini gum.colour.ini Presets %name
  213. writeini gum.colour.ini Presets %name %settings
  214. echo $color(info) -a Preset colour configuration $qt(%name) saved.
  215. ; Refresh the presets list of it won't appear in there
  216. gum.colour.presetrefresh
  217. }
  218. }
  219. }
  220.  
  221. ; This alias refreshes the list of presets (doing it as the menu opens is too intensive)
  222. alias -l gum.colour.presetrefresh {
  223. var %presets, %i
  224. %i = $ini(gum.colour.ini,Presets,0)
  225. while (%i) {
  226. %presets = $addtok(%presets,$ini(gum.colour.ini,Presets,%i),44)
  227. dec %i
  228. }
  229. ; Sort the list of presets for purely aesthetic purposes
  230. %presets = $sorttok(%presets,44,a)
  231. set %gum.colour.presetlist %presets
  232. }
  233.  
  234. ; Use this $colourname alias as you wish; customise it such that it matches your colours 0-15.
  235. alias colourname {
  236. ; I know this could be done with a $gettok but then it would be harder to understand (and change, for that matter)
  237. var %ret
  238. if ($1 == 0) %ret = White
  239. if ($1 == 1) %ret = Black
  240. if ($1 == 2) %ret = Dark Blue
  241. if ($1 == 3) %ret = Dark Green
  242. if ($1 == 4) %ret = Red
  243. if ($1 == 5) %ret = Maroon
  244. if ($1 == 6) %ret = Purple
  245. if ($1 == 7) %ret = Orange
  246. if ($1 == 8) %ret = Yellow
  247. if ($1 == 9) %ret = Light Green
  248. if ($1 == 10) %ret = Teal
  249. if ($1 == 11) %ret = Light Blue
  250. if ($1 == 12) %ret = Blue
  251. if ($1 == 13) %ret = Pink
  252. if ($1 == 14) %ret = Dark Grey
  253. if ($1 == 15) %ret = Light Grey
  254. if ($1 == 99) %ret = No Background
  255. return %ret
  256. }
  257.  
  258. ; This just says thanks when they load the script, obviously
  259. on *:load: {
  260. echo $color(info) -a ---
  261. echo $color(info) -a Thanks for using Gummo's Colour Script. :D
  262. echo $color(info) -a Right-click in a channel or PM to customise.
  263. echo $color(info) -a ---
  264. }
  265.  
  266. ; Reset any missing variables upon startup ('soft' settings)
  267. on *:start: {
  268. gum.colour.reset -soft
  269. }
  270.  
  271. on *:unload: {
  272. unset %gum.colour.*
  273. echo $color(info) -a ---
  274. echo $color(info) -a Thanks for using Gummo's Colour Script, sorry you want to remove it. :P
  275. echo $color(info) -a All variables related to this script have been removed.
  276. if ($isfile(gum.colour.ini)) {
  277. if ($input(The presets configuration file $chr(40) $+ gum.colour.ini $+ $chr(41) has not been deleted. Would you like to delete it?,y,Delete Presets?)) {
  278. .remove gum.colour.ini
  279. echo $color(info) -a Presets configuration file deleted.
  280. }
  281. else echo $color(info) -a Presets configuration file remains.
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement