Advertisement
Guest User

Untitled

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