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.

Eggdrop Web Information

Help for those learning Tcl or writing their own scripts.
Post Reply
k
karodde
Voice
Posts: 10
Joined: Tue May 01, 2007 12:56 pm

Eggdrop Web Information

Post by karodde »

Hello,
I need a script, which should do this:
When somebody in a channel types "!test", I want that my eggdrop automaticly posts a text/string. This text/string comes from a php or html file (http://www.site.com/thefile.html), i specified.
The Problem is, that the html source code contains much text, and I dont know how to tell the eggdrop, to post just the text/string I want.

By searching I found this example code:

Code: Select all

bind pub - !example my:example

proc my:example {nick uhost hand chan text} {
  set url "http://your.web.server/page.php"
  set token [::http::geturl $url]
  set content [::http::data $token]
  ::http::cleanup $content
  foreach line [split $content \n] {
    putserv "PRIVMSG $chan :$line"
  }
} 
When I use this script the whole html source code is posted by the eggdrop, but I only need one string.

Example:
<html>

...code...

<tr><td bgcolor="#ffffff"><b>Here is any text</b><br>I want this</td><td bgcolor="#ffffff" align="right" valign="top">text...<b>text</b><br>more text and so on<b>text</b></td></tr>

...code...
This is a part of the html source code, and I want the eggdrop to post the red marked text on my channel when somebody types !test.

Thanks for helping!


p.s.
Here another good example:
http://uhrzeit.org/atomuhr.html
(uhrzeit is german and means "Time"; uhr = a clock)

When somebody types !time, I want that the time is posted on the channel.
The source code from the website:

Code: Select all

...code...
<h6 id="anzeige" class="off" style="padding-left:15px;padding-right:15px;">

							13:39:53</h6><br>
						<br>
						Die Uhrzeit wird in regelmässigen Abständen mit.....code.....


EDIT:
I tried the script from demond (which needs tDOC), and it works. But it only works in my shell at home:) not with the eggdrop
Last edited by karodde on Thu May 03, 2007 7:46 am, edited 1 time in total.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

You want to use regexp to get the string you're looking for. From your example, something like:

Code: Select all

regexp {<h6 id="anzeige".*?>(.*?)</h6>.*?Die Uhrzeit} $htmlInput fullmatch exactmatch
There's lots of example scripts for grabbing data from html pages. Take a look around the forum and archive.
k
karodde
Voice
Posts: 10
Joined: Tue May 01, 2007 12:56 pm

Post by karodde »

Code: Select all

bind pub - !example my:example

proc my:example {nick uhost hand chan text} {
  set url "http://uhrzeit.org/atomuhr.html"
  set token [::http::geturl $url]
  set content [::http::data $token]
  ::http::cleanup $content
  regexp {<h6 id="anzeige".*?>(.*?)</h6>.*?Die Uhrzeit} $content fullmatch exactmatch
  putserv "PRIVMSG $chan :$exactmatch"
}
The script doesnt work, but when I change the last line:

putserv "PRIVMSG $chan :$exactmatch"
to
putserv "PRIVMSG $chan :$fullmatch"

I get the following message from my eggdrop by typing !example
(MyEggdrop) <h6 id="anzeige" class="off" style="padding-left:15px;padding-right:15px;">

p.s.
for other sites it works, thanks.
k
karodde
Voice
Posts: 10
Joined: Tue May 01, 2007 12:56 pm

Post by karodde »

Code: Select all

bind pub - !test my:test

proc my:test {nick uhost hand chan text} {          #this has to have the name theproc1
  set url "http://www.site.com/page.htm"
  set token [::http::geturl $url]
  set content [::http::data $token]
  ::http::cleanup $content
  regexp {<html>(.*?)</html>.*?} $content fullmatch exactmatch
  regexp {<html>(.*?)</html>.*?} $content fullmatch2 exactmatch2
  putserv "PRIVMSG $chan : $exactmatch"
}
When somebody types !test the 'proc' from my code will be outputted by eggdrop.

What I want now, is to give this 'proc' a name, so that I have to type "!test theproc1" to let the eggdrop output the proc theproc1.
I have other proc's too in the later code, I want to give each proc a name,
theproc1
theproc2
theproc3 and so on...

So is there any chance to give each 'proc' a name? I want that the command !test doesnt work, just the commands !test theproc1, !test theproc2, !test theproc3 should work.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

There are newlines in the result, so you either need to remove them with regsub or do some further processing (perhaps using foreach line [split $exactmatch \n]) or even change the regexp to take account of the newlines.

As far as how to handle parameters within a single proc, you basically test for them and process them. A short example:

Code: Select all

proc myproc {nick uhost hand chan text} {
        set command [lindex [split $text] 0]
        if {$command == "" || $command == "option1"} {
               # do thing1
        } elseif {$command == "option2"} {
               #do thing2
        } elseif {$command == "option3"} {
               #do thing3
        } else {
               #do default action
        }
#anti-wordwrap######################################
The action part of the if's (#do thing) can call another proc and return, or call another proc and wait for the result. If you want to get the result, you use like:

Code: Select all

#do thing1
set myvar [someotherproc (optional parameters)]
where optional parameters can be input such as $command, $nick, $text, and so on, or whatever params you want to pass to "someotherproc"

If you just want to branch off to another proc, you do:

Code: Select all

# do thing2
someotherproc (optional params)
return
[code]
Or you might want to do further processing after calling someotherproc so you leave the "return" out.

You can also integrate the other subprocs into the main proc, under the "if's"

Matter of style and design really. I generally keep everything in the same proc, unless it's reusable (meaning, other scripts or parts of the same script use the functions.)  As an example, when I make html scripts, if I have to do extensive regsub's or word-wrapping, I make the wordwrap and regsub functions into seperate procs, so that there's only 1 copy of that processing code, instead of duplicating it under many different "if" sections of the main proc.

Hope that makes some sense.
k
karodde
Voice
Posts: 10
Joined: Tue May 01, 2007 12:56 pm

Post by karodde »

thanks,
now I have a last question.
bind pub - !hello my:test

proc my:test {nick uhost hand chan text} {
set url "http://www.site.com/$hello.htm"
set token [::http::geturl $url]
set content [::http::data $token]
::http::cleanup $content
regexp {<html>(.*?)</html>.*?} $content fullmatch exactmatch
regexp {<html>(.*?)</html>.*?} $content fullmatch2 exactmatch2
putserv "PRIVMSG $chan : $exactmatch"
}
I want that the ! command (in my case !hello) is set as a variable which stands for the .htm file.

For example:
Somebody types !chair, then the page http://www.site.com/chair.htm has to be proc'ed in my proc code.
When a word is typed, that not exists (at the site) then a error message has to came.
sorry for my english

that would be awsome, thanks for the help!
k
karodde
Voice
Posts: 10
Joined: Tue May 01, 2007 12:56 pm

Post by karodde »

Another Way I would appreciate even more is this:
The command !hello is standard and should have 2 more attributes.
!hello chair blue, !hello table green and so on.
'chair blue' will have to link to a proc, 'table green' to another proc, table red to another proc, table white also to another etc...

How to make this?

I still need to tell the script, that chair has to link to chair.htm and table to table.htm. So I will have to make a variable of the .htm.
Post Reply