All pastes #223668 Raw Edit

Untitled

public text v1 · immutable
#223668 ·published 2006-10-27 01:06 UTC
rendered paste body
loadmodule mysql

bind pubm - * latest

proc putnow { a } {
  append a "\n"
  putdccraw 0 [string length $a] $a
}

proc size { size } {
if [expr $size >= 1073741824] { 
set size "[expr round(($size / 1073741824.) * 100) / 100.]" 
if {[lindex [split $size "."] 1] == 0} { set size [expr round($size)] }
set size "[expr $size]GB"
} elseif [expr $size >= 1048576] { 
set size "[expr round(($size / 1048576.) * 100) / 100.]" 
if {[lindex [split $size "."] 1] == 0} { set size [expr round($size)] }
set size "[expr $size]MB"
} elseif [expr $size >= 1024] { 
set size "[expr round($size/ 1024.)]" 
if {[lindex [split $size "."] 1] == 0} { set size [expr round($size)] }
set size "[expr $size]KB"
} else { set size "[expr $size]B" }
return $size
}


proc latest {nick uhost handle chan args} {
set args [join $args]

mysql_connect 

if {[lindex $args 0] == "!new"} {
set limit [lindex $args 1]
putlog $limit

if {[lindex $args 1] == "symbian" || [lindex $args 1] == "ppc" || [lindex $args 1] == "palm" || [lindex $args 1] == "psp" || [lindex $args 1] == "misc"} {
if {[lindex $args 2] > 0 && [lindex $args 2] <= 15} { set limit [expr [lindex $args 2]] } elseif { [lindex $args 2] == "" } { set limit 5 } else { 
putnow "notice $nick :4,1Error:15 You must specify a limit between 1-15. For complete listings, visit 14http://pdaDB.info"
mysql_close
return }

if {[lindex $args 2] != ""} { set top "4\[15 Showing Last $limit 4\"[lindex $args 1]\" 4| 14http://pdaDB.info 4\]" } else {
set top "4\[15 Showing Last 5 4\"[lindex $args 1]\" 4| 14!new \[category\] \[limit\] 4| 4http://pdaDB.info 4\]" }

set query "select * from `mediaplace` where `category` = '[lindex $args 1]' ORDER BY `date` DESC,`id` DESC LIMIT 0,$limit"

mysql_ping
set answer [mysql_query $query ]
if {[mysql_affected_rows] == 0} { 
putnow "NOTICE $nick :4Error:15 0 Results Found"
mysql_close
return }

putnow "notice $nick :$top"
for {set i 0} {[lindex $answer $i] != ""} { incr i } {
set filename [lindex [lindex $answer $i] 1]
set size [size [lindex [lindex $answer $i] 4]]
set date [lindex [lindex $answer $i] 3]
set date "[lindex [split $date "-"] 2]/[lindex [split $date "-"] 1]"
putnow "NOTICE $nick :04,01[expr $i + 1]. 4\[15 $filename 4\] 4\[14 $size 4|14 $date 4\]"

}
}
}

mysql_close

}