I'm trying to make a script that firstly warns the users who use ASCII chars in the channel and if they do it again they get banned... but when someone uses ASCII chars it gets banned and the bot also sends him notices at the same time.
You realize that ASCII characters include a-z, A-Z, 0-9, and all that right? heh
Aside from that, the reason you're probably having this problem is that the pubm bind is "stackable". Which means, it gets executed multiple times for the same input. So if a user types a line with more than one of your forbidden characters, the procedure will get called more than once, thus warning him and banning him.
Instead, you should have a single bind with *, and check for illegal chars within it.
stdragon was correct in regards to the script being called multiple times, however, there is a second reason for the notice and ban in one go, that requires only a single control character to be used in the text.
In your second "if" test, you see if the user ISNT there. If not, then add them and warn them.
Your third i"if" checks to see if they ARE added. If so, then ban them.
The way you use this is very correct, however, but your ordering isn't.
The first "validuser" returns 0, so add them. The second "validuser" returns 1, because you have just added them.
A qucik fix for this, is to switch the order in which these "if" statments are called.
if {![validuser usera]} {
#User isn't added, as noted
#So do this code
adduser usera
}
if {[validuser usera]} {
#User is added, we just added him above, so this gets called now
#SO we call ban code
}
ppslim, actually he had it correct the first time. The reason is that he has a 'return' statement after adding the user. So basically he's using the user record as a flag to see if the person has been warned already.
1. sheep sends a msg with control chars
2. bot checks if user exists
3: no - so bot adds user and sends notice, returns
4. sheep sends another msg with control chars
5. bot checks if user exists
6. yes - so bot bans and deletes user (resetting flag), returns
It's actually a very smart way of doing it, because using the user record automatically adds permanance (e.g. bot saves user records automatically, so on .restart the user still exists).
# add a user
proc my_adduser {mask} {
global my_users
set my_users([string tolower $mask]) ""
}
# return "" = not found
# else return the 1st mask which matched
proc my_searchuser {uhost} {
global my_users
set uhost [string tolower $uhost]
foreach mask $my_users {
if {[string match $mask $uhost]} {
return $mask
}
}
return
}
# remove a user
proc my_deluser {mask} {
global my_users
catch {unset my_users($mask)}
}
set validuser [my_searchuser $nick!$uhost]
if {$validuser == ""} {
#User isn't added, as noted
#So do this code
my_adduser [maskhost $uhost]
}
if {$validuser != ""} {
#User is added, we just added him above, so this gets called now
#SO we call ban code
}
# remove the user:
my_deluser $validuser
This thing with the userlist is not a good ideea because in case someone uses a colour or something today, it's added to the list and after 24 hours when it uses it again it's directly banned so he used only one time the colours per that day.
Also, instead of adding a user, removing it and so on, just add it's host to a certain user and see if it's mask is there either by checking the masks or by matching his handle with a certain flag of that user.
Once the game is over, the king and the pawn go back in the same box.