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.

Problem with bind time in existing script

Old posts that have not been replied to for several years.
Locked
t
thedude0001
Voice
Posts: 7
Joined: Sat Dec 18, 2004 8:32 pm

Problem with bind time in existing script

Post by thedude0001 »

Hi everybody!

I have a working script for announcing the traffic stats of a glftpd with a public trigger here. Now i wanted to modify it so the script announces the monthly traffic every hour in the chan. After looking around a bit I thought a simple 'bind time - "00 * * * *" procname' would do the trick, but it didn't.
After searching around the web for several hours I still have no idea where the problem is or how to solve it...

Here's the script:

Code: Select all

# v-1.05 22 Feb 05 (21:06:58)
# Don't know who the original author is, but I'm releasing this
# out with a few fixes to get around looping into negatives above
# 2GB when reading k size. -Genocaust

# glftpd users directory
set glftpdusers "/glftpd/ftp-data/users"

# output themes
#  variables:
#   $traffick - traffic in kilobytes
#   $trafficm - traffic in megabytes
#   $trafficg - traffic in gigabytes
#   $msgtag   - i just prepend to the outputs to match my bot theme

set msgtag          "\002Alcatraz\002 :: \[\002stats \002\]"
set gtoutput(all)   {$msgtag \002${trafficg}\002GB have passed through Alcatraz.}
set gtoutput(month) {$msgtag While passing through Alcatraz, \002${trafficg}\002GB had an out of body experience this month.}
set gtoutput(wk)    {$msgtag \002${trafficg}\002GB saw Elvis this week in Alcatraz.}
set gtoutput(day)   {$msgtag Today \002${trafficg}\002GB all agreed that 'if the dick don't fit, you must acquit.'}

# trigger
set gtcommand "!traffic"


# usage is: trigger [day/wk/month/all] - if not period is specified the default will be used
set gtdefault "month"

proc gtgltraffic {nick host hand chan arg} {
	set monthup 0
	set monthdn 0
	global msgtag
	if {[llength [split $arg]]==0} {
		set period $::gtdefault
	} else {
		set period [lindex $arg 0]
	}
	if {![info exists ::gtoutput($period)]} {
		puthelp "PRIVMSG $chan :usage: $::gtcommand \[day/wk/month/all\]"
		return
	}
	foreach user [glob -nocomplain $::glftpdusers/*] {
#		putlog $user
		if {[catch {open $user} fp]} {
#			putlog "glftpd-traffic.tcl: $fp :("
			continue
		}
		set lines [split [read $fp] \n]
		foreach line $lines {
			if {[lindex [split $line] 0]=="[string toupper $period]UP"} {
#				putlog $line
				foreach {files size time} [lrange [split $line] 1 end] {
					if {$size==""} {continue}
					incr monthup $size
				}
			} elseif {[lindex [split $line] 0]=="[string toupper $period]DN"} {
#				putlog $line
				foreach {files size time} [lrange [split $line] 1 end] {
					if {$size==""} {continue}
					incr monthdn $size
				}
			}
		}
	}
	set traffick [expr wide($monthdn) + wide($monthup)]
	set trafficm [format %.1f [expr wide($traffick) /1024.0]]
	set trafficg [format %.1f [expr wide($trafficm) /1024.0]]
	puthelp "PRIVMSG $chan :[subst -nocommands $::gtoutput($period)]"
}

bind pub - $gtcommand gtgltraffic

putlog "glFTPD Traffic 1.05 loaded"
Any help is really appreciated.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

did you try 'bind time - "00 * * * *" gtgltraffic'?
I hope read TCL-Commands.tcl close to recognize, that this would result in something like:
nick=00
host=17
hand=28
chan=04
arg=2005
^-^
so you have to "reply" it with a proc like:

Code: Select all

bind time - "00 *" gtgltraffic:t

proc gtgltraffic:t {min h d m y} {
   gtgltraffic {} {} {} #channel {}
   return 0
}
dont forget to replace your channel name :P.
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...
t
thedude0001
Voice
Posts: 7
Joined: Sat Dec 18, 2004 8:32 pm

Post by thedude0001 »

That actually worked :D

Thanks a lot! :D
Locked