This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

detecting this pattern with regexp ?

Old posts that have not been replied to for several years.
Locked
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

detecting this pattern with regexp ?

Post by z_one »

Wna21E251 (Wnj56K492@clt74-100-186.carolina.rr.com) joined #MyChannel.
Mqa38W416 (~Ihq93J246@host116-142.pool80180.interbusiness.it) joined #MyChannel.
Pqm42J441 (Yjv89B611@80.192.158.40) joined #MyChannel.
Gas77K949 (cthkfqb@217.164.49.17) left #MyChannel.
Wmd78U721 (~Pgp6W653@12-254-126-139.client.attbi.com) left #MyChannel.
Pqm42J441 (Yjv89B611@80.192.158.40) left #MyChannel.

What's the best RegExp to have an exact match of such similar nicks (they all have the same composition).

Thanks.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

regexp {^(\w){3}(\d){2}\w(\d){3}$} $nick
dunno if it's the best one but it should work
Elen sila lúmenn' omentielvo
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

may I ask what does a regexp do ?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Regexp is a complex matching system.

Where normal string based matches (glob style) you can detect for certain characters. It doesn't allow for exraction, only the evidance of existance.

Regexp allow to to prove they are there, extract, and can even do this matching, based on if certain part exist or not.

The quickest example I can give of this, is the stripping code used by No!Spam.

Colour codes are made up of a control character, the forground colour, a background colour and comma.

Not all of these elements are required to produce a colour, and text may or may not contain them at all.

A regular expression can and does remove the colour code, even if certain parts of it are missing.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

oh ok, well the no!spam strip code:

Code: Select all

set text [ctrl:filter $text]

proc ctrl:filter {str} { 
  regsub -all -- {\003[0-9]{0,2}(,[0-9]{0,2})?|\017|\037|\002|\026|\006|\007} $str "" str 
  return $str 
}
so the regexp u posted above should be like
set nick [comp:nick $nick]

and then add a proc like:
proc comp:nick {com} {
regexp {^(\w){3}(\d){2}\w(\d){3}$} $nick
}

or how ?
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

the regexp I gave will just return 1 on match, or 0 if not.. so you could use it like this

Code: Select all

if {[regexp {^(\w){3}(\d){2}\w(\d){3}$} $nick]} {
  blablabla ban or whatever
}
Elen sila lúmenn' omentielvo
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

ok, i understoud.

thanx :)
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

hi,
i get flooded with bots that use those types of nicks too.

how can i use that regep code?
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

well creat a bind for join.
example: bind join - * proc-name
then from tcl-commands.doc in your eggdrop's /doc directory.
creat the proc for the join bind and add the like given by Papillon:
if {[regexp {^(\w){3}(\d){2}\w(\d){3}$} $nick]} {
blablabla ban or whatever
}
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

would this kick the 3rd bot nick, or am i missing something?

Code: Select all


# Channels you want to Check for Bot Nicks on. 
# Multiple channels seperated by spaces.
set my.chans "#TCLhelp #TCLlovers"

# Set the Max Number of Bot Nicks Allowed before a kick
set bot.limit 3

# During the Number of Seconds
set bot.sec 7

bind join - * bot:check

proc bot:check {nick uhost handle chan} {
  global botnick my.chans bot.limit bot.sec bot.ctr
  set chan [string tolower $chan]
  if {![botisop $chan]} {
    return 
  }
  if {![info exists bot.ctr($chan)]} { 
    return 0
  }
  if {[regexp {^(\w){3}(\d){2}\w(\d){3}$} $nick]} { 
    incr bot.ctr($chan) 1
    utimer $bot.sec [list bot:dec $chan]
    if {$bot.ctr($chan) >= $bot.limit} {
      ban:bots $nick $chan $type
    } else {
      return 0
    }
  }
}

proc bot:dec {chan} {
  global bot.ctr
  incr bot.ctr($chan) -1
}

foreach chan [strlwr $my.chans] { 
  if {![info exists bot.ctr([strlwr $chan])]} { 
    set bot.ctr([strlwr $chan]) 0 
  }
}

I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

wouldn't this be a more simple script ?

Code: Select all

##channels u want the script to apply on
set my.chans "#TCLhelp #TCLlovers"
##set ban reason
set brsn "your reason here"

###code###

bind join - * check:nick

proc check:nick {nick uhost hand chan} {
foreach chan [split $::my.chans] {
if {[regexp {^(\w){3}(\d){2}\w(\d){3}$} $nick] && [botisop $chan]} {
  set mask "*!*@[lindex [split $uhost @] 1]"
  putquick "KICK $chan $nick :$::brsn"
  putquick "MODE $chan +b $mask"
  }
 }
}
also yes, I think your script should work fine.
Locked