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.

Publish Channel Stats/Userlist to website - PHP

Old posts that have not been replied to for several years.
Locked
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Publish Channel Stats/Userlist to website - PHP

Post by Stylez »

I would like to know if anyone knows of a basic script that would do the following OR be able to make one :D :
Take the current # of users in a channel, their names (maybe including voices +, op @, and appended it to their name, but this would probably happen anyways), and the current topic. Then save it to a file, with a .php extension. THEN, ftp it to a webserver every x mins. :D This sounds maybe somewhat easy for you tcl guru's, but way too hard for me. Anyways, it should be in this format:
There are #USERS in channel.

Current Topic:
currenttopic

Users:
User1
User2
User3

...
Something like that. I just want to do a php include and have this on the left hand menu of my site = http://www.kronicconcerz.com
BTW, I run a Windrop if that makes a diff *hides*
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Yes it does make a differance.

There are two ways to go about this.

Be lazy, and let us do all the leg work. This way usualy takes a long time, as we do not do on demand, unless we feel it is a worthy cause, and would be usful to ourselves or teh masses.

Or learn Tcl, slowly, and addapt scripts in existance. Can take just as long as the first method, but will also help inthe longrun. There are snippets of code, all through this forum, code in the Tcl archive, and a well documented tcl-commands.doc, that will help you do this.

One such snippet, was some code that would write the userlist to a file. could easily be addapted.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Okay I managed to make a working version, using code snippets here and there, and modifying and stripping. Now I only have a couple bugs to work out: Is there a way to strip the colour codes for the topic, or any text using the tcl? Also I'm getting this error all of a sudden:
Tcl error in script for 'timer1540':
can't read "topic": no such variable
Even though this worked like 5 minutes ago.
Here is the script so far:

Code: Select all

#Set the variables

#set the file you want to write to
set tghtmlfile "d:/matt/public_html/kc-chan.html"

#Channel to show stats for
set tgchan "#kc"

#How often (in seconds) does the html file get updated. 
set tghtmlrefresh 60

#  The font to use on the html page.
set tghtmlfont "verdana,helvetica,arial"

#what is the topic on the channel?
#set thetopic [topic $tgchan]

#Check and Inits
if {[utimerexists tghtml]!=""} {killutimer $tghtmlrefreshtimer}
if {$tghtmlrefresh>0} {
 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}

#this generates an html file with all the people on the chan 
#and the channel topic
proc tghtml {} {
 global tgchan botnick tghtmlfile tghtmlrefresh server 
 global tgrealnames 
 global tghtmlfont
 global topic
 set _file [open $tghtmlfile~new w]
 puts $_file "<p>$tgchan Topic:<br>$topic</p><br>"
 puts $_file "<table width=150><tr><td width=100>Name</td><td width=50>Idle</td></tr>"
foreach nick [lsort [chanlist $tgchan]] {
   puts $_file "   <tr>"
   puts $_file "    <td>[expr [isop $nick $tgchan]?"@":""][expr [isvoice $nick $tgchan]?"+":""]$nick[expr [string match $nick $botnick]?" (Bot)":""]</td>"
puts $_file "   <td>[expr [getchanidle $nick $tgchan]>10?"[getchanidle $nick $tgchan]m":"-"]</td>"
}
 #puts $_file ""
 #puts $_file ""
 #puts $_file ""
 #puts $_file ""
 close $_file
 file rename -force $tghtmlfile~new $tghtmlfile
 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}
set thetopic [topic $tgchan] is commented out because I used global topic inside the tghtml process.
I'll work on it some more and see if I can figure it out myself until maybe someone replies.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Okay now it works, I didn't quite understand the concept of globals and setting things and such for a minute. So I changed #set thetopic [topic $tgchan] TO set topic [topic $tgchan] and now it works. Now I just need to get the colour codes stripped off of the topic and add some more to the script so it will actually upload that file, or maybe just exec a .bat file.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Actually it doesn't work, it's just not giving any errors. It is making the html file but not actually putting the topic in it.
Also I was thinking about ftp'ing the file to the site. This may scrap the whole idea. I want to be able to do this silently, without having consoles and programs flicking up on my screen every x mins. Would it be possible to do this silently/in the background?
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

OKAY, lol, got it to work again. I moved where I set the topic down so that it is inside the procedure:

Code: Select all

#Set the variables

#set the file you want to write to
set tghtmlfile "d:/matt/public_html/kc-chan.html"

#Channel to show stats for
set tgchan "#kc"

#How often (in seconds) does the html file get updated. 
set tghtmlrefresh 60

#  The font to use on the html page.
set tghtmlfont "verdana,helvetica,arial"


#Check and Inits
if {[utimerexists tghtml]!=""} {killutimer $tghtmlrefreshtimer}
if {$tghtmlrefresh>0} {
 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}

#this generates an html file with all the people on the chan 
#and the current topic.
proc tghtml {} {
 global tgchan botnick tghtmlfile tghtmlrefresh server 
 global tgrealnames 
 global tghtmlfont
 #set the topic that is in the channel
 set topic [topic $tgchan]
 set _file [open $tghtmlfile~new w]
 puts $_file "<p>$tgchan Topic:<br>$topic</p><br>"
 puts $_file "<table width=150><tr><td width=100>Name</td><td width=50>Idle</td></tr>"
 foreach nick [lsort [chanlist $tgchan]] {
 puts $_file "   <tr>"
 puts $_file "    <td>[expr [isop $nick $tgchan]?"@":""][expr [isvoice $nick $tgchan]?"+":""]$nick[expr [string match $nick $botnick]?" (Bot)":""]</td>"
 puts $_file "   <td>[expr [getchanidle $nick $tgchan]>10?"[getchanidle $nick $tgchan]m":"-"]</td>"
}
 #puts $_file ""
 #puts $_file ""
 #puts $_file ""
 #puts $_file ""
 close $_file
 file rename -force $tghtmlfile~new $tghtmlfile
 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}
The code is quite messy, and some of the variables are not even needed. I also have to change some of the variable names because they are conflicting with the script I used to make this, which is Souperman's trivia script.
Now I end up with this as my file:

Code: Select all

<p>#kc Topic:<br>12^kC Trivia - Now 4only12 available in 11,12#kc-trivia</p><br>
<table width=150><tr><td width=100>Name</td><td width=50>Idle</td></tr>
   <tr>
    <td>@ChanServ</td>
   <td>-</td>
   <tr>
    <td>@Kami-M|M</td>
   <td>-</td>
   <tr>
    <td>@+KronBot (Bot)</td>
   <td>-</td>
   <tr>
    <td>@Stylez_kC</td>
   <td>-</td>
The dashes are there because the bot was restarted to overcome the tcl errors, so it hasn't gathered an idle time yet.
/me is getting his learn on.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Apparently, as I've read on the forums in some places, there is a flaw in Windrop/TCL that won't allow you to exec programs on windows? Is this right? Because when I try to execute (from sendftp-win.tcl)

Code: Select all

# Configure here the full path of your FTP.EXE program:
set progftp "C:/Windows/System32/ftp.exe"

# This is a proc to send a file via FTP to another server. Useful in many
# situations, for example to upload a HTML file generated by eggdrop to your
# www server if it is not the same as your eggdrops machine.

# Include it with 'source scripts/sendftp.tcl'.  Call it with all parameters:
#
#   sendftp <localfile> <server> <user> <password> <remotefile>
#
# 'localfile' and 'remotefile' *must* both be given as FULL paths to the
# filenames, the first on the local, the second	on the remote server.
#
# For example:
#
# sendftp /home/bill/stats.htm www.ms.com bill secret /bgates/WWW/stats.htm
#             (local-file       server    user  pass       remote-file)


proc sendftp { localfile server user pass remotefile } {
	global progftp
	if {![file exist $localfile]} {
		return "sendftp: File $localfile does not exist."
	}
	set pipe [open "|$progftp -n $server" w]
	puts $pipe "user $user $pass"
	puts $pipe "bin"
	puts $pipe "put $localfile $remotefile"
	puts $pipe "quit"
	close $pipe
	return 1
}

I get
Tcl error in script for 'timer8':
couldn't duplicate output handle: bad file number
I also get this when I used exec to execute a batch file to upload my page.
This is what is in my chanstats script

Code: Select all

sendftp d:/matt/public_html/kc-chan.html ftp.kronicconcerz.com mylogin mypass /httpdocs/kc-chan.html
I am having a HARD time with this script. :roll:
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Put it this way, you have made one of the better efforts than some, and there will likely be loads of help available to you now.

You are quite correct about this windrop issue, and there error that occurs.

There are 2 possible ways around this.

1 is to downgrade to eggdrop 1.4.*. According to the windrop FAQ on http://windrop.sf.net/ this error started in eggdrop 1.5.3, which shows signs of a eggdrop issue, but I am having a hard time, tracing where the problem started.

2, Tcllib, which is a seperate download, provides Tcl based support for being a FTP client. This, using pure script, you avoice any exe, or calls to other applications.

I would recomend the second.

Download Tcllib from http://prdownloads.sourceforge.net/tcll ... p?download

Next, you will need to save the directory structure under the lib directory of the windrop directory. I have not looked at this, but in theory, it should look like "windropdir/lib/packagename/". This you are on your own with for now.

Next, at the very time of your script, on a line of it's own, place the line "package requiree ftp". This will load the ftp package.

At the point of upload, you use the following code. replace anything within <> with the correct values.

Code: Select all

if {[set ftpsock [ftp::open <SERVER> <USERNAME> <PASSWORD> <*>]] != -1} {
  if {![ftp::put $ftpsock <LOACLFILE> <REMOTEFILE>]} {
    putlog "Failed upload on FTP socket $ftpsock"
    ftp::close $ftpsock
    return
  }
  ftp::close $ftpsock
} else {
  putlog "Failed to connect to FTP server"
}
If the port of the FTP server is different to the standard port, than replace the <*> with "-port <PORT>" without the quotes, you can otherwise remove it.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Okay I get this error when trying to load the bot
Tcl error in file 'eggdrop.conf':
couldn't read file "d:/Windrop/lib/tcllib-1.3/ftp/ftp.tcl": no such file or directory
I noticed that the dir structure is wrong, it should be d:/Windrop/lib/tcllib-1.3/modules/ftp/ftp.tcl
How do I adjust this? Would is use 'package require modules/ftp'? I'll try that anyways.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Nope package require modules/ftp didn't work. I know it says something about install.bat in the tcllib-1.3 directory, but all the file structure and such is all there, so I don't think it would be necessary to run the install.bat.
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Okay I kind of cheated and copied everything from d:/Windrop/lib/tcllib-1.3/modules/ to d:/Windrop/lib/tcllib-1.3/ - and now the bot will load but it has an error in the script:
[06:15] <KronBot> [06:15] Tcl error in script for 'timer3':
[06:15] <KronBot> [06:15] invalid command name "ftp::open"
Here is the code I used:

Code: Select all

if {[set ftpsock [ftp::open ftp.kronicconcerz.com mylogin mypass]] != -1} { 
  if {![ftp::put $ftpsock d:/matt/public_html/kc-chan.html /httpdocs/kc-chan.html]} { 
    putlog "Failed upload on FTP socket $ftpsock" 
    ftp::close $ftpsock 
    return 
  } 
  ftp::close $ftpsock 
} else { 
  putlog "Failed to connect to FTP server" 
} 
I assume that means that it may not have actually loaded the module correctly?
S
Stylez
Voice
Posts: 35
Joined: Fri Dec 06, 2002 1:32 am
Location: NS, Canada
Contact:

Post by Stylez »

Hmmmm... I redid the ftp thing myself from the lib's help files, now I get
Tcl error in script for 'timer8':
error writing "stdout": bad file number
I give up, windrop sucks compared to eggdrop. I'll settle for an automatic windows ftp program called TinyUploader to upload my file every 10 minutes. I wish I could use linux! lol I have Red Hat 8.0.. or is it 7.0.. anyways, I had it installed but COULD NOT get the internet to work, so I removed it. :roll: Anyone know of a program to emulate *nix from Windows XP? :wink:
Locked