Code: Select all
bind topc - * topic:topic_change
bind pub o|o whotopic pub:topicby
proc topic:topic_change {nick uhost hand chan topic} {
global topcnick topctime
set chan [string tolower $chan]
if {![info exists topcnick($chan)]} {
set topcnick($chan) ""
}
if {$nick != "*"} {
set topcnick($chan) $nick
set topctime($chan) [unixtime]
}
}
proc pub:topicby {nick uhost hand chan arg} {
global topcnick topctime
set chan [string tolower $chan]
putcmdlog "<<$nick/$chan>> $hand requested whotopic for $chan"
if {$topcnick($chan) != ""} {
set time [expr [unixtime] - $topctime($chan)]
set years 0
set days 0
set hours 0
set mins 0
if {$time < 60} {
return "< 1 min"
}
if {$time >= 31536000} {
set years [expr int([expr $time/31536000])]
set time [expr $time - [expr 31536000*$years]]
}
if {$time >= 86400} {
set days [expr int([expr $time/86400])]
set time [expr $time - [expr 86400*$days]]
}
if {$time >= 3600} {
set hours [expr int([expr $time/3600])]
set time [expr $time - [expr 3600*$hours]]
}
if {$time >= 60} {
set mins [expr int([expr $time/60])]
}
if {$years == 0} {
set output ""
} elseif {$years == 1} {
set output "1 year,"
} else {
set output "$years years,"
}
if {$days == 1} {
lappend output "1 day,"
} elseif {$days > 1} {
lappend output "$days days,"
}
if {$hours == 1} {
lappend output "1 hour,"
} elseif {$hours > 1} {
lappend output "$hours hours,"
}
if {$mins == 1} {
lappend output "1 minute"
} elseif {$mins > 1} {
lappend output "$mins minutes"
}
set timeago [string trimright [join $output] ", "]
if {$topcnick($chan) == "*"} {
puthelp "privmsg $chan :The topic was already set when i joined this channel $timeago ago."
} else {
puthelp "privmsg $chan :The topic was set by: $topcnick($chan) $timeago ago."
}
} else {
puthelp "privmsg $chan :I didn't see the topic being changed."
}
}