mIRC Homepage

$didhighlight in text events

Posted By: gencha

$didhighlight in text events - 07/03/08 02:56 PM

I would really like an identifier that signals me whether a received line of text triggered a highlight.
Posted By: RoCk

Re: $didhighlight in text events - 07/03/08 03:55 PM


There have been some similar requests here and here. I recall seeing a couple of others, you may want to do a search if you're interested.
Posted By: SladeKraven

Re: $didhighlight in text events - 07/03/08 04:06 PM

You are already notified if you enable tips for that highlight match, or have I got the wrong idea here?
Posted By: gencha

Re: $didhighlight in text events - 07/03/08 04:20 PM

Ah, yes, i see. I hope this makes it into the next release.

And, as i want my script distributable, i don't want to rely on users having to enable a feature, like tips, in mirc.
Posted By: gencha

Re: $didhighlight in text events - 07/03/08 07:33 PM

I can't say that i have fully tested this, but based on what i read in those two threads, i wrote this little script.
It takes a nickname and a given text as you would receive them in a text event and checks whether any highlight matches it.

Code:
; Returns whether a given string would trigger a highlight
; $1 The nick that said the text
; $2- The text
alias isHighlight {
  var %nick = $1
  var %message = $2-
  
  var %text
  
  var %highlightIdx = 1
  var %highlightText = $_highlight( %highlightIdx ).text
  var %highlightRegex = $_highlight( %highlightIdx ).regex
  var %highlightCS = $_highlight( %highlightIdx ).cs
  var %highlightNicks = $_highlight( %highlightIdx ).nicks
  var %highlightMessages = $_highlight( %highlightIdx ).messages

  while ( %highlightText != $null ) {
    %text = $null
    if ( %highlightNicks ) %text = $+( %text, $chr( 32 ), %nick )
    if ( %highlightMessages ) %text = $+( %text, $chr( 32 ), %message )
    
    if ( !%highlightCS ) {
      %text = $lower( %text )
      %highlightText = $lower( %highlightText )
    }
    
    if ( %highlightRegex ) {
      if ( $regex( %text, %highlightText ) > 0 ) return $true
    }
    elseif ( ( ? isin %highlightText ) || ( * isin %highlightText ) ) {
      if ( %highlightText iswmcs %text ) return $true
    }
    else {
      if ( $istokcs( %text, %highlightText, 32 ) ) return $true
    }

    inc %highlightIdx
    %highlightText = $_highlight( %highlightIdx ).text
    %highlightRegex = $_highlight( %highlightIdx ).regex
    %highlightCS = $_highlight( %highlightIdx ).cs
    %highlightNicks = $_highlight( %highlightIdx ).nicks
    %highlightMessages = $_highlight( %highlightIdx ).messages
  }
  
  return $false
}


Oh, and if someone can tell me if (and how) you can override an identifier (like $highlight) properly, please let me know wink

Suggestions are highly welcome.

Credits to Horstl for his inspiration on this.

edit: Case-sensitive settings are now respected.
Posted By: SladeKraven

Re: $didhighlight in text events - 07/03/08 07:47 PM

How do you mean override?
Posted By: gencha

Re: $didhighlight in text events - 07/03/08 07:52 PM

Like you could do:
Code:
alias echo {
  !echo $1- :)
}

Like overriding the internal mirc command with my own. When i tried that with $highlight it didn't work for me.
Posted By: Wims

Re: $didhighlight in text events - 07/03/08 08:49 PM

Code:
alias highlight {
if ($isid) return isid
else echo -a ok
}


/highlight will echo in the active window "ok"
/!highlight will call the internal command
$highlight will call the internal commmand
$/highlight will return isid

so $/aliasname is what you want but this have to be used carefuly imo smile
Posted By: gencha

Re: $didhighlight in text events - 07/03/08 09:09 PM

Ah, i see. That's interesting on the one hand, but doesn't provide a real advantage over my current solution *g*
Good to know nevertheless.
Thanks
© 2021 mIRC Discussion Forums