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.

[solved] best way to apprach this

Help for those learning Tcl or writing their own scripts.
Post Reply
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

[solved] best way to apprach this

Post by doggo »

grabs a added time from a db in unix time

but im having a right time getting it to return what i want in channel :/

heres the proc

Code: Select all

namespace eval mp3_time_add {
proc get_mp3_time {nick host hand chan text} {

	set time_pred ""
	set add_time_mp3 [::mysql::connect -host $reqs::sett::db_host -port $reqs::sett::db_port -user $reqs::sett::db_user -password $reqs::sett::db_pass -db $reqs::sett::db_pre_name];
	set added_mp3 [::mysql::sel $mp3_pre "SELECT $reqs::sett::db_pre_time FROM $reqs::sett::db_pre_table where $reqs::sett::db_pre_rls = '$add_rls'" -flatlist];
	::mysql::endquery $add_time_mp3
	::mysql::close $add_time_mp3
	if {$added_mp3 == ""} {set time_pred "unknown"} else {
	set now [unixtime]
	incr now -$pre_mp3
	set time_pred [duration $now]
    	regsub -nocase {seconds} $time_pred "s" time_pred
    	regsub -nocase {second} $time_pred "s" time_pred
    	regsub -nocase {minutes} $time_pred "m" time_pred
    	regsub -nocase {minute} $time_pred "m" time_pred
    	regsub -nocase {hours} $time_pred "h" time_pred
    	regsub -nocase {hour} $time_pred "h" time_pred
    	regsub -nocase {days} $time_pred "d" time_pred
    	regsub -nocase {day} $time_pred "d" time_pred
    	regsub -nocase {weeks} $time_pred "w" time_pred
    	regsub -nocase {week} $time_pred "w" time_pred
   	regsub -nocase {months} $time_pred "m" time_pred
    	regsub -nocase {month} $time_pred "m" time_pred
    	regsub -nocase {years} $time_pred "y" time_pred
    	regsub -nocase {year} $time_pred "y" time_pred
	#regsub -all { |\*} $time_pred {} time_pred
	putquick "PRIVMSG $reqs::sett::add_chan :$time_pred"
	}

#END NAMESPACE mp3_time_add
}


currently returns

[Pred 1 d 12 h 56 m 59 s ago]

if i use the regsub to remove the spaces it returns

[Pred 1d13h27m8s ago]

but i realy realy want it to return like this

[Pred 1d 12h 56m 59s ago]

if anyone has any better way to achieve this id be most interested, thanks :D
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

Code: Select all

namespace eval mp3_time_add { 
proc get_mp3_time {nick host hand chan text} { 

   set time_pre "" 
   set add_time_mp3 [::mysql::connect -host $reqs::sett::db_host -port $reqs::sett::db_port -user $reqs::sett::db_user -password $reqs::sett::db_pass -db $reqs::sett::db_pre_name]; 
   set added_mp3 [::mysql::sel $mp3_pre "SELECT $reqs::sett::db_pre_time FROM $reqs::sett::db_pre_table where $reqs::sett::db_pre_rls = '$add_rls'" -flatlist]; 
   ::mysql::endquery $add_time_mp3 
   ::mysql::close $add_time_mp3 
   if {$added_mp3 == ""} {set time_pred "unknown"} else { 
   set now [unixtime] 
   incr now -$pre_mp3 
   set time_pre [duration $now] 
    	regsub -nocase -all -- { seconds|seconds} $time_pre "s" time_pre
    	regsub -nocase -all -- { minutes|minutes} $time_pre "m" time_pre
    	regsub -nocase -all -- { hours|hours} $time_pre "h" time_pre
    	regsub -nocase -all -- { days|days} $time_pre "d" time_pre
    	regsub -nocase -all -- { weeks|weeks} $time_pre "w" time_pre
    	regsub -nocase -all -- { months|months} $time_pre "m" time_pre
    	regsub -nocase -all -- { years|years} $time_pre "y" time_pre
   putquick "PRIVMSG $reqs::sett::add_chan :$time_pred" 
   } 

#END NAMESPACE mp3_time_add 
} 
i just needed to read more :D

returns

Code: Select all

[Pred 27y 50w 5d 22m 46s ago]
just how i wanted
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: [solved] best way to apprach this

Post by speechles »

Code: Select all

namespace eval mp3_time_add {
proc get_mp3_time {nick host hand chan text} {

	set add_time_mp3 [::mysql::connect -host $reqs::sett::db_host -port $reqs::sett::db_port -user $reqs::sett::db_user -password $reqs::sett::db_pass -db $reqs::sett::db_pre_name];
	set added_mp3 [::mysql::sel $mp3_pre "SELECT $reqs::sett::db_pre_time FROM $reqs::sett::db_pre_table where $reqs::sett::db_pre_rls = '$add_rls'" -flatlist];
	::mysql::endquery $add_time_mp3
	::mysql::close $add_time_mp3
	if {![string length $added_mp3]} {set time_pred "unknown"} else {
		set now [unixtime]
		incr now -$pre_mp3
		foreach {val short} [split [duration $now] " "] { append time_pred "$val[string index $short 0] " }
		putquick "PRIVMSG $reqs::sett::add_chan :[string trim $time_pred]"
	}

#END NAMESPACE mp3_time_add
}
Post Reply