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.

detect bad word hidden in long nicks

Help for those learning Tcl or writing their own scripts.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

detect bad word hidden in long nicks

Post by simo »

greetingz folks,


we have been using this tcl for a while it works fine but we wanted to be able to check for hidden badnick paterns hidden withing the nickname nicks like

badnick hidden in:
drgb-a}d-nzuickcqf
without having to use a lot of *

Code: Select all

set bnick {
     "badnick" 
	"someverylongbadword"
	"somewordthatsbad"
	"veryabussivelongword"
}


bind join - * join:badnick
bind nick - * nick:badnick

proc nick:badnick {nick uhost hand chan newnick} {
	join:badnick $newnick $uhost $hand $chan
}


proc join:badnick {nick uhost hand chan} {
	global bnick temp
	regsub -all -- {(.)\1+} $nick {\1} nick2x2

	set temp 0
	foreach i [string tolower $bnick] {
		if {[string match *$i* [string tolower $nick2x2]]} {
			set badpart $i
			set temp 1
		}
	}

	if {!$temp} { return } {
		pushmode $chan +b *$badpart*!*@*
	}
}
Last edited by simo on Sun Aug 28, 2022 1:53 am, edited 3 times in total.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

this is a way i know of in msl :

Code: Select all


if ($regex($gettok($nick,/( $+ $regsubex(badword|badword|badword|badword|badword|badword|badword|badword|badword|badword|badword|badword,//g,.*) $+ )/i)) {  do stuff }  

Last edited by simo on Sun Aug 28, 2022 1:45 am, edited 1 time in total.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

the regex basically checks for
*b*a*d*w*o*r*d*
in the nick

not sure if there is an equivalent of that in regex for eggdrop
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Is this not doable with regexp / regsub or a combination of the two?

Or another way perhaps
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

This is because *b*a*d*w*o*r*d* must be (to be used in regexp) :

Code: Select all

[^\s]*b[^\s]*a[^\s]*d[^\s]*w[^\s]*o[^\s]*r[^\s]*d[^\s]*
You can probably make a little proc which will transform all your badnicks into the good regexp

https://regex101.com/r/Ahp8OQ/1
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Thanks crazycat but when I said it checks for *b*a*d*n*i*c*k*
I didn't mean it checks for literally * in the nick but rather it searches between chars to find hidden badword hidden between characters to evade a ban
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Did you check my regex101.com link before answering ?
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Thanks crazycat Yes i checked it it has a lot of * i wanted to prevent that to add a zillion * for each bad word to check for
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

...
I said you that you can create a proc to transform your badnicks into regexp:

Code: Select all

proc bn2reg {text} {
   set sep {[^\s]*}
   set reg $sep
   for {set i 0} {$i<=[string length $text]} {incr i} {
      append reg [string index $text $i]$sep
   }
   return $reg
}
Test in tclsh:

Code: Select all

% proc bn2reg {text} {
   set sep {[^\s]*}
   set reg $sep
   for {set i 0} {$i<=[string length $text]} {incr i} {
      append reg [string index $text $i]$sep
   }
   return $reg
}
% bn2reg badnick
[^\s]*b[^\s]*a[^\s]*d[^\s]*n[^\s]*i[^\s]*c[^\s]*k[^\s]*
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks CrazyCat let me try that
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Sorry for the late reply, i wanted to try your last posted code crazycat but im not sure how to test it with the current badnick checker i have in use the one i posted above
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Just replace

Code: Select all

if {[string match *$i* [string tolower $nick2x2]]} 
with

Code: Select all

if {[regexp [bn2reg $i] [string tolower $nick2x2]]}
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks CrazyCat
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

after trial i get :
couldn't compile regular expression pattern: quantifier operand invalid

i used :

Code: Select all

      if {[regexp [bn2reg $i] [string tolower $nick2x2]]} {
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

ive changed to :


if {[regexp -- {[bn2reg $i]} [string tolower $nick2x2]]} {


but now it sets weird bans


17:13:25   Joins :   sfbdfadnicksdjh   [ident: Mibbit]     *!*@32.158.124.74
17:13:25 @Hawk Sets Mode on #test to: +b *veryabussivelongword*!*@*

i guess what we were looking is +b *b*a*d*n*i*c*k*!*@*

to set wild mask ban on the detected bad part of nick
Last edited by simo on Sat Sep 10, 2022 11:26 am, edited 3 times in total.
Post Reply