egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

strip duplicate characters in nick and match against badnick
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Nov 02, 2020 3:39 pm    Post subject: strip duplicate characters in nick and match against badnick Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Nov 03, 2020 4:55 am    Post subject: Reply with quote

It's a quite simple regsub:
Code:
regsub -all -- {(.)\1+} $nick {\1} nick

_________________
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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Tue Nov 03, 2020 7:14 am    Post subject: Reply with quote

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
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Tue Nov 03, 2020 7:35 am    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Nov 03, 2020 7:43 am    Post subject: Reply with quote

Sorry, I just gave the code to remove the duplicate letters, didn't look where $nick was used Smile
_________________
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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Tue Nov 03, 2020 8:04 am    Post subject: Reply with quote

no problem seems to work now thanx again CrazyCat
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Nov 04, 2020 2:49 am    Post subject: Reply with quote

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
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Wed Nov 04, 2020 8:07 am    Post subject: Reply with quote

thanx Caesar the first part i understood but the second i didnt also since there is no variable called numbers
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Nov 04, 2020 9:15 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Wed Nov 04, 2020 10:15 am    Post subject: Reply with quote

thanx crazycat i wanted to integrate that into code but im not sure how to tbh
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Nov 04, 2020 10:34 am    Post subject: Reply with quote

Show your actual code, because it won't really help you if I modify the older Smile
_________________
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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Wed Nov 04, 2020 11:11 am    Post subject: Reply with quote

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
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Nov 04, 2020 12:24 pm    Post subject: Reply with quote

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. Embarassed
_________________
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
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Wed Nov 04, 2020 1:01 pm    Post subject: Reply with quote

excellent tnx Caesar and CrazyCat
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Nov 09, 2020 11:14 am    Post subject: Reply with quote

i had one last request if the check could be done with regexp to check like:

Quote:
b[ae]dw[0o]rd



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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber