Meta commented on a Page, jHIKa - Slaps Back It  -  Mar 29, 2012

First, I think I see what you are attempting to do with the long $replace, and I'll show you a trick I learned to make your job so much easier:

$!decode( $encode($reptok($strip($1-),$me,$nick,0,32),m) ,m)


The spaces here are necessary, as is the ! in $!decode, so don't omit them. What this will do is first encode the raw input with whatever encryption the m switch provides**, then decode that once the timer executes, returning the original string with nothing evaluated.

*I've decided to use $reptok rather than $replace, and I'll explain why later on.

**there was a specific reason for this, I think it has to do with parentheses and other such characters...

Second, the 'isin' check is an inefficient method for something like this because it runs the risk of false positives:

Say, for example, your nick is 'ger', and three other people in the channel are named "liger' 'gerbil' and 'lingerer'. (or something, I don't know)... If somebody, e.g., 'mel', slaps liger, gerbil, or lingerer, the script will trigger and you will slap mel for no reason...

Let me make a minor adjustment to that.

Because your script uses $replace, it will take any instance of 'ger' (or - your nick) in the string and replace it with 'mel'... So when mel slaps gerbil, the script will react and you will slap some person named melbil for no reason. Poor melbil! He/she's not even in the channel!

The best way to avoid these problems is to use something that only matches your nick exactly. Token identifiers work well, as can regex. Here's one regex-free way to do this:

on *:ACTION:*slaps*:#: {
  if ($istok($strip($1-),$me,32)) && (!%f1) {
    inc -u10 %f1
    .timer 1 2 describe # $!decode( $encode($reptok($strip($1-),$me,$nick,0,32),m) ,m)

This should work for our purpose, and problems will only arise if your nick happens to be 'slaps'. However, it requires that your nick be a token exactly as is, so if you want to take it a step further, you can use regex - replace the $istok(...) with:

$regex($1-,/(?<![][}{a-z0-9^`|-])(Q $+ $me $+ E)(?![][}{a-z0-9^`|-])/gSi)

and the $reptok can be replaced with a similar $regsubex:

$regsubex($1-,/(?<![][}{a-z0-9^`|-])(Q $+ $me $+ E)(?![][}{a-z0-9^`|-])/gSi,$nick)

What these will do is not only check to see if your nick is a token within the string, but also match if your nick is immediately surrounded by characters that can't be used in nicks (at least according to someone).

So the code becomes something like this - (And I'll set a var to the regex match pattern to make things shorter):

on *:ACTION:*slaps*:#: {
  var %rgx /(?<![][}{a-z0-9_^`|-])(Q $+ $me $+ E)(?![][}{a-z0-9_^`|-])/gSi
  if ($regex($1-,%rgx)) && (!%f1) {
    inc -u10 %f1
    .timer 1 2 describe # $!decode( $encode($regsubex($1-,%rgx,$nick),m) ,m)
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.