|
DharmaTurtle
|
DharmaTurtle
|
Hi all, I use this to auto-blue-ify and underline URLs: alias urlreg return /((?:(?:http)|(?:www)\.)\S+)|(\S+\.(?:com|org|edu|gov|net|tv|uk|cc|xxx|mil|co|us|se|fm|me|de|kr|sv|fr|jp|tk|be|ly|info|biz|us|in|mobi)\S*)/Sig
alias urlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3))
;trigger for the regex event only
on ^&$*:text:$($urlreg):*:{
;if we are in a channel, turn nick into @nick if applicable
var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)
;color all the linkes using the predefined alias above
var %msgs = $regsubex($1-, $urlreg, $urlcolor(\t))
;debugging stuffs
echo -a $1- ORIGINAL
echo -a %msgs REGSUBEX
;print the message, default timestamp, highlighting options, and nick coloring
echo -tcrl normal $iif($chan, $v1, $nick) $+(<, $chr(3), %color, %nick, $chr(3), >) %msgs
;prevent mIRC's default echo
haltdef
} However, when someone posts a line that has both a URL and color codes, the $regsubex removes the $chr(3) symbol and numbers. Is there a way to fix this? Here is (optional) code that works on input, so that way you might have an easier time of bugsquishing :] on &*:INPUT:*:{
if ($regex($1-,$urlreg) > 0) {
var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)
var %msgs = $regsubex($1-, $urlreg, $selfurlcolor(\t))
var %color = $cnick($nick).color
;debugging stuffs
echo -a $1- ORIGINAL
echo -a %msgs REGSUBEX
echo -atcr normal $+($chr(3), %color(own), <, $chr(3), $color, %nick, $chr(3), $color(own), >) %msgs
.msg $iif($chan, $v1, $target) $1-
haltdef
}
} Thanks!
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
How would you like to "fix" this? You probably want to strip the color from the original line so just use $strip(\t) inside the $regsubex instead of just \t
Last edited by Wims; 02/04/12 04:20 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
DharmaTurtle
|
DharmaTurtle
|
Sorry if I wasn't clear, but I wanted to keep the color codes.
It would be nice to have the line keep the blue and the URL underlined, but also keep whatever color codes the person added.
Thanks though!
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
Ok, update the urlreg alias: alias urlreg return /(\x03\d{1,2}(?:,\d{1,2})?|)(.*)((?:(?:http)|(?:www)\.)\S+)|(\S+\.(?:com|org|edu|gov|net|tv|uk|cc|xxx|mil|co|us|se|fm|me|de|kr|sv|fr|jp|tk|be|ly|info|biz|us|in|mobi)\S*)/ig and the $regsubex now becomes: $regsubex($1-, $urlreg,\1\2$urlcolor(\3)\1)
Edit: You can also use \K in the pattern after (.*) and remove the \1\2 in the $regsubex.
Last edited by Wims; 02/04/12 05:02 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
DharmaTurtle
|
DharmaTurtle
|
Is there a way to do it without capturing groups? Before, without the groups it was able to capture multiple URLs in a line. With your clever modification, however, it dislikes anything that has multiple matches.
Thanks very much for your assistance.
(On a semi-unrelated note, what is \K? I can't find any documentation on that bit of code.)
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
Yeah my bad, I added .* which is greedy which means that it matches as much as possible, so it "eats" any previous url, to make it non-greedy use .*? \K resets the starting point of the reported match. You can read about it there: http://www.phpfreaks.com/blog/pcre-regex-spotlight-k
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
DharmaTurtle
|
DharmaTurtle
|
Awesome, thank you very much! Everything works as I hoped it would! Here's the code for posterity's sake and future googlers. It works on input from others, as well as your own input, so yay for consistency: ;Inspired by BillGreen and http://stackoverflow.com/questions/4867035/how-do-i-change-the-color-of-links-in-mirc/6071100#6071100
;this is actually needed to bypass mIRC's parsing behavior of strtok(str, ":")
alias urlreg return /(\x03\d{1,2}(?:,\d{1,2})?|)(.*?)(((?:(?:http[s]?:)|(?:www)\.)\S+)|(?:\S+\.(?:com|org|edu|gov|net|tv|uk|cc|xxx|mil|co|us|se|fm|me|de|kr|sv|fr|jp|tk|be|ly|info|biz|us|in|mobi)\S*))/ig
alias urlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3))
alias selfurlcolor return $+($chr(3), 12, $chr(31), $1-, $chr(31), $chr(3), $color(own))
;trigger for the regex event only
on ^&$*:text:$($urlreg):*:{
;if we are in a channel, turn nick into @nick if applicable
var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)
;color all the linkes using the predefined alias above
var %msgs = $regsubex($1-, $urlreg,\1\2$urlcolor(\3)\1)
;print the message, default timestamp, highlighting options, and nick coloring
echo -tcrl normal $iif($chan, $v1, $nick) $+(<, $chr(3), $cnick($nick).color, %nick, $chr(3), >) %msgs
;prevent mIRC's default echo
haltdef
}
on &*:INPUT:*:{
if ($regex($1-,$urlreg) > 0) {
var %nick = $iif($chan, $nick($chan, $nick).pnick, $nick)
var %msgs = $regsubex($1-, $urlreg,\1\2$selfurlcolor(\3)\1)
echo -atcr normal $+($chr(3), $color(own), <, %nick, >) %msgs
.msg $iif($chan, $v1, $target) $1-
haltdef
}
} Any problems with it, I'm usually on Quakenet in #DestinySC2 under the nick bean_dharma, though I nick change every now and then.
|
|
|
|
|