Advertisement
Bette

Untitled

Mar 22nd, 2024
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 3.88 KB | None | 0 0
  1. proc ::bonaPRE::pre:init { args } {
  2.     if { [catch { package require bonaPRE-SQL 1.0 }] } {
  3.         set AE_LOGERR  [format "${::bonaPRE::VAR(release)} modTCL * mysql.tcl file must be loaded before pre.tcl"]
  4.         return -code error ${AE_LOGERR};
  5.     }
  6. }
  7. ::bonaPRE::pre:init
  8.  
  9. bind pub -|- !pre ::bonaPRE::pre
  10.  
  11. proc ::bonaPRE::pre { nick uhost hand chan arg } {
  12.     set P_Rlsname [lindex ${arg} 0]
  13.     if { ![channel get ${chan} bpsearch] } {
  14.         set P_LOGERR   [format "User %s attempted a !pre on %s, but the channel does not have the necessary *flags*." ${nick} ${chan}]
  15.         #set P_MSGERR   [format "%s tried a !pre, but the channel does not have the necessary *flags*." ${nick}]
  16.         putquick "privmsg ${chan} ${P_MSGERR}"
  17.         return -code error ${P_LOGERR};
  18.     }
  19.     if { ${P_Rlsname} == "" } {
  20.         set P_LOGERR   [format "Syntax *%s attempted a !pre on %s, but lacks information..." ${nick} ${chan}]
  21.         set P_MSGERR   [format "Syntax * !pre <release.name>"]
  22.         putquick "privmsg ${chan} ${P_MSGERR}"
  23.         return -code error ${P_LOGERR};
  24.     }
  25.     set P_Sql          "SELECT `${::bonaPRE::db_(id)}`, `${::bonaPRE::db_(rlsname)}`, `${::bonaPRE::db_(section)}`, `${::bonaPRE::db_(datetime)}`, `${::bonaPRE::db_(files)}`, `${::bonaPRE::db_(size)}`";
  26.     append P_Sql       "FROM `${::bonaPRE::mysql_(dbmain)}` ";
  27.     append P_Sql       "WHERE `${::bonaPRE::db_(rlsname)}` LIKE '${P_Rlsname}%' ";
  28.     append P_Sql       "ORDER BY ${::bonaPRE::db_(datetime)} DESC LIMIT 1;";
  29.     set P_Sqld        [::mysql::sel ${::bonaPRE::mysql_(handle)} ${P_Sql} -flatlist];
  30.     if { ${P_Sqld} != "" } {
  31.         # (lassign) The SQL List separated into variables https://www.tcl.tk/man/tcl8.7/TclCmd/lassign.html
  32.         lassign  ${P_Sqld} P_Id P_Rls P_Section P_Datetime P_Files P_Size;
  33.  
  34.         # Calculate pretimes
  35.         set now [clock seconds]
  36.         set pretimestamp [clock scan $P_Datetime]
  37.         set elapsed [expr {($now - $pretimestamp)}]
  38.  
  39.         set pretimestring [format_time $elapsed]
  40.         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"]
  41.  
  42.         putquick "privmsg ${chan} ${P_MSGOK1}"
  43.         return false;
  44.     } else {
  45.         set P_MSGERR [format "\002\0033(\0037PRE\0033)\002\0037 ${P_Rlsname} \00315does not exist in the database."]
  46.         putquick "privmsg ${chan} ${P_MSGERR}"
  47.         return false;
  48.     }
  49. }
  50.  
  51. # Function to format time in a simplified human-readable format
  52. proc format_time {seconds} {
  53.     set years [expr {$seconds / (365*24*3600)}]
  54.     set seconds [expr {$seconds % (365*24*3600)}]
  55.  
  56.     set months [expr {$seconds / (30*24*3600)}]
  57.     set seconds [expr {$seconds % (30*24*3600)}]
  58.  
  59.     set weeks [expr {$seconds / (7*24*3600)}]
  60.     set seconds [expr {$seconds % (7*24*3600)}]
  61.  
  62.     set days [expr {$seconds / (24*3600)}]
  63.     set seconds [expr {$seconds % (24*3600)}]
  64.  
  65.     set hours [expr {$seconds / 3600}]
  66.     set seconds [expr {$seconds % 3600}]
  67.  
  68.     set minutes [expr {$seconds / 60}]
  69.     set seconds [expr {$seconds % 60}]
  70.  
  71.     set result ""
  72.     if {$years > 0} {
  73.         append result "${years}y "
  74.     }
  75.     if {$months > 0} {
  76.         append result "${months}m "
  77.     }
  78.     if {$weeks > 0} {
  79.         append result "${weeks}w "
  80.     }
  81.     if {$days > 0} {
  82.         append result "${days}d "
  83.     }
  84.     if {$hours > 0} {
  85.         append result "${hours}h "
  86.     }
  87.     if {$minutes > 0} {
  88.         append result "${minutes}m "
  89.     }
  90.     if {$seconds > 0} {
  91.         append result "${seconds}s "
  92.     }
  93.     return [string trim $result]
  94. }
  95.  
  96. package provide bonaPRE-PRE-PUBLiC 1.0
  97. putlog "Tcl load \[::${::bonaPRE::VAR(release)}::PRE\]: modTCL Loaded."
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement