mIRC Home    About    Download    Register    News    Help

Print Thread
#114004 11/03/05 03:12 AM
Joined: Feb 2005
Posts: 194
A
Vogon poet
OP Offline
Vogon poet
A
Joined: Feb 2005
Posts: 194
Code:
on @*:kick:#: {
  if ($read(protect.txt,w,$+(,$knick)) { 
    kick # $nick YOU KICKED A PROTECTED USER!
  }
}
I know the responce i'm going to get is: "why don't you just use the /protect list". Well, my reply to that is that I just want to get this working temperarly. blush It should be simple enough. Just in case you don't understand what I am trying to do., I want it to kick a person who kicks a nick in the protect.txt file. Can anyone please help?


"God sometimes puts us in the dark for us to see the light"
Joined: Mar 2004
Posts: 175
Vogon poet
Offline
Vogon poet
Joined: Mar 2004
Posts: 175
Try this:

Code:
on @*:KICK:#: {
  if ($read(protect.txt,r,$knick)) {
    kick # $nick YOU KICKED A PROTECTED USER!
  }
}


- Relinsquish
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
on @*:kick:#: { 
  if ($read(protect.txt,w,$+(,* $knick *,))) {  
    kick # $nick YOU KICKED A PROTECTED USER!  
  }
}

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Missmatched brackets ($read(protect.txt,w,$+(,$knick)))

but also $+(,$knick) is the same as saying $knick on its own so its not needed.

* I assume the protect.txt is formated as...
bob
ted
bill
etc
etc

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
$+(,* $knick *,) lol now your just being crazy smile

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
lol hehehe yup, that's been said.

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I should warn that using regex has consequences that should be taken into consideration.

  • Firstly, as you may or may not know, there are many characters that have a special meaning in a regex pattern. Some of those can be found in a nickname, so they should be escaped.

    For instance in a regex | stands for alternation (or), [ ] stands for a character class, a . matches any character etc etc.

    Someone with the nick [on] would trigger on any nickname that has either an o or n in their nick in the file. The nickname jake|afk would trigger on jake or afk. Definitely not what we were looking for.

    You can escape special characters in a regex by either prefixing them with a backslash \ or by putting the pattern that needs escaping between \Q \E. Be careful! It is possible that $knick evaluates to something with \E in it, which would mess up our initial \Q \E, so that should also be escaped, fex by using a $replacecs on it.
    We'd end with something like:

    $read(protect.txt,nr,$+(/^\Q,$replacecs($knick,\E,\Q\\E\E),\E$/i))

    (for those of you wondering, we cannot use the x modifier here since the spaces are not ignored when escaped between \Q \E, or in a character class etc.)
  • Secondly, if the slashes / / do not enclose the regex, you may encounter weird results in some cases, for example if your pattern starts with an m. Try this //echo -a $regex(a,moo). You'd expect this to return 0, but in fact it gives 1. A nickname may very well start with an m, which is bound to give unrequired results.
  • Thirdly, a pattern in a regex is always case sensitive unless specified otherwise by using the i modifier (which I added in the example). If case sensitivity isn't disabled, then "FO" will not match "fo".
  • Finally, as you know, a regex matches as if there were wildcards around it when using iswm (*pattern*) unless it has been specified differently by adding boundaries around the pattern. In this case, a nickname is unique so should only match 1 nickname, not any others. The nick "one" may not match in the nick "Theone". Therefore I've added the anchors ^ and $ denoting that the matched string should start with the first letter of $knick, and end with the last letter of $knick, or in other words: a unique match.
  • Taking all of this into consideration, the easiest most straightforward method is to use the w flag with $knick. No wildcards should be added so that $read matches a unique nickname, not a false positive.

    $read(protect.txt,nw,$knick)

Even though I replied to you, this is more of a general reply to anyone using regex without being fully aware of the consequences.

Greets


Gone.
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Quote:
I$read(protect.txt,nr,$+(/^\Q,$replacecs($knick,\E,\Q\\E\E),\E$/i))


Shouldnt that be $replacecs($knick,\E,\E\\E\Q)? If you use the one you said then \\E won't work because \\ has no special meaning inside of \Q\E anyway.


New username: hixxy
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Indeed, mixed it up when typing out.


Gone.
Joined: Feb 2005
Posts: 194
A
Vogon poet
OP Offline
Vogon poet
A
Joined: Feb 2005
Posts: 194
lol. Thanks everyone! grin


"God sometimes puts us in the dark for us to see the light"

Link Copied to Clipboard