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.

new version of convert.tcl

Support & discussion of released scripts, and announcements of new releases.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

new version of convert.tcl

Post by rosc2112 »

Another completely re-written script. Trimmed all the fat, made it special-char safe, etc. All of the conversion binds now go through one main proc, this reduces the amount of redundant code, making the script lean and mean. An added bonus is the capacity to use the .calc function for almost anything you can use [expr] for, but in a safe manner (I say almost, because it will not handle variables, command substitutions in [], or other unsafe procedures =)

Script can be found here:
http://members.dandy.net/~fbn/convert.2.tcl.txt

For those who may not know, convert.tcl does conversions to/from metric/imperial units, and also has a mathematical/arithmetical calculator.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

calc won't work with expressions containing adjacent whitespaces
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

You mean like '1 + 1' ? Not sure I follow your meaning.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

my calc bind looks like that and I am pretty confident about the safety:

Code: Select all

...
	set text [string map {[ ( ] ) $ " dollar "} $text]
...
	catch {set ergebnis [expr $text]} fehler
...
At least I failed with all my imaginations to force a second substitition.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

rosc2112 wrote:You mean like '1 + 1' ? Not sure I follow your meaning.

Code: Select all

'1 +         1'
you might want to take a look at my FAQ post about splitting
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

'1 +         1'
I don't see that as a problem, it just makes the script return an error msg.
you might want to take a look at my FAQ post about splitting
It does use split on the user input.

I made one small update to the script as well, to use [split] on the calc $reply, so that replies are properly formated (otherwise it drops chars when [join $rep] is sent to the user.)

Found a few typos too, fixed :P
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Read last post here.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Neat. Thanks :)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

v205b

Post by rosc2112 »

Some minor updates to the convert script. v205b. Same url as above.
21/5/06 - Added inch/centimeter conversion..
27/5/06 - A better string2list was posted in egghelp.org and is now incorporated here.
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

Post by incith »

I'm not sure how this post will be taken, but by all means I am not trying to prevent people from using your script.

I just thought I would point out, incith:google script, and Google itself, does conversions for just about anything. I can even calculate download times with something like 5 MB / 50 KB/s = (5 MB) / (50 (KB / s)) = 102.4 seconds, or you can do 5 MB / 50 KB/s in minutes, and your result would be in minutes.

Perhaps this post is more directed at those that may already use :google script. :)

Good job though, a local conversions script will always be faster than one doing net lookups.

Again, sorry if I've intruded this thread, I'm not looking for props on my scripts or anything. *paranoid* :)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

No problem Incith. I actually have your google script in my work dir, haven't had a chance to put it into the bot yet, but it's in my pile of todo stuff :)

I'm sure once I do start using it, I'll be pestering you with bugreports and suggestions too, like I do with everyone else ;)

I'm also using your horoscope script and did some minor tweaks to my local copy, didn't think they were significant enough to post about. The most significant change I made was to use:

Code: Select all

catch {set http [::http::geturl "${query}daily${input}.html" -timeout [expr 1000 * 15]]} error

[..snip..]

catch {set http [::http::geturl "${query}dailychinese${input}.html" -timeout [expr 1000 * 15]]} error

[..snip..]

     if {[string match -nocase "*couldn't open socket*" $error]} {
            return "Error: couldn't connect..Try again later"
      }

if { [::http::status $http] == "timeout" } {

[..snip..] 

I added the catch and return error msg cos my isp's dns sucks and I've hit 'host unreachable' quite a few times in scripts.

Also had to change:

Code: Select all

       regsub -- "^${incith::horoscope::command_char}" $input "" input
to:
        regsub -- ^\\. $input "" input
because I use the . char as a cmd char, and the regsub was thinking that the . was an atom so it was chopping off the 1st letter of the sign name when using .horoscope leo, for example.

Also changed this a bit to give more verbose help:

Code: Select all

Original:

   namespace eval horoscope {
     # SEND_OUTPUT
     # no point having two copies of this in public/private_message{}
     #
     proc send_output {input where} {
       foreach line [incith::horoscope::parse_output [horoscope $input]] {
         putquick "PRIVMSG $where :$line"
       }
     }

---
My change:

namespace eval horoscope {
 # SEND_OUTPUT
 # no point having two copies of this in public/private_message{}
   proc send_output {input where} {
      if {$input == ""} {
         puthelp "PRIVMSG $where :Please choose a sign: capricorn aquarius pisces aries taurus gemini cancer leo virgo libra scorpio sagittarius rat ox tiger rabbit dragon snake horse goat monkey rooster dog pig"
         return
      }
      set validsign 0
       foreach sign [split $incith::horoscope::valid_signs " "] {
            if {$input == $sign} {
                  set validsign 1
            }
       }
       if {$validsign == 0} {
              puthelp "PRIVMSG $where :Please choose a sign: capricorn aquarius pisces aries taurus gemini cancer leo virgo libra scorpio sagittarius rat ox tiger rabbit dragon snake horse goat monkey rooster dog pig"
             return
       } else {
               foreach line [incith::horoscope::parse_output [horoscope $input]] {
                     puthelp "PRIVMSG $where :$line"
                }
         }
  }
And now I've totally mucked up this topic thread <g>
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Hmm, now that I looked at my changes again, I just noticed a bit I can condense:

Code: Select all

                proc send_output {input where} {
                      set validsign 0
                      foreach sign [split $incith::horoscope::valid_signs " "] {
                                if {$input == $sign} {
                                        set validsign 1
                                }
                        }
                        if {($validsign == 0) || ($input == "")} {
                                puthelp "PRIVMSG $where :Please choose a valid sign: etc etc"
                                return
                        } else {
                              foreach line [incith::horoscope::parse_output [horoscope $input]] {
                                        puthelp "PRIVMSG $where :$line"
                              } 
                        }
                 }
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

Post by incith »

You're amazing. :o

If you do submit any google changes, they'd have to go to the guy I handed the script over to, madwoota.

As for horoscope.. it is probably due for an update, but weather was a priority.

I'll definitely refer back to this thread for a future horoscope release. The . problem can likely be resolved by changing the regexp to {} instead of "", but it is late, and sometimes I think I know Tcl better than I really do (which isn't that well). To be honest, I never use horoscope.. perhaps I'll wait until my luck feels a bit better. :)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

incith wrote: If you do submit any google changes, they'd have to go to the guy I handed the script over to, madwoota.
Ahh, didn't know you handed it off. I'll have to grab a more recent version (I have v1.8 in my archive)
As for horoscope..
The . problem can likely be resolved by changing the regexp to {} instead of ""
Yep, just tried it, and it worked :)

Tnx :)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

oops, my bad, I must be tired too..It didnt work (I mis-tested it... I did .horoscope leo, the error shows when I do .leo - the 1st letter gets chopped..) Garf..
Post Reply