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.

Simple read & display webpage script

Old posts that have not been replied to for several years.
Locked
A
Astatine
Voice
Posts: 3
Joined: Sun Dec 19, 2004 12:18 pm

Simple read & display webpage script

Post by Astatine »

Hi all, I need help writing a very simple script. It needs to take a pubic msg from a channel that specifies an id number (such as !id 999) and then grab the contents of a page (such as www.domain.com/content.php?id=999) and display it. The id number will change and the output of the web page can be very bare, just the needed data. Can someone help me with this? Thanks.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

package require http
bind pub - !id foo
proc foo {n u h c t} {
  set t [::http::geturl http://www.domain.com/content.php?id=$t]
  foreach line [split [::http::data $t] \n] {puthelp "privmsg $c :$line"}
  ::http::cleanup $t
}
you might want to add some error checking to this
A
Astatine
Voice
Posts: 3
Joined: Sun Dec 19, 2004 12:18 pm

Post by Astatine »

Thanks, it works perfectly.
D
DJ-X-Ray133
Voice
Posts: 4
Joined: Tue Jan 04, 2005 2:19 pm

Post by DJ-X-Ray133 »

Hi,
I wrote a Script in PHP on my Webserver.
The content of this script changes often a day.

I need a script that gets the content only when its requestet by !foo in a channel. How can i do this???

Does your Script do this demond?

Thank you,
Dj-X-Ray133
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

try it, changing the URL to yours
D
DJ-X-Ray133
Voice
Posts: 4
Joined: Tue Jan 04, 2005 2:19 pm

Post by DJ-X-Ray133 »

It seems to work great, thank you.

But some people in my channel don't like bots so i decided to let him act by msg and not by public requests. But when I msg the !command the console says:

[01:55] Tcl error [today]: wrong # args: should be "today n u h c t"

how can i fix it?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

package require http 
bind msg - cmd foo 
proc foo {n u h t} { 
  set t [::http::geturl http://yourURL] 
  foreach line [split [::http::data $t] \n] {puthelp "notice $n :$line"} 
  ::http::cleanup $t 
} 
D
DJ-X-Ray133
Voice
Posts: 4
Joined: Tue Jan 04, 2005 2:19 pm

Post by DJ-X-Ray133 »

Thank you very much it works perfect. But how can I use two or more arguments vor the website like $t???

Sry, i dont like tcl much, i'd like a php module for eggdrop ^^

Cya, Dj-X-Ray133
D
DJ-X-Ray133
Voice
Posts: 4
Joined: Tue Jan 04, 2005 2:19 pm

Post by DJ-X-Ray133 »

Maybe i hsould describe it more:
i want that the users that give the bot the command can use two arguments, like
!foocmd foo1 foo2

And then it would go to a homepage like
http://foo.org/foo.php?foo1=$foo1&foo2=$foo2

Is that possible????
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

package require http 
bind msg - cmd foo 
proc foo {n u h t} { 
  set foo1 [lindex [split $t] 0]
  set foo2 [lindex [split $t] 1]
  set t [::http::geturl http://foo.org/foo.php?foo1=${foo1}&foo2=${foo2}] 
  foreach line [split [::http::data $t] \n] {puthelp "notice $n :$line"} 
  ::http::cleanup $t 
} 
Locked