mIRC Homepage
Posted By: Breno script request! - 14/04/05 04:04 PM
how does to ban automatically anybody what join with the identd with a letter and 2 or more varied numbers? Ex: ~a1234, ~x8734, ~z21... ** on !*:join:#:{ if ($regex ...? **
Posted By: Riamus2 Re: script request! - 14/04/05 04:26 PM
Probably not the best way to do this, but...

on @*:join:#chan: {
var %ident $gettok($gettok($address($nick,0),2,33),1,64)
if ($mid(%ident,2,1) isletter && $mid(%ident,3,20) isnum) {
ban -k $chan $nick
}
}

You can change the ban to be on one of the $address types if you wanted a different type of ban. This should do what you want.

As I said, there may be a better way to do this. This is just what I did while I work. smile
Posted By: BarGarth Re: script request! - 14/04/05 06:34 PM
a possible regex solution instead of

if ($mid(%ident,2,1) isletter && $mid(%ident,3,20) isnum) {

is:

if ($regex(%ident,^[a-zA-Z][0-9][0-9]+$)) {

it now takes all digits instead of the first 20 you specified
Posted By: Riamus2 Re: script request! - 14/04/05 06:38 PM
Yeah, I don't really know much about $regex codes. I just put 20 since the likelihood of an ident with over 20 characters is minimal... and even if there were more than 20 characters in it, if you have 20 numbers in a row, then it is most likely a bot anyhow. But $regex is good too. smile
Posted By: FiberOPtics Re: script request! - 15/04/05 01:57 PM
I have a couple of tips for you.

  1. Use the slashes / / to encapsulate the regular expression.

    You might wonder why? Well one of these days you'll be scratching your head when $regex(a,moo) gives 1. If you want to know why it matches, let me know.

  2. U can use the i modifier so that the pattern is case insensitive, so that you can shorten the initial [a-zA-Z] to simply [a-z] (or another variation of that). The expression would be something like /<pattern>/i
    Or if you want only a part of the pattern to be case insensitive you can use the modifiers like this:
    (?<modifiers>)

    Example: /foo(?i)bar(?-i)s/

    Both the foo and s are case sensitive, which means they will only match in that exact representation, so not on mOo etc. bar is however case insensitive, so matches BAR, bAR, etc.

    You can set and unset multiple in one assignment like: /foo(?iS)bar(Ux-iS) s+/
    I won't go into detail about all the meanings of the different modifiers.

  3. You could replace [0-9] with \d, however this is a personal preference, and some might prefer it for easier understanding.

  4. Finally you can use the quantifier {<N>[,N]} to specify how many times you want something to match.

    2 or more digits would be: \d{2,}

    Of course what you did, being \d\d+, or \d\d\d* etc. are just as good.

    In mIRC, commas are the delimiters in an identifier, so the possible comma used in {N,N} would screw up the regex, but we can work around that by putting the expression in brackets (whether that be capturing, uncapturing, lookaround, etc.), then mIRC treats it as part of the pattern, and not as an identifier delimiter.

    Example: /^moo(?:\d{2,5})$/

Note that those tips are not necessarily aimed at you, they might come in handy for anyone taking the first steps in regex.

Greets
Posted By: Hammer Re: script request! - 18/04/05 10:45 AM
In addition (for the purposes of the exact example under discussion in this thread), I would also use $fulladdress (or $address) as the first parameter for $regex(), and switching ! (start-of-identd) for ^ (start-of-string) and @ (end-of-identd) for $ (end-of-string). They are functionally the same here, delimiting the string you wish to check. Alternately, since you are requiring the client to be unidentd'd in this example, you could start with the ~ as your start-of-match character since it cannot appear anywhere else in $fulladdress or $address.

on @*:JOIN:#: if ($regex($fulladdress, /~[a-z](?:\d{2,})@/i)) ban -k # $nick 2 Auto-ban: Spam bot.
Posted By: FreekOne Re: script request! - 19/05/05 02:22 PM
Quote:
on @*:JOIN:#: if ($regex($fulladdress, /~[a-z](?:\d{2,})@/i)) ban -k # $nick 2 Auto-ban: Spam bot.


Great script, works like a charm wink BUT what if the ident doesn't start with ~ ? (for example: it's just x1234 instead of ~x1234)
Posted By: SladeKraven Re: script request! - 19/05/05 03:11 PM
I don't know anything about $regex() but I think this will do what you want, if not there's a few on here that know $regex(). smile

Code:
on @*:JOIN:#: {
  if ($regex($fulladdress, /~[a-z](?:\d{2,})@/i) || $regex($fulladdress, /[a-z](?:\d{2,})@/i)) {
    ban -k # $nick 2 Auto-ban: Spam bot. 
  }
}
Posted By: FreekOne Re: script request! - 19/05/05 08:11 PM
Well, it now works with idents that don't start with ~ but it also reacts to idents like xxxx123 (multiple letters before the numbers instead of just one letter). Any idea ?

Thanks !
© mIRC Discussion Forums