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.

.000000 overload!

Old posts that have not been replied to for several years.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

I don't see why you all are using these string functions. There is a round command in tcl. It's quite simple really.

You want to round [lindex $all 3], so

Code: Select all

set num [lindex $all 3]
set num [expr round(100*$num)/100.0]
if {$num >= 0} {
  set num "+$num"
}
That's about it.

ps. just a stylistic note, it's usually a lot clearer to break things onto multiple lines than have one line with 4 levels of nested brackets hehe.

pps. place this code before your "string map" command and then use $num instead of [lindex $all 3]. Also, "string map" is a strange way to do it. It's better to say if $num < 0, set num "<colorcode>$num" and the other color in the else.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

it was the script that Papillon suggested I use...
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

hi guys, none of the lines of script mentioned above work for me - by the way, no point saying 'I don't see why you're doing it like this..' etc because I'm just doing what is suggested to me on this forum by ppl helping me!

I guess it's just not possible to do what I want to do in TCL...

thanks anyway.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

NewzBoy, I hate to sound harsh, but all of the things we've suggested work. You're probably just doing it wrong. Also, I dunno where you got that script but it's pretty horrible. Do you see the first line? That allows anybody to run code on your bot heh.

set [lindex [info args pub:quote] 4] [string trimleft [subst $[lindex [info args pub:quote] 4]] !]

"info args pub:quote" returns the argument list for that proc, e.g. "nick uhost handle channel arg".

lindex 4, returns the 5th arg, which is arg.

Now, do you know what subst does? Subst evaluates whatever you give it.

So this part of that line, [subst $[lindex [info args pub:quote] 4]], is taking the variable $arg and evaluating it.

It's just disguised so it doesn't immediately look like a backdoor.

Anyway if you want to test it, try !q [die] and see what happens.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

hi st - thanks for the help and tips. if there are any 'backdoors' in the script, they are there because the bits I've added on are from help I've recieved in here...the bit you refer to was from:

http://forum.egghelp.org/viewtopic.php?t=3406

and that was provided by: ppslim - are you suggesting ppslim is trying to set me up/make me vulnerable to attack or something?

I appreciate the help I get on this forum, it's been invaluable, but I'm still learning and yes I feel dumb when I have to come back and say it's not working - will keep trying...
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

I did not say you should use it, I gave you a possible solution :)
and as stdragon said, all the given lines of code works. Either something is wrong with your eggdrop/tcl or you are using it the wrong way.

as for the backdoor.. I'm sure ppslim never meant it to be a backdoor.. look at his signature ;) ... he was probably just deep into the tequilabottle :p

...anyway.. you could use the switch command instead of the subst

Code: Select all

switch -exact -- [lindex [info args pub:quote] 4] {
  "trigger1" {do this}
  "trigger2" {do this}
  ....etc
}
something like this
Elen sila lúmenn' omentielvo
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Lol nevermind I'm stupid. I should have tested... it looks like a vulnerability but it's not.

Anyway, I put in the bit of code I showed you. And cleaned up some stuff. Give this a try.

Code: Select all

proc pub:quote { nick uhost handle channel arg } {
  global IGwords
  set arg [string trimleft $arg !]
  set cmd [lindex [split $arg] 0]
  foreach _IG $IGwords {
    if {[string equal -nocase $_IG $cmd]} { return }
  }
  if {[llength $arg]==0} {
    putserv "NOTICE $nick : 0,2 please type \002!news\002 for options "
    return
  }

  set stock [string toupper [lindex $arg 0]]
  set query "http://finance.yahoo.com/d/quotes.csv?s=$stock&f=st5l9c6p4mv&e=.csv"
  set token [http::geturl $query]
  set all [http::data $token]
  regsub -all \" $all "" all
  set all [split $all ","]

  # rounding code here
  set num [lindex $all 3]
  set num [expr round(100*$num)/100.0]
  if {$num >= 0} {
    set num "+$num"
  }

  set test [string map [list + \00309+ - \00304-] $num]
  set test2 [string map [list + \00309+ - \00304-] [lindex $all 4]]
  if {[lindex $all 2]!="0.00"} {
    putserv "PRIVMSG $channel :\0037» [lindex $all 0]:\003 [lindex $all 2] $test ($test2)\003 [lindex $all 1] USET \0037 Low-High:\003 [lindex $all 5] \0037 Volume:\003 [lindex $all 6]"
  } else {
    putserv "PRIVMSG $channel :\002 [lindex $all 0]\002 symbol not found"
  }
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Admitadly, I can't remember why the subst is there.

However, when looking at it, I do share the concerns.

In the original post, there was an issue, where we didn't have the full code. Rather than ask for the information, i tried somthing new, that would collect the information on it's own.

It's not fast, it's not ideal but it worked for him.

However, staring at it a few hundred times, reminded me why I used the subst command.

Take the following two examples.

Code: Select all

set test "Hello to all"
set list "hello test all"
puts stdout "1: $[lindex $list 1]"
puts stdout "2: [subst $[lindex $list 1]]"
This will output
[quote]
1: $test
2: Hello to all
[/code]

"$[lindex $list 1]" ins't a valid variable name. However, once "[lindex $list 1]" is evaluated, it is.

The subst just forces the evaluation of the new name.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

thank you guys - from all that I've finally been able to make it work...

many thanks for your persistance!
Locked