Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc ::bonaPRE::pre:init { args } {
- if { [catch { package require bonaPRE-SQL 1.0 }] } {
- set AE_LOGERR [format "${::bonaPRE::VAR(release)} modTCL * mysql.tcl file must be loaded before pre.tcl"]
- return -code error ${AE_LOGERR};
- }
- }
- ::bonaPRE::pre:init
- bind pub -|- !pre ::bonaPRE::pre
- proc ::bonaPRE::pre { nick uhost hand chan arg } {
- set P_Rlsname [lindex ${arg} 0]
- if { ![channel get ${chan} bpsearch] } {
- set P_LOGERR [format "User %s attempted a !pre on %s, but the channel does not have the necessary *flags*." ${nick} ${chan}]
- #set P_MSGERR [format "%s tried a !pre, but the channel does not have the necessary *flags*." ${nick}]
- putquick "privmsg ${chan} ${P_MSGERR}"
- return -code error ${P_LOGERR};
- }
- if { ${P_Rlsname} == "" } {
- set P_LOGERR [format "Syntax *%s attempted a !pre on %s, but lacks information..." ${nick} ${chan}]
- set P_MSGERR [format "Syntax * !pre <release.name>"]
- putquick "privmsg ${chan} ${P_MSGERR}"
- return -code error ${P_LOGERR};
- }
- set P_Sql "SELECT `${::bonaPRE::db_(id)}`, `${::bonaPRE::db_(rlsname)}`, `${::bonaPRE::db_(section)}`, `${::bonaPRE::db_(datetime)}`, `${::bonaPRE::db_(files)}`, `${::bonaPRE::db_(size)}`";
- append P_Sql "FROM `${::bonaPRE::mysql_(dbmain)}` ";
- append P_Sql "WHERE `${::bonaPRE::db_(rlsname)}` LIKE '${P_Rlsname}%' ";
- append P_Sql "ORDER BY ${::bonaPRE::db_(datetime)} DESC LIMIT 1;";
- set P_Sqld [::mysql::sel ${::bonaPRE::mysql_(handle)} ${P_Sql} -flatlist];
- if { ${P_Sqld} != "" } {
- # (lassign) The SQL List separated into variables https://www.tcl.tk/man/tcl8.7/TclCmd/lassign.html
- lassign ${P_Sqld} P_Id P_Rls P_Section P_Datetime P_Files P_Size;
- # Calculate pretimes
- set now [clock seconds]
- set pretimestamp [clock scan $P_Datetime]
- set elapsed [expr {($now - $pretimestamp)}]
- set pretimestring [format_time $elapsed]
- set P_MSGOK1 [format "\0030\[\00314SEARCH\0030\]\002\0030 ${P_Rls} \002\0030\[\002\00314PRED\002\0030\]\002\0032\ ${pretimestring} \002\0030ago \0030\[\002\00314PRETiME\002\0030\]\002\0032 ${P_Datetime} \002\0030\[\002\00314${P_Section}\002\0030\]\002\0032\ ${P_Size} \002\0030\MB in\002\0032\ ${P_Files} \002\0030\Files"]
- putquick "privmsg ${chan} ${P_MSGOK1}"
- return false;
- } else {
- set P_MSGERR [format "\002\0033(\0037PRE\0033)\002\0037 ${P_Rlsname} \00315does not exist in the database."]
- putquick "privmsg ${chan} ${P_MSGERR}"
- return false;
- }
- }
- # Function to format time in a simplified human-readable format
- proc format_time {seconds} {
- set years [expr {$seconds / (365*24*3600)}]
- set seconds [expr {$seconds % (365*24*3600)}]
- set months [expr {$seconds / (30*24*3600)}]
- set seconds [expr {$seconds % (30*24*3600)}]
- set weeks [expr {$seconds / (7*24*3600)}]
- set seconds [expr {$seconds % (7*24*3600)}]
- set days [expr {$seconds / (24*3600)}]
- set seconds [expr {$seconds % (24*3600)}]
- set hours [expr {$seconds / 3600}]
- set seconds [expr {$seconds % 3600}]
- set minutes [expr {$seconds / 60}]
- set seconds [expr {$seconds % 60}]
- set result ""
- if {$years > 0} {
- append result "${years}y "
- }
- if {$months > 0} {
- append result "${months}m "
- }
- if {$weeks > 0} {
- append result "${weeks}w "
- }
- if {$days > 0} {
- append result "${days}d "
- }
- if {$hours > 0} {
- append result "${hours}h "
- }
- if {$minutes > 0} {
- append result "${minutes}m "
- }
- if {$seconds > 0} {
- append result "${seconds}s "
- }
- return [string trim $result]
- }
- package provide bonaPRE-PRE-PUBLiC 1.0
- putlog "Tcl load \[::${::bonaPRE::VAR(release)}::PRE\]: modTCL Loaded."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement