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.

Need help with Web Parsing-like Eggdrop/TCL-Script

Old posts that have not been replied to for several years.
Locked
A
Aenguish
Voice
Posts: 6
Joined: Tue Apr 26, 2005 5:33 am

Need help with Web Parsing-like Eggdrop/TCL-Script

Post by Aenguish »

Hi there, I have a Problem with an TCL-Script for my Windrop.

It should output the Playerinfos from www.nollex.de in the Channel when its called with e.g."user_search 3 micromaster".

Its for a Browsergame called ogame (www.ogame.de)
I´m really new to this Eggdrop/tcl stuff, would be really kind if someone could help me bit out :wink:


Heres the script:

Code: Select all

proc user_search {mode args} { 
  if {![regexp {\A[123]{1}\Z} $mode]} {error "Error: Mode has to be 1, 2 or 3. (Not \"$mode\"!)"} 
  package require http 
  foreach char [split $args {}] { append keyword %[format %x [scan $char %c]] } 
  set string [::http::data [::http::geturl http://www.nollex.de/ogame/se_uni1.php?cmbAllyPlayer=Player&txtSuchen=$keyword]] 
  regexp {..:: punkte ::..(.*)..:: forschung ::..(.*)..:: flotte ::..(.*)\Z} $string -> data(1) data(2) data(3) 
  set string $data($mode) 
  set output {} 
  while {[regexp {<tr[^>]*><[^>]*><[^>]*>([^<]+)<[^>]*><[^>]*><[^>]*><[^>]*><[^>]*>([^<]+)<[^>]*><[^>]*><[^>]*><[^>]*><[^>]*><[^>]*>([^<]*)<[^>]*><[^>]*><[^>]*><[^>]*><[^>]*>([^<]+)<[^>]*><[^>]*><[^>]*><[^>]*>([^/]+)/([^<]+)<[^>]*><[^>]*>([^<]+)<[^>]*><[^>]*>[^\(]*\(([^%]+)%\)<[^>]*><[^>]*></tr>(.*)} $string -> rank player ally score from to scoregain percent string]} { 
    append output "$rank / $player / $ally / $score / $from - $to / $scoregain / $percent%\n" 
  } 
  return [string trim $output]

The Error message reads:
Tcl error [user_search]: can't read "data(aenguish)": no such element in array
Thanks for reading, greats Aenguish
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

There is no $data(aenguish) in the proc you displayed, the error's probably comming from another proc, try .set errorInfo in your partyline to know more info about the error.
A
Aenguish
Voice
Posts: 6
Joined: Tue Apr 26, 2005 5:33 am

Post by Aenguish »

"Aenguish" is the Nickname of the one who calls the script.
ok, i will try .set errorinfo and post the result
A
Aenguish
Voice
Posts: 6
Joined: Tue Apr 26, 2005 5:33 am

Post by Aenguish »

Ok, here it is:

marvin <- Name of the Bot
lord <- User who calls the script

Code: Select all

[20:30] <marvin> Currently: can't read "data(lord)": no such element in array
[20:30] <marvin> Currently:     while executing
[20:30] <marvin> Currently: "set string $data($mode) "
[20:30] <marvin> Currently:     (procedure "user_search" line 6)
[20:30] <marvin> Currently:     invoked from within
[20:30] <marvin> Currently: "user_search $_pub1 $_pub2 $_pub3 $_pub4 $_pub5"
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

i'am not tcl expert, but try to put (not really know, if it help)

Code: Select all

global data
right after proc xxxx....
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

you cannot use the code above.
your error can only occure, when $mode is lord or Aenguish etc.
but the code you posted doesnt allow to be $mode something like that. I confirmed the regexp and the error command do work that way they are supposed to.

If nothing helps, replace the var name "args" with "arg" and give it a try again. I don't see why it could cause it, but its obvious, mode doesnt contain the number its suppsed to.
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...
A
Aenguish
Voice
Posts: 6
Joined: Tue Apr 26, 2005 5:33 am

Post by Aenguish »

Yes, mode was always the nickname, i dont see why, but when i give args like that:

Code: Select all

proc user_search {nick uhost hand chan mode args} { 
He throws another error:

Code: Select all

Error: Mode has to be 1, 2 or 3. (Not "1 micromaster"!)
Im really lost :cry:
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

have you any activ binds to that proc? the proc seems to be intented to be called as function, not to be triggered by a bind ^-^.
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...
A
Aenguish
Voice
Posts: 6
Joined: Tue Apr 26, 2005 5:33 am

Post by Aenguish »

Yes, its :
bind pub - !nollex user_search
Do i have to call it in a different way?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

From tcl-commands.doc:
PUB
bind pub <flags> <command> <proc>
procname <nick> <user@host> <handle> <channel> <text>

Description: used for commands given on a channel. The first word
becomes the command and everything else is the text argument.
Module: irc
so from your initial proc, mode is the nick and args is the rest (i.e. uhost hand chan text).
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

ROFL
dont you think you have forgotten to send the output somewhere? ^^

Code: Select all

bind pub - !nollex user:search

proc user:search {nick uhost hand chan text} {
   set text [split $text]
   puthelp "NOTICE $nick :[user_search [lindex $text 0] [join [lrange $text 1 end]]]"
   return 0
}
use something like this and stop making so funny things :D.
usage with be then:
!nollex <mode> <args>
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...
A
Aenguish
Voice
Posts: 6
Joined: Tue Apr 26, 2005 5:33 am

Post by Aenguish »

:lol: :lol:

Thanks for the "hint" *g*
h
hellspawn
Voice
Posts: 1
Joined: Sat May 28, 2005 9:09 am

Post by hellspawn »

Hi,

i'm trying to do the same script. do you get it work ?
G
Ghoete
Voice
Posts: 4
Joined: Fri Jan 07, 2005 2:01 pm

Post by Ghoete »

Can you post the script?
Locked