| View previous topic :: View next topic |
| Author |
Message |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri Nov 13, 2020 1:55 am Post subject: |
|
|
You mean have the regexp pattern in a separate variable?
| Code: |
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. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Fri Nov 13, 2020 7:34 am Post subject: |
|
|
this is what i came up with if its proper
| 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] {
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
|
|
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri Nov 13, 2020 10:33 am Post subject: |
|
|
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: |
global bnick bchan kickreason temp
|
instead of having a cleaner:
where something for example holds the following variables:
| Code: |
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: |
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: |
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: |
% 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: |
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: |
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: |
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. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sat Nov 14, 2020 9:47 am Post subject: |
|
|
this is confusing thats why i dont use it
| Quote: | set something(one) "1"
set something(two) "2"
# and so on.. you get the idea |
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sat Nov 14, 2020 9:50 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Sat Nov 14, 2020 10:07 am Post subject: |
|
|
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: |
global bnick bchan kickreason temp
|
instead of having a cleaner:
where something for example holds the following variables:
| Code: |
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  _________________ 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 |
|
 |
|
|
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
|
|