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!
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You mean have the regexp pattern in a separate variable?

Code: Select all

regexp -options { pattern } text -> match
Just remove the pattern you got right now and put a variable instead. Shouldn't be hard to figure out.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

this is what i came up with if its proper

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] {
    regexp -options { i } text -> match
   if {[string match -nocase *$match* $nick2]  && ![string match -nocase *guest* $nick2]} {
        set badpart $match
   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 »

As a general rule of thumb generally it's a good idea to:
1. have variables inside an array, so you won't end up with stuff like this:

Code: Select all

global bnick bchan kickreason temp
instead of having a cleaner:

Code: Select all

global something
where something for example holds the following variables:

Code: Select all

set something(one) "1"
set something(two) "2"
# and so on.. you get the idea
2. use of the namespace, that's basically a collection of commands and variables and if given a unique name chances to end up at some point with two functions or variables having the same name are ZERO. will save you of a lot of hassle trying to figure out why your code isnt working properly

Next we got this:

Code: Select all

if {[lsearch -nocase $bchan $chan] || ![llength $bchan]} { 
# execute stuff
}
this is, for me at least, a bad approach on programming as it makes it harder for you to track if all the { have an}, if you got all the stuff you wanted to be executed in the right place and whatnot. At the top of the code before everything else is executed should have the sattements that validate the access to the next lines so it not only easier to follow but also to debug. The TCL interpreter doesn't care how you make the code as long as it's valid. Now let's intepret the statement and see what it dose:

Code: Select all

IF we can find a case in-sensitive match of the channel name in that list OR the list has at least one element THEN { execute this code }
and let's see what happens:

Code: Select all

% set chan "foo"
foo
% set channels "something else in here"
something else in here
% lsearch -nocase $channels $chan
-1
% llength $channels
4
% if {[lsearch -nocase $channels $chan] || ![llength $channels]} { puts "I'm in" }
I'm in
As you can notice the channel isn't in the list, list has 4 elements and the code is executed nevertheless. The logic of the line is a bit flawed. At this point would like to point out that would be a lot easier to use the built-in mechanics we got and not hard-code variables that at some point we would like to change, so instead of this create a special flag like setudef flag myFlag and combined with channel get $chan myFlag for example you know if given channel should be allowed to execute the code.

Code: Select all

foreach i [string tolower $bnick] {
I mentioned the string tolower in one of my previous posts, so no point in talking about it again, just remove it as your 'string match ' is done in a case in-sensitive manner so it's useless.

Code: Select all

if {!$temp} { return } {
         putquick "MODE $chan  +b  *$badpart*!*@*"
         putquick "KICK $chan $nick :$kickreason"
 } 
This is a gem, cos you are basically scratching your left ear with your right hand OVER your head:

Code: Select all

if $temp equals 0 we return ELSE execute this code
Why bother with an IF-THEN-ELSE (it's IF statement THEN return ELSE { execute this code } basically) when you can just IF statement THEN { execute this code } directly. I see some of the stuff I previously mentioned didn't make the cut as well, so in the spirit of what CrazyCat suggested, don't expect me to spoon feed you the answers on this one. I mean, I could do just that but wouldn't help you in the long run.

As always, don't find my answers as patronizing you or anything like that. If you look at the history of my early posting you will see I got a lot of stupid questions and mistakes, but people like ppslim, user, stdragon, egghead to name a few had the patience and pushed me in the right direction without spoon feeding me every time. Just take this as a loving push in the right direction as well. :)
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

this is confusing thats why i dont use it
set something(one) "1"
set something(two) "2"
# and so on.. you get the idea
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks caesar i cant figure it out for the moment but i will have a go at it perhaps another time for the moment ill use old code i do apreciate the efforts tho will use that when i have some more clear mind to look at this

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

Post by CrazyCat »

Short remarks (or personnal preference)
caesar wrote:As a general rule of thumb generally it's a good idea to:
1. have variables inside an array, so you won't end up with stuff like this:

Code: Select all

global bnick bchan kickreason temp
instead of having a cleaner:

Code: Select all

global something
where something for example holds the following variables:

Code: Select all

set something(one) "1"
set something(two) "2"
# and so on.. you get the idea
I agree with caesar because of a pratical reason: if you use several scripts, you'll probably have variables with the same name but with a different usage.
Having myscript(nicklist) and myscipt(delay) is better than having nicklist and delay which could be use somewhere else.

Personnaly, I prefer use variables but call them using their namespace rather than use global. And having namespace for scripts, so when I use a variable, I know exactly where it comes from. $::username is not $::myscript::username.

A long time before, I was used to have global in my scripts, because I didn't know namespaces. But now, I think it's quite evil to use global :)
Post Reply