mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
I'm writing a script that allows the user to add "highlight" words to a file that the client then looks for in the channel chat, alerting the user when a "highlight" word is mentioned.

The reason I'm doing this, instead of using the mIRC highlight feature, is that I'm including some options that can be set on a "per word" basis, that mIRC doesn't cater for.

It finds partial matches fine, like if a user added "test" to the file, the script would find "this is a test" and "I'm testing something" but what I want it to do is match on the whole word only. So if they have "test" in their file, the script would only trigger on "test" and not "testing" or "fastest".

The line I'm using is:

Code:
if ($ini($scriptdirHighlights.ini,%highlightword) isin $strip($1-)) || ($ini($scriptdirHighlights.ini,%highlightword) == $strip($1)) {

I put the "||" in there to catch a "highlight" word when its seen in the channel as the first word of a sentence,because then there wouldn't be space in front of it. I don't know if its needed if I could code this properly.

I've tried variations of:

Code:
($chr(32) $+ $ini($scriptdirHighlights.ini,%highlightword) $+ $chr(32))

and after failing to find any answers on this forum, or online, I also tried

Code:
($chr(32) [ $+ [ $ini($scriptdirHighlights.ini,%highlightword) ] $+ ])

Which is probably horribly wrong, but I'm utterly out of ideas, and knowledge.

This is the last hurdle that I have to get over before my script is completed. Please can someone show me how to do this?

Thanks

Panda

Sorry about the terrible subject title, I just couldn't work out how to describe my problem in a few words.

Last edited by Panda; 24/02/15 06:34 PM. Reason: Edited to try and make my question more clear
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
How about you remake the script to not use "isin" and use "$istok(...,32)" instead?


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
This totally worked laugh

Code:
if ($istok($1-,$ini($scriptdirHighlights.ini,%highlightword),32))


Thanks @Nillen

Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
So, its working REALLY well ... doing exactly as its been coded to do ... but if, for example, the word its looking for is "test", it wont trigger if its followed by any "." or ",".

I know this is because its using $chr(32) as a delimiter and its working exactly its its been told to, but how do I cater for this? Is there a way to ignore all the "." and "," in the string before it checks so that test, and test. still trigger the script?

Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
Ok,so I figured it out ... it works but I'm not sure I've done it the correct way.

Code:
if ($istok($remove($1-,$chr(44),$chr(46)),$ini($scriptdirHighlights.ini,%highlightword),32))

Is this the best way to do it?

Panda

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Welcome to regular expressions: http://www.regular-expressions.info/wordboundaries.html

Code:
//tokenize 32 this is a test | echo -ag $regex($1-,/\btest\b/iS)

Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
Thanks @Loki12583

So, using your method, would the following be the correct application to my earlier example where I used $remove ?

Code:
on *:TEXT:*:#: {
    tokenize 32 $1-
    if ($regex($1-,/\b($ini($scriptdirHighlights.ini,%highlightword))\b/iS) >= 1) {
      do stuff
    }
}

If I've got this wrong (which I think I may have), could you please explain how I might better use the $regex method?

Thanks smile

Panda

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
You've got it, except the tokenize line was just to fill $1- with that text for testing and you need to separate the identifier because it won't be evaluated if it's touching other text.

Code:
var %word = $ini($scriptdirKC-ScriptPackv2-Highlights.ini,%numberofhighlights)
var %regex = $+(/\b,%word,\b/iS)
if ($regex($1-,%regex)) {
  echo -ag match
}

Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
I see ... ok that makes sense smile

Just a thought, but would this still trigger on test if the string it was looking at was:

This is a,test,string!

and if not, how would I cater for bad grammar lol

Right now I'm using the following, inspired from @Nillen's advice:

Code:
if ($istok($replace($1-,$chr(33),$chr(32),$chr(34),$chr(32),$chr(44),$chr(32),$chr(46),$chr(32),$chr(60),$chr(32),$chr(62),$chr(32),$chr(63),$chr(32)),$ini($scriptdirHighlights.ini,%highlightword),32))


Which looks (and is) terribly clumsy, but I keep bumping into my own lack of knowledge.

It actually works well but everytime I see that line, I wince a little because its anything but elegant lol

Thanks @Loki12583

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
May I ask the seperate options you are supplying for the user?

is it something like:
Match as whole work only=word1 word2
Match as word part=word3 word4

Code:
alias -l safeRegex return $regsubex($1-, /([^a-z\d_-])/g, \E\ $+ \t $+ \Q)



if (*word* isin $strip($1-)) {
  ;; matches for "word" anywhere in text
}
elseif ($regex($strip($1-), /\b\Q $+ $safeRegex(word) $+ \E\b/i)) {
  ;; matches "word" as a whole word only (can be preceded or followed by punctuation)
}
elseif ($regex($strip($1-), /\b\Q $+ $safeRegex(word) $+ \E/i)) {
  ;; matches if "word" is the start of a word(can have punctuation before, anything after)
}
elseif ($regex($strip($1-), /\Q $+ $safeRegex(word) $+ \E\b/i)) {
  ;; matches if "word" is the end of a word (anything before, punctuation after)
}



Last edited by FroggieDaFrog; 24/02/15 10:53 PM.

I am SReject
My Stuff
Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
Yep, the script will be giving the user various options, among them are:

Whole word only
Partial matches
Beginning with
Ending with (not sure how useful this option will be, may scratch it)
Choice of visual and/or audio alerts
Logging system for the words the user has chosen
Teleport me to this message (which will take the user to the window (and position in that window) where the word was triggered)
Timed alerts (choose during what times of the day you want to be alerted, basically a DND function)
Morning reports (a window that presents everything you missed during the time you were away)

I've got most of it working the way I want it to, the main issue that was holding me back was getting the $remove, $replace or $regex technique down, so that I wasn't just limited to partial matches based on the isin return (which I hated lol)

Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
@FroggieDaFrog

Oh cool ... thanks for those examples smile

So would I be correct in saying that, for my use, this would be the correct syntax?

Code:
elseif ($regex($strip($1-), /\b\Q $+ $safeRegex($ini($scriptdirHighlights.ini,%highlightword),32)) $+ \E\b/i)) {
  ;; matches "word" as a whole word only (can be preceded or followed by punctuation)
}

Joined: Nov 2014
Posts: 32
P
Panda Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Nov 2014
Posts: 32
@Loki12583

Unfortunately, I'm writing this for my staff, so not really in a position to be able to tell them to, as you say, "write their own" ... would be nice if I could though lol :P

Panda


Link Copied to Clipboard