Guest User

Untitled

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