egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

new version of convert.tcl
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Apr 25, 2006 5:00 pm    Post subject: new version of convert.tcl Reply with quote

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.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Apr 26, 2006 3:47 am    Post subject: Reply with quote

calc won't work with expressions containing adjacent whitespaces
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Apr 26, 2006 4:46 am    Post subject: Reply with quote

You mean like '1 + 1' ? Not sure I follow your meaning.
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Wed Apr 26, 2006 5:03 am    Post subject: Reply with quote

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

Code:
...
   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...
Back to top
View user's profile Send private message MSN Messenger
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Apr 26, 2006 5:17 am    Post subject: Reply with quote

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


Code:

'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] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Apr 26, 2006 5:28 pm    Post subject: Reply with quote

Quote:

Code:

'1 +         1'


I don't see that as a problem, it just makes the script return an error msg.

Quote:

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 Razz
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Apr 26, 2006 6:13 pm    Post subject: Reply with quote

Read last post here.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Apr 27, 2006 7:45 pm    Post subject: Reply with quote

Neat. Thanks Smile
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Jun 10, 2006 2:58 pm    Post subject: v205b Reply with quote

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.
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Mon Jun 12, 2006 4:30 pm    Post subject: Reply with quote

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. Smile

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* Smile
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Jun 13, 2006 1:27 am    Post subject: Reply with quote

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 Smile

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 Wink

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:

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:

       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:

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>
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Jun 13, 2006 1:59 am    Post subject: Reply with quote

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

Code:

                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"
                              }
                        }
                 }
Back to top
View user's profile Send private message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Tue Jun 13, 2006 3:35 am    Post subject: Reply with quote

You're amazing. Surprised

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. Smile
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Jun 13, 2006 5:35 am    Post subject: Reply with quote

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)
Quote:

As for horoscope..
The . problem can likely be resolved by changing the regexp to {} instead of ""

Yep, just tried it, and it worked Smile

Tnx Smile
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Jun 13, 2006 5:39 am    Post subject: Reply with quote

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..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber