| View previous topic :: View next topic |
| Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon Nov 02, 2020 3:39 pm Post subject: strip duplicate characters in nick and match against badnick |
|
|
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: |
#--------------------------------------------------------------------------------------------------------------------#
# 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
|
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Tue Nov 03, 2020 7:14 am Post subject: |
|
|
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: |
#--------------------------------------------------------------------------------------------------------------------#
# 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
|
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Tue Nov 03, 2020 7:35 am Post subject: |
|
|
that seems to work now
thanx CrazyCat
Last edited by simo on Tue Nov 03, 2020 8:03 am; edited 1 time in total |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Tue Nov 03, 2020 8:04 am Post subject: |
|
|
| no problem seems to work now thanx again CrazyCat |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Nov 04, 2020 2:49 am Post subject: |
|
|
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: |
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: |
if {[lsearch -nocase $bchan $chan] || ![llength $bchan]} {
|
We compare case in-sensitive and check the length of a list.
| Code: |
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: |
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. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Nov 04, 2020 8:07 am Post subject: |
|
|
| thanx Caesar the first part i understood but the second i didnt also since there is no variable called numbers |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Nov 04, 2020 9:15 am Post subject: |
|
|
| 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. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Nov 04, 2020 10:15 am Post subject: |
|
|
| thanx crazycat i wanted to integrate that into code but im not sure how to tbh |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Nov 04, 2020 11:11 am Post subject: |
|
|
| Code: |
#--------------------------------------------------------------------------------------------------------------------#
# 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
|
|
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Nov 04, 2020 12:24 pm Post subject: |
|
|
| Code: |
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.  _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Thu Nov 05, 2020 1:42 am; edited 1 time in total |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Wed Nov 04, 2020 1:01 pm Post subject: |
|
|
| excellent tnx Caesar and CrazyCat |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon Nov 09, 2020 11:14 am Post subject: |
|
|
i had one last request if the check could be done with regexp to check like:
if we use current code we have to use like:
| Quote: | 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 |
|
| Back to top |
|
 |
|