Mercurial > hg > egg-tcls
diff tj.tcl @ 0:1c4e2814cd41
Initial import.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Sep 2010 13:12:49 +0300 |
parents | |
children | 5ac4fd6d011a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tj.tcl Tue Sep 21 13:12:49 2010 +0300 @@ -0,0 +1,194 @@ +############################################################################ +# +# TJ (Army Mornings Left-counter) v0.60 by ccr/TNSP +# (C) Copyright 2000,2009 Tecnic Software productions (TNSP) +# Send comments and shit via e-mail: <ccr@tnsp.org> +# +# This script is freely distributable under GNU GPL (version 2) license. +# +# Laskee aamuja tiettyyn paivamaaraan. TJ-paivamaara annettava +# tietenkin etta toimii, oletuksena skripti asettaa (uudelle kayttajalle) +# sen hetkisen ajan + 180 aamua. Esimerkkeja kaytosta: +# !tj [nick] +# /msg TheBot tj [nick] +# +# Ja TJ:n asetus toimii nain: +# !tjaamut <[-]aamujen lkm tasta hetkesta laskien> [+/- tunnit] +# !tjset dd.mm.yyyy hh:mm +# +############################################################################ + +# Default starting TJ +set tj_defstarttj 180 + + + +############################################################################ +# No need to look below this line +############################################################################ +set tj_message "TJ (SA-INT model) v0.60 by ccr/TNSP" +set tj_dateident "tjdate" +set tj_preferredmsg "PRIVMSG" + +putlog "$tj_message" +bind pub - !tj tj_pubmsg +bind pub - !tjaamut tj_pubaamut +bind pub - !tjset tj_pubset + +# ------------------------------------------------------------------------- +proc tj_correctnickcase { jnick } { + + if {![validuser $jnick]} { return "" } + set nicklwr [string tolower $jnick] + foreach juser [userlist] { + if {[string tolower $juser] == $nicklwr} { + unset nicklwr + return "$juser" + } + } + + return "" +} + + +# ------------------------------------------------------------------------- +proc tj_smsg {udest umsg} { + global tj_preferredmsg + + putserv "$tj_preferredmsg $udest :$umsg" +} + + +# ------------------------------------------------------------------------- +proc tj_pubmsg {nick uhost hand chan args} { + if {$args == "{}" || $args == ""} { set args $hand } + set args [lindex [split $args " "] 0] + + tj_smsg $chan [tj_gettj $args $chan] + return 1 +} + + +# ------------------------------------------------------------------------- +proc tj_ctime { utime } { + return [clock format $utime -format "%d.%m.%Y %H:%M"] +} + + +# ------------------------------------------------------------------------- +proc tj_pubaamut {unick uhost uhand uchan uargs} { + set foo [split $uargs " "] + set tjdays [lindex $foo 0] + set tjhours [lindex $foo 1] + if {$tjdays == ""} { + tj_smsg $uchan "Hälärm." + return 1 + } + + if {$tjhours == ""} { set tjhours 0 } + + set udate [expr [unixtime] + ($tjdays * 86400) + ($tjhours * 3600)] + tj_smsg $uchan [tj_settj $uhand $unick $udate] + return 1 +} + + +# ------------------------------------------------------------------------- +proc tj_pubset {unick uhost uhand uchan uargs} { + + set udate [clock scan $uargs -format "%d.%N.%Y %H:%M"] + tj_smsg $uchan [tj_settj $uhand $unick $udate] + return 1 +} + + +# ------------------------------------------------------------------------- +proc tj_settj { uuser unick udate } { + global tj_dateident + + if {![validuser $uuser]} { + return "Tuntematon käyttäjä $uuser." + } + + setuser $uuser XTRA $tj_dateident $udate + return "$unick:n ($uuser) TJ asetettu. ([tj_ctime $udate])" +} + + +# ------------------------------------------------------------------------- +proc tj_gettj {ihandle ichan} { + global tj_defstarttj + global tj_dateident + + # Tarkistetaan onko kayttaja OK + if {![validuser $ihandle]} { + if {$ichan == ""} { + return "$ihandle, Mene pois." + } else { + if {$ihandle == "*"} { + return "En tiedä kuka olet, mene pois." + } else { + return "En tiedä kuka $ihandle on." + } + } + } + + set chandle [tj_correctnickcase $ihandle] + + # Haetaan TJ aloitus paivamaara + set tjpaiva [getuser $chandle XTRA $tj_dateident] + + if {$tjpaiva == ""} { + return "$chandle ei ole asettanut itselleen TJ päivämäärää." + } + + # Lasketaan tamanhetkinen TJ aika + set deltatj [expr $tjpaiva - [unixtime]] + + if {$deltatj < 0} { + set tmp [expr [unixtime] - $tjpaiva] + } else { + set tmp $deltatj + } + + # Lasketaan TJ aamut, tunnit jne + set aamut [expr ($tmp / 86400)] + set tunnit [expr (($tmp % 86400) / 3600)] + + # Maaritetaan sanalause + if {$ichan != ""} { + set tjmt "$chandle:lla on" + set tjmi "$chandle on" + } else { + set tjmt "Sinulla on" + set tjmi "Sinä olet" + } + + if {$aamut > 0} { + set lause "$aamut aamua" + } else { + set lause "" + } + + if {$tunnit > 0} { + if {$aamut > 0} { set lause "$lause ja" } + set lause "$lause $tunnit tuntia" + } + + if {$aamut == 0 && $deltatj > 0} { + if {$tunnit == 0} { + return "$tjmt TOSI WÄINÖ! TJ 0!!" + } else { + return "$tjmt AIKA WÄBÄ -- TJ $tunnit tuntia!" + } + } else { + if {$deltatj > 0} { + return "$tjmt $lause jäljellä... ([tj_ctime $tjpaiva])" + } else { + return "$tjmi ollut reservissä jo $lause! ([tj_ctime $tjpaiva])" + } + } + +} + +# -------------------------------------------------------------------------