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.

Bind a formatted string

Help for those learning Tcl or writing their own scripts.
Post Reply
w
wier
Voice
Posts: 2
Joined: Sat Oct 16, 2010 10:55 am

Bind a formatted string

Post by wier »

Hi,

i am trying to build a bind for a formatted string..
If User writes the following text into the channel, i would like to trigger a proc

<User> This is a test

i thought this would be it, but it doesn't work

Code: Select all

bind pubm - "\0034\026This is a test" pub_test

proc pub_test {nick mask hand channel args} {
    puthelp "PRIVMSG $channel: Test"
}
and to check, if "User" wrote the text, i can check it with

Code: Select all

if($nick ne "User") {...}
but.. as i said.. it doesn't work like this..
thanks for help :)
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Try

Code: Select all

bind pubm - "\00304\026This is a test" pub_test
and read this http://forum.egghelp.org/viewtopic.php?p=80884#80884
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: Bind a formatted string

Post by speechles »

wier wrote:Hi,

i am trying to build a bind for a formatted string..
If User writes the following text into the channel, i would like to trigger a proc

<User> This is a test

i thought this would be it, but it doesn't work

Code: Select all

bind pubm - "\0034\026This is a test" pub_test

proc pub_test {nick mask hand channel args} {
    puthelp "PRIVMSG $channel: Test"
}
Because you've chosen to bind on a pubm rather than pub.

Code: Select all

bind pubm - "\0034\026This is a test" pub_test
To make this work, it would need to look like this...

Code: Select all

bind pubm - "\0034\026This is a test*" pub_test
Now it's a mask, notice the wildcard * at the end? To make it work as a regular pub bind, and not one masked, use:

Code: Select all

bind pub - "\0034\026This is a test" pub_test
Also...about "args"...

Code: Select all

proc pub_test {nick mask hand channel args} {
Here it serves no purpose. Your bind will pass a single-argument as the text the user entered. You've chosen to capture this into "args" which will allow multiple arguments. Therefore, your captured text will be conveyed instead as a list, not as a string. So rather than craft ways to convert this list back into a string for processing. Craft your procedure header correctly, like this:

Code: Select all

proc pub_test {nick mask hand channel arg} {
--or--
proc pub_test {nick mask hand channel text} {
--or--
proc pub_test {nick mask hand channel literally_anything_but_args} {
w
wier
Voice
Posts: 2
Joined: Sat Oct 16, 2010 10:55 am

Post by wier »

First of all thanks for your help.
Unfortunately it didn't work like wanted it to.. ;-)
Thats why, I tried to change the way I am handling the problem.

The idea is, to allow a bot-command only between two certain commands of another bot..

Code: Select all

bind pubm - * test
proc test {nick host hand chan text} {
	global flag
	if {[string equal -nocase "!test" $text]} {
		if {[$flag==0]} {
			puthelp "NOTICE $nick :This a test" }
		}
	}
	elseif {[string equal -nocase "*startpoint*" $text]} {
		set flag 1
	}
	elseif {[string equal -nocase "*endpoint*" $text]} {
		set flag 0
	}
} 
but unfortunatly the if/elseif equations are never reached.
So my first question is, where the mistake is in my code, and secondly I would like to know, wheather a coloured text would trigger the proc.

Thanks,
wier
t
thommey
Halfop
Posts: 76
Joined: Tue Apr 01, 2008 2:59 pm

Post by thommey »

wier wrote: So my first question is, where the mistake is in my code
Almost everything starting from the second if is syntactically broken, it doesn't follow Tcl syntax. Tcl syntax: http://wiki.tcl.tk/dodekalogue . To see a more fine grained complaint about all your syntax errors (oh, and of course why your braces mismatch - it's easy to see with correct indention + the [] around $flag == 0 is wrong), see: http://paste.tclhelp.net/?id=83i . You should also see errors in your partyline - you absolutely need to see them there to test your Tcl scripts.
wier wrote: and secondly I would like to know, wheather a coloured text would trigger the proc.
Yes. However, bind pubm does not match against the text only tho, reread the documentation (that's why all pubm binds not being '*' mentioned in this thread never match), http://www.eggheads.org/support/egghtml ... binda_pubm and http://www.eggheads.org/support/egghtml ... matchchars (the % wildcard is helpful).
Post Reply