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 getting info from site

Help for those learning Tcl or writing their own scripts.
Post Reply
H
Hamish
Voice
Posts: 25
Joined: Mon Mar 27, 2006 1:20 pm

Help with getting info from site

Post by Hamish »

Ok I got this so far:

Code: Select all

bind pub - !stats stats:private

proc stats:private {nick uhost hand chan text} {
  set rsname [lindex $text 0]
  set site "http://*/stats2.php?name=$rsname"
  set token [::http::geturl $site]
  set content [::http::data $token]
  ::http::cleanup $content
  foreach line [split $content \n] {
    putserv "NOTICE $nick :Runescape hiscores lookup for $rsname"
    putserv "NOTICE $nick :$line"
  }
} 
I get this error:
-Bot- Runescape hiscores lookup for hamish150
-Bot- Overall: 970 Attack: 64 Defence: 60 Strength: 59 Hitpoints: 61 Ranged: 51 Prayer: 41 Magic: 50 Cooking: 62 Woodcutting: 56 Fletching: 34 Fishing: 61 Firemaking: 41 Crafting: 49 Mining: 55 Agility: 40 Thieving: 37 Slayer: 31
-Bot- Runescape hiscores lookup for hamish150
The site it connects is a single line containing the stats as shown in the second notice. What I need to do is, get rid of the third notice (the repeat of the the first one). I also need to know how to put it into colour, and, for the second notice to put all the words in darkred (5,0) and the numbers in darkblue (2,0).

I also need it so that if there are no numbers in $line it will return that the user's hiscores aren't ranked.

Also how would I be able to make it so that if the user types two words or more as a name, for example:

!stats jim bob jones

It will set $rsname as jim_bob_jones?

Thanks!
Thanks, Hamish.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Move the
putserv "NOTICE $nick :Runescape hiscores lookup for $rsname"
before (outside) the loop (foreach) and should say that just once.
Once the game is over, the king and the pawn go back in the same box.
H
Hamish
Voice
Posts: 25
Joined: Mon Mar 27, 2006 1:20 pm

Post by Hamish »

Cool, thanks. :)

Do you think you could help me with colours too?
Thanks, Hamish.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Hamish wrote:Cool, thanks. :)

Do you think you could help me with colours too?
Colour and formatting codes
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
H
Hamish
Voice
Posts: 25
Joined: Mon Mar 27, 2006 1:20 pm

Post by Hamish »

Ok, rockon thanks.

I now have this, I have added some stuff for design reasons:

Code: Select all

bind pub - !stats stats:private

proc stats:private {nick uhost hand chan text} {
  set rsname [lindex $text 0]
  set site "http://*/stats2.php?name=$rsname"
  set token [::http::geturl $site]
  set content [::http::data $token]
  ::http::cleanup $content
    putserv "NOTICE $nick :\0032,0(\0035,0Runescape hiscores lookup for\0032,0 $rsname)\003"
  foreach line [split $content \n] {
    putserv "NOTICE $nick :\0032,0(\0035,0$line\0032,0)\003"
  }
}
Ok, so now it looks nice but:
-Bot- (Runescape Hiscores Lookup for hamish150)
-Bot- (Overall: 970 Attack: 64 Defence: 60 Strength: 59 Hitpoints: 61 Ranged: 51 Prayer: 41 Magic: 50 Cooking: 62 Woodcutting: 56 Fletching: 34 Fishing: 61 Firemaking: 41 Crafting: 49 Mining: 55 Agility: 40 Thieving: 37 Slayer: 31 )
-Bot- ()
What's with the extra ()?
Thanks, Hamish.
N
Nara
Halfop
Posts: 40
Joined: Sun Jul 23, 2006 11:12 pm

Post by Nara »

Cancel out the ( using a \ and the ) with a \. That should do it.

~Nara
H
Hamish
Voice
Posts: 25
Joined: Mon Mar 27, 2006 1:20 pm

Post by Hamish »

Ok, fixed up that (used string trim).
Now I have this code, it doesn't work, please tell me whats wrong with it.

Code: Select all

proc stats:private {nick uhost hand chan text} {
  if {![lindex $text 0]} {
    set rsname $nick
  }
  else {
    set rsname [lindex $text 0]
  }
  set site "http://kewlbot.us.jerrcs.net/stats2.php?name=$rsname"
  set token [::http::geturl $site]
  set content [::http::data $token]
  ::http::cleanup $content
  putserv "NOTICE $nick :\0035,0Runescape\00314,0 Hiscores Lookup for \0035,0$rsname\00314,0:\003"
  set line [string trim $content]
  putserv "NOTICE $nick :\00314,0$line\003"
} 
Basically if the user doesn't specify a name (!stats NAME) it just uses there nickname instead. Please help. :)
Thanks, Hamish.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Hamish wrote:

Code: Select all

proc stats:private {nick uhost hand chan text} {
  if {![lindex $text 0]} {
    set rsname $nick
  } else {
    set rsname [lindex $text 0]
  }
Basically if the user doesn't specify a name (!stats NAME) it just uses there nickname instead. Please help. :)
That's because you have "set rsname $nick" there. If you want it to return an error msg or help msg, I'd change "if {[$lindex $text 0]}" to

Code: Select all

if {$text == ""} {
    puthelp "PRIVMSG $nick :Please supply a name!";return
} else {
I would also suggest that you [split $text] to prevent problems with tcl special chars.
H
Hamish
Voice
Posts: 25
Joined: Mon Mar 27, 2006 1:20 pm

Post by Hamish »

Sorry I didn't explain very well, I need it to return the statistics for the persons nickname if they don't specify a name, for example:
<RandomGuy> !stats
-Bot- Stats for RandomGuy
-Bot- Blablabla
Thanks.
Thanks, Hamish.
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Code: Select all

proc stats:private {nick uhost hand chan text} {
  if {[set target [lindex [split $text] 0]] == ""} {
    set target $nick
  }
  set site "http://kewlbot.us.jerrcs.net/stats2.php?name=$target"
  set token [::http::geturl $site]
  set content [::http::data $token]
  ::http::cleanup $content
  putserv "NOTICE $nick :\0035,0Runescape\00314,0 Hiscores Lookup for \0035,0$target\00314,0:\003"
  set line [string trim $content]
  putserv "NOTICE $nick :\00314,0$line\003"
} 
Post Reply