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.

string match? and -nocase ??

Old posts that have not been replied to for several years.
u
up^to^you

string match? and -nocase ??

Post by up^to^you »

if {[string match "*foo*" [string tolower $args]]} {

This code only detect if someone type 'foot', and bot will consider it as match as 'foo', but
if someone type 'not foo' in channel, the bot will ignore it as the match word. How to prevent this not happen? How to make bot consider 'not foo' is also match as 'foo'?

and also what is the different if I use:

if {[string match -nocase "*foo*" [string tolower $args]]} {

with:

if {[string match "*foo*" [string tolower $args]]} {

is there any different on them?


and is -nocase $var meaning is the same with [string tolower $var] ??
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

This is 99% likely due to your use of the $args variable.

Tcl has a special meanign for the $args variable. It can be used to make a procedure accept variable length arguments.

An example of this is the built in "list" command.

You can send as many or as little items to this command, but it doesn't complain.

This variable works, by taking each argument sent to the procedure, and making it a item in a list. Thus, $args becomes a list.

SImpoly changing it for $arg, and arg in the p[rocedure definition will most likely solve your problem.
u
up^to^you

Post by up^to^you »

so..the problem will solved if I use $args, but I'm afraid I cant use $args in this script coz the author set so :(

## checkit!
proc checkit {nick uhost hand chan args} {

set checked [string tolower $args]
foreach z [array names valid] {
if {$texttocheck == $checked} {
set okay 1
}

Because I want to use match and not == (equal), I use this :

if {[string match "*[string tolower $z]*" $checked]} {
set okay 1
}

but that code consider the 'not foo' is not match with 'foo'. That code only detect 'foot' is same with 'foo'
well..this script looks more complicated for me....I there any another way except puts $args to make my bot detect 'not foo' as 'foo'? coz seems i cant use $args here.

thx
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

First, regardless of what the auther says, usign $args is incorect.

This needs to be changed first off, the reasons noted in my previous post.

Does nobody take us seriously around here, are we doing this to fall on deaf ears.

Just because an auther creates a script like such, do people asume that is the most correct way of doing it, even if the thing is so full of holes or issues, there is no toher way of doing it.

If the auther claims so much, that $args must be used, then why are you using "string match", surly the auther did not indent for this usage.

Maybe you could explain your problem better.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Can we have an example of this? I have tryed on my way to do such an thing but I haven't succided at all. I want to do a match if in a line is the my channel to do nothing, and if it's other channel name (with an # in front) and/or other channel name (with an # in front) and my channel. I have tryed some codes but still nothing. Give me an clue please, cos I'm stuck here. Thanks in advance..
Once the game is over, the king and the pawn go back in the same box.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I have looked on the previous posts and found something, but I haven't understood a thing from there :) .. Take a look here and maybe you will understand something..
Once the game is over, the king and the pawn go back in the same box.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

if {[string match "*#*" $text] && ![string match "*$chan*" $text]} {
this is a simple way to check if # is in the text and to check that it's not current channel beeing mentioned....
this is when dealing with $text

Code: Select all

if {[lsearch $args "*#*"] != -1 && [lsearch $args "*$chan*"] == -1} {
^^use this one when u use $args
*note: this will never trigger when $chan is beeing said, even if some other chan is beeing mentioned in the same line...
Elen sila lúmenn' omentielvo
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

bind pubm - * adv:match

proc adv:match {nick host hand chan arg} {
if {[string match "*#*" $arg] && ![string match "*$chan*" $arg]} {
putserv "PRIVMSG $chan :do nothing"
return 0 }
putserv "PRIVMSG $chan :kick/ban"
return 0 }

This dose the opus of the thing should do:
[21:17] <@caesar> #channel
[21:17] <@bob> kick/ban
[21:17] <@caesar> #dhsdt
[21:17] <@bob> do nothing

If I change with: if {[string match "*#*" $arg] && [string match "*$chan*" $arg]} {

Reacts as normal should do, results:
[21:19] <@caesar> #dhsdt
[21:19] <@bob> kick/ban
[21:19] <@caesar> #channel
[21:19] <@bob> do nothing

Then, with the if {[lsearch $arg "*#*"] != -1 && [lsearch $arg "*$chan*"] == -1} { line:

[21:21] <@caesar> #dhtr
[21:21] <@bob> do nothing
[21:21] <@caesar> #channel
[21:21] <@bob> kick/ban

As you can see, I'm in the same place I have started.. :(
Once the game is over, the king and the pawn go back in the same box.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

caesar wrote:bind pubm - * adv:match

proc adv:match {nick host hand chan arg} {
if {[string match "*#*" $arg] && ![string match "*$chan*" $arg]} {
putserv "PRIVMSG $chan :do nothing"
return 0 }
putserv "PRIVMSG $chan :kick/ban"
return 0 }

This dose the opus of the thing should do:
[21:17] <@caesar> #channel
[21:17] <@bob> kick/ban
[21:17] <@caesar> #dhsdt
[21:17] <@bob> do nothing
that's cause u have the wrong output ;)
what that if command does is to check if # is used in $arg.. if it is it checks if the #... is the same as $chan.. if both match it will do nothing.. not kick/ban as u have set it to ;)
Elen sila lúmenn' omentielvo
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You meen to use: bind PUBM - {* *#*} adv:match and one of the lines you sugested? I shall test this..
Once the game is over, the king and the pawn go back in the same box.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code 1:
bind pubm - {* *#*} adv:match

proc adv:match {nick host hand chan arg} {
if {[string match "*#*" $arg] && ![string match "*$chan*" $arg]} {
putserv "PRIVMSG $chan :do nothing"
return 0 }
putserv "PRIVMSG $chan :kick/ban"
return 0 }

Results:
[17:43] <@caesar> #channel
[17:43] <@bob> kick/ban
[17:43] <@caesar> #dsthdt
[17:43] <@bob> do nothing

Code 2:
bind pubm - {* *#*} adv:match

proc adv:match {nick host hand chan arg} {
if {[lsearch $arg "*#*"] != -1 && [lsearch $arg "*$chan*"] == -1} {
putserv "PRIVMSG $chan :do nothing"
return 0 }
putserv "PRIVMSG $chan :kick/ban"
return 0 }

Results:
[17:44] <@m|sk> #dsthdt
[17:44] <@bob> do nothing
[17:44] <@m|sk> #channel
[17:44] <@bob> kick/ban

What you sugest next? I have tryed some combiations but still nothing..
Once the game is over, the king and the pawn go back in the same box.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Code: Select all

bind pubm - {* *#*} adv:match

proc adv:match {nick host hand chan arg} { 
if {[string match "*$chan*" $arg]} { 
putserv "PRIVMSG $chan :do nothing" 
return 0 } 
putserv "PRIVMSG $chan :kick/ban" 
return 0 } 
(ugly formatting preserved where possible :p)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Using the code you told me, got the folowing results:

[19:02] <@caesar> #channel
[19:02] <@bob> do nothing
[19:02] <@caesar> #dsghsdt
[19:02] <@bob> kick/ban

Ok, until here is ok.. then:

[19:03] <@caesar> #dhsd #channel
[19:03] <@bob> do nothing

and boom! .. wrong.. This covers only the first part, the other part is exploatable as you can see. Well?
Once the game is over, the king and the pawn go back in the same box.
P
Photon
Op
Posts: 170
Joined: Wed Aug 28, 2002 8:00 am
Location: Liverpool, England

Post by Photon »

It would be safer to use an if/else then only the first one it finds will be executed.

This removes the exploit... sort of.

However, you will have to order it with the one that needs to take precidence first.

Otherwise you are going to have to use string first to find out which one comes first in the string....
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Caesar,

Don't you remember that other thread where we were all talking about the best way to do this? We already figured out several ways to do it, and even ranked them according to accuracy and performance.

You even posted in the thread. And then we told you which code to use.

If you want to remove this "exploit" then use the code we have already posted.

Anyway, your question has nothing to do with the original thread by up^to^you lol. This is silly.
Locked