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.

Help with weird results

Old posts that have not been replied to for several years.
Locked
i
iguana
Voice
Posts: 6
Joined: Fri Dec 31, 2004 12:09 pm

Help with weird results

Post by iguana »

Reference a previous post I made, I got my script I wanted working fine (or as well as I could do). Remembering this is only my second bit of coding in TCL, anyone give me any pointers on the following code to reduce it in size or is it pretty my all that is required?

The other thing, it has some weird postings on IRC, for example, if the result has a "[" or and "]" in it, it prints a { } around the result. Any idea of how to get rid of that? It only does it when I use the

Code: Select all

lappend result [string trim $nick], 
line and doesnt do it if its put direct to the IRC channel with the

Code: Select all

puthelp "privmsg $channel :$nick ($times )"
command.

Here's the full code.

Code: Select all

package require http
bind pub - !guid guid

proc guid {n u h channel t} {
set length [string length $t]
if {$length == 0|| $t == "help"} {puthelp "notice $n :Enter a GUID of 8 characters or more to return a list of all aliases associated with it.. GUID Checker Beta 0.5" ; return 0 }
if {$length < 8} {puthelp "privmsg $channel :GUID's must be 8 characters or more." ; return 0 }
	set page [::http::geturl *site here*=$t]
	set content [split [::http::data $page] \n]
	regsub -all -nocase { } $content " " tosave
	regsub -all -nocase {<[^>*>]} $tosave {} tosave
	regsub -all -nocase {<td>|</td>|d>|td>} $tosave {} tosave
	regsub -all -nocase {>} $tosave ">" tosave
	regsub -all -nocase {<} $tosave "<" tosave
	::http::cleanup $content
set result ""
for {set x 127} {$x<500} {incr x 6} {
	set nick [lindex $tosave $x]
    	set times [lindex $tosave [expr {$x +1}]]
	if {$nick == ""} {break}
#	puthelp "privmsg $channel :$nick ($times )"
	lappend result [string trim $nick], 
}
if {$result == "html>,"} {	
puthelp "privmsg $channel :Nothing found, please check GUID and try again!"
} else {
	puthelp "privmsg $channel :Aliases used by GUID $t"
	puthelp "privmsg $channel :$result"
}
}
This is still in beta and needs more error checking putting in I know (hence some commented lines that were/are used for debugging).
i
iguana
Voice
Posts: 6
Joined: Fri Dec 31, 2004 12:09 pm

Post by iguana »

Ah no, it's ok, sorted it, removed

Code: Select all

lappend result [string trim $nick],
and replaced with

Code: Select all

append result $nick ", "
Seemed to sort it.

If you wonder why I posted back here I hate it when people say they fixed it and never told you how so you are always wondering how when you get the same problems! :)
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

[, ], {, }, ", ?, \, are all special tcl characters used for coding purposes. So you have to escape them using an "\" infront of them for it to work.

Code: Select all

#Will not work:
 putserv "PRIVMSG $chan :[Stats] for $chan is:"

#Will work:
 putserv "PRIVMSG $chan :\[Stats\] for $chan is:"
Take a look at:
http://www.peterre.com/characters.html

As for why you get the, extra parasynthesis { and } when you have special tcl characters in your output, new versions of eggdrop and tcl interpreter tries to escape those characters. For example in this script:

Code: Select all

bind pub m !topic topic

proc topic {nick host hand chan text} {
 putquick "TOPIC $chan :[lrange $text 0 end]"
}
If you use [ or ] in the topic, when the bot places the topic the [ and ] characters will be replaced by the same curly bracket parasynthesis so the script doesn't choke.

Also if a variable is a list then all the elements in the list are displayed within the curly brackets, especially when you use .tcl in partyline.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
i
iguana
Voice
Posts: 6
Joined: Fri Dec 31, 2004 12:09 pm

Post by iguana »

I managed to drop the { }'s by using append as opposed to lappend, I presume that append has been reworked in a new version of eggdrop/interpreter to discard the curly brackets.

I now understand the \'s as well now, they are escape so it means "treat the next character as a charater and not a TCL command/code string (if I understand you correctly! :) )
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

This might be because lappend would be using it in a list form (seperate elements) so hence you got the {, }'s. However append will use it in a normal string format so you shouldn't get the parasynthesis.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

awyeah wrote:As for why you get the, extra parasynthesis { and } when you have special tcl characters in your output, new versions of eggdrop and tcl interpreter tries to escape those characters. For example in this script:

Code: Select all

bind pub m !topic topic

proc topic {nick host hand chan text} {
 putquick "TOPIC $chan :[lrange $text 0 end]"
}
If you use [ or ] in the topic, when the bot places the topic the [ and ] characters will be replaced by the same curly bracket parasynthesis so the script doesn't choke.

Also if a variable is a list then all the elements in the list are displayed within the curly brackets, especially when you use .tcl in partyline.
Wrong.
Tcl/eggdrop does no such thing. lrange extracts a range of elements from a LIST and returns a new LIST (You used it on a string in your example, which is not a good idea. (try your example with a "{" in the string))
Tcl escapes the content of list elements (when needed) to be able to tell where each element ends.

I suggest you read and understand the page you posted a link to yourself before giving any more advice on this subject. (or making any more scripts for that matter)
Have you ever read "The Manual"?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

One of the clear facts here being that user, I used the same simple topic script and after the trigger I had some text, which had special characters such as those square brackets. When I said the bot to trigger it, it set the topic with {, }'s in return while I had supplied a set of [, ]'s to be set.

So, if I would have used string range, then all would have been well, ain't it? :roll:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Did you read my post?
Strings and lists are not the same but you can convert string to lists using 'split' and lists to strings using 'join'.
You should have 'split' the string before using 'lrange' on it and 'join'ed the result to get a string to output.
Have you ever read "The Manual"?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Yes, I did read your post. Or instead we can use string range, instead of lrange, then splitting and then joining back.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

awyeah wrote:Yes, I did read your post. Or instead we can use string range, instead of lrange, then splitting and then joining back.
They have nothing in common except for the fact that they extract ranges. What is your point? Do you understand what a list is?
Have you ever read "The Manual"?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Ofcourse I do. I am steewpid, but surely not that much too. My definition of a list would be "A combination of one or more elements placed together to from bunch of elements; list". Like for example I make a list of my groceries, weekly which are finished and need to be bought from the supermarket. And each grocery item from that list would represent a seperate element in the list.

A list would have seperate elements, like for examples of lists:
set names { {name1} {name2} {name3} }
set names { "name1" "name2" "name3" }

My knowledge of a string would be basically a string more than one character, if I am correct, which has nothing todo with elements seperately.

set name "my name is bla bla...."
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked