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.

strip duplicate characters in nick and match against badnick

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

strip duplicate characters in nick and match against badnick

Post by simo »

ive been using this badnick tcl by RANA USMAN

it detects single badnicks i was wondering if this could be modified to detect
nicks like ssooomeeeenick bbbaaddddniccckk to strip any duplicate characters and match against bad nicks in the variable and all this with case insensitive
to prevent evades

thanx in advance.

Code: Select all


#--------------------------------------------------------------------------------------------------------------------#
#                                               BAD NICK SCRIPT BY RANA USMAN                                        #
#--------------------------------------------------------------------------------------------------------------------#

#Author : RANA USMAN
#Email : coolguy_rusman@yahoo.com
#URL : www.ranausman.tk
#Version : 1.2
#Catch me on UNDERNET @ #VASTEYE my nick is ^Rana^Usman
###################
# Version History #
###################
#The version before was not supporting Wildcards like ** ?? etc etc
#So now in this version you can use wild cards too

###########################
#- CONFIGURATION SECTION -#
###########################

########################################################################################
#- Enter the Bad nicks Below on which you want your bot to BAN  (Wild Cards Supported)-#
########################################################################################
set bnick {
    "somenick"
    "badnick"
}

#########################################################################################################
##                SET The channel on which you want this script to work                                ##
## Channels Separted by space...and if you want this script to work on all channels leave it as ""     ##
#########################################################################################################

set bchan ""

################
#- Set Reason -#
################

set kickreason "4Bad Nick Detected"


#--------------------------------------------------------------------------------------------------------------------#
#   SCRIPT STARTS FROM HERE...MAKE IT BETTER WITH YOUR SKILLS IF YOU CAN.I DONT RESTRICT YOU TO NOT TO TOUCH CODE!   #
#--------------------------------------------------------------------------------------------------------------------#


bind join - * join:RanaUsman
bind nick - * nick:tvrsh

proc nick:tvrsh {nick uhost hand chan newnick} {
    join:RanaUsman $newnick $uhost $hand $chan
}

proc join:RanaUsman {nick uhost hand chan} {
global bnick bchan kickreason temp
if {(([lsearch -exact [string tolower $bchan] [string tolower $chan]] != -1)  || ($bchan == ""))} {
  set temp 0
	foreach i [string tolower $bnick] {
if {[string match *$i* [string tolower $nick]] && ![string match -nocase *guest* $nick]} {
	# if {[string match *$i* [string tolower $nick]]} { }
        set badpart $i
	set temp 1
 	}
 	}
}
	if {!$temp} { return } {
            putquick "MODE $chan  +b  *$badpart*!*@*"
            putquick "KICK $chan $nick :$kickreason"
 } 
}
putlog "=-\002 LOADED BAD NICK BY RANA USMAN (www.ranausman.tk)\002 -="

#Author : RANA USMAN  

User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

It's a quite simple regsub:

Code: Select all

regsub -all -- {(.)\1+} $nick {\1} nick
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanx crazycat i tried it and it worked for the ban part but the kick part doesnt seem to work

this is what i have so far:

Code: Select all

#--------------------------------------------------------------------------------------------------------------------#
#                                               BAD NICK SCRIPT BY RANA USMAN                                        #
#--------------------------------------------------------------------------------------------------------------------#

#Author : RANA USMAN
#Email : coolguy_rusman@yahoo.com
#URL : www.ranausman.tk
#Version : 1.2
#Catch me on UNDERNET @ #VASTEYE my nick is ^Rana^Usman
###################
# Version History #
###################
#The version before was not supporting Wildcards like ** ?? etc etc
#So now in this version you can use wild cards too

###########################
#- CONFIGURATION SECTION -#
###########################

########################################################################################
#- Enter the Bad nicks Below on which you want your bot to BAN  (Wild Cards Supported)-#
########################################################################################
set bnick {
    "somenick"
    "badnick"
}

#########################################################################################################
##                SET The channel on which you want this script to work                                ##
## Channels Separted by space...and if you want this script to work on all channels leave it as ""     ##
#########################################################################################################

set bchan ""

################
#- Set Reason -#
################

set kickreason "4Bad Nick Detected"


#--------------------------------------------------------------------------------------------------------------------#
#   SCRIPT STARTS FROM HERE...MAKE IT BETTER WITH YOUR SKILLS IF YOU CAN.I DONT RESTRICT YOU TO NOT TO TOUCH CODE!   #
#--------------------------------------------------------------------------------------------------------------------#


bind join - * join:RanaUsman
bind nick - * nick:tvrsh

proc nick:tvrsh {nick uhost hand chan newnick} {
    join:RanaUsman $newnick $uhost $hand $chan
}

proc join:RanaUsman {nick uhost hand chan} {
global bnick bchan kickreason temp
regsub -all -- {(.)\1+} $nick {\1} nick
if {(([lsearch -exact [string tolower $bchan] [string tolower $chan]] != -1)  || ($bchan == ""))} {
  set temp 0
   foreach i [string tolower $bnick] {
if {[string match *$i* [string tolower $nick]] && ![string match -nocase *guest* $nick]} {
   # if {[string match *$i* [string tolower $nick]]} { }
        set badpart $i
   set temp 1
    }
    }
}
   if {!$temp} { return } {
            putquick "MODE $chan  +b  *$badpart*!*@*"
            putquick "KICK $chan $nick :$kickreason"
 }
}
putlog "=-\002 LOADED BAD NICK BY RANA USMAN (www.ranausman.tk)\002 -="

#Author : RANA USMAN 

s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

that seems to work now

thanx CrazyCat
Last edited by simo on Tue Nov 03, 2020 8:03 am, edited 1 time in total.
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Sorry, I just gave the code to remove the duplicate letters, didn't look where $nick was used :)
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

no problem seems to work now thanx again CrazyCat
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I take it this piece of code is quite old and was aimed to work with previous versions of TCL library, but since TCL is at 8.6 (at least in my Debian server) should adapt every piece of code you are using to take advantage of what it has to offer. Anyway..

Code: Select all

if {(([lsearch -exact [string tolower $bchan] [string tolower $chan]] != -1)  || ($bchan == ""))} {
Using the -exact and turning the $bchan and $chan to lower case has the same effect as using -nocase directly without needing to turn everything to lower case. The program will do it for you.

Code: Select all

if {[lsearch -nocase $bchan $chan] || ![llength $bchan]} {
We compare case in-sensitive and check the length of a list.

Code: Select all

set temp 0
foreach i [string tolower $bnick] {
	if {[string match *$i* [string tolower $nick]] && ![string match -nocase *guest* $nick]} {
	# if {[string match *$i* [string tolower $nick]]} { }
	set badpart $i
	set temp 1
	}
}
Here we got 3 things:

1. Since your goal is to see if there's a match should use the break statement to immediately terminate it and continue at the next line after the loop.

Code: Select all

set match 0
foreach no $numbers {
	if {$no == 3} {
		incr match
		break
	}
}
if {$match} {
	# do whatevever
}
2. See #1 but applied to string match.

3. As a general rule of thumb is a good idea to take outside a loop any function or if you do something to a variable that doesn't change in the loop, i mean the [string tolower $nick] that is in the loop and it doesn't change from one iteration to the other.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanx Caesar the first part i understood but the second i didnt also since there is no variable called numbers
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

simo wrote:thanx Caesar the first part i understood but the second i didnt also since there is no variable called numbers
caesar gave you an example on how to exit from the loop when you have a match, because it's useless to stay in it.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanx crazycat i wanted to integrate that into code but im not sure how to tbh
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Show your actual code, because it won't really help you if I modify the older :)
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Code: Select all

#--------------------------------------------------------------------------------------------------------------------#
#                                               BAD NICK SCRIPT BY RANA USMAN                                        #
#--------------------------------------------------------------------------------------------------------------------#

#Author : RANA USMAN
#Email : coolguy_rusman@yahoo.com
#URL : www.ranausman.tk
#Version : 1.2
#Catch me on UNDERNET @ #VASTEYE my nick is ^Rana^Usman
###################
# Version History #
###################
#The version before was not supporting Wildcards like ** ?? etc etc
#So now in this version you can use wild cards too

###########################
#- CONFIGURATION SECTION -#
###########################

########################################################################################
#- Enter the Bad nicks Below on which you want your bot to BAN  (Wild Cards Supported)-#
########################################################################################
set bnick {
    "somenick"
    "badnick"
}

#########################################################################################################
##                SET The channel on which you want this script to work                                ##
## Channels Separted by space...and if you want this script to work on all channels leave it as ""     ##
#########################################################################################################

set bchan ""

################
#- Set Reason -#
################

set kickreason "4Bad Nick Detected"


#--------------------------------------------------------------------------------------------------------------------#
#   SCRIPT STARTS FROM HERE...MAKE IT BETTER WITH YOUR SKILLS IF YOU CAN.I DONT RESTRICT YOU TO NOT TO TOUCH CODE!   #
#--------------------------------------------------------------------------------------------------------------------#


bind join - * join:RanaUsman
bind nick - * nick:tvrsh

proc nick:tvrsh {nick uhost hand chan newnick} {
    join:RanaUsman $newnick $uhost $hand $chan
}

proc join:RanaUsman {nick uhost hand chan} {
global bnick bchan kickreason temp
 regsub -all -- {(.)\1+} $nick {\1} nick2
if {[lsearch -nocase $bchan $chan] || ![llength $bchan]} {
  set temp 0
	foreach i [string tolower $bnick] {
if {[string match *$i* [string tolower $nick2]] && ![string match -nocase *guest* $nick2]} {
        set badpart $i
	set temp 1
 	}
 	}
}
	if {!$temp} { return } {
         putquick "MODE $chan  +b  *$badpart*!*@*"
         putquick "KICK $chan $nick :$kickreason"
 } 
}

putlog "=-\002 LOADED BAD NICK BY RANA USMAN (www.ranausman.tk)\002 -="

#Author : RANA USMAN
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

if {[string match -nocase *guest* $nick2]} return
set match 0
foreach i $bnick {
	if {[string match -nocase *$i* $nick]} {
		incr match
		set badpart $i
		break
	}
}

if {$match} {
	putquick "MODE $chan  +b  *$badpart*!*@*"
	putquick "KICK $chan $nick :$kickreason"
}
I missed to point out that there was no point on having the ![string match -nocase *guest* $nick2] check in a loop since it doesn't change at the 2nd, 3rd, or nth time you check it in the loop.

Haven't tested anything.

Edit: I did a copy/paste of your code and forgot to remove the string tolower from the foreach loop statement. :oops:
Last edited by caesar on Thu Nov 05, 2020 1:42 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

excellent tnx Caesar and CrazyCat
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i had one last request if the check could be done with regexp to check like:
b[ae]dw[0o]rd

if we use current code we have to use like:
badword
badw0rd
bedword
bedw0rd
instead of adding like 3 or 4 word with different paterns in the current code while regexp could do it with one word

thanx gents
Post Reply