comparison tj.tcl @ 0:1c4e2814cd41

Initial import.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Sep 2010 13:12:49 +0300
parents
children 5ac4fd6d011a
comparison
equal deleted inserted replaced
-1:000000000000 0:1c4e2814cd41
1 ############################################################################
2 #
3 # TJ (Army Mornings Left-counter) v0.60 by ccr/TNSP
4 # (C) Copyright 2000,2009 Tecnic Software productions (TNSP)
5 # Send comments and shit via e-mail: <ccr@tnsp.org>
6 #
7 # This script is freely distributable under GNU GPL (version 2) license.
8 #
9 # Laskee aamuja tiettyyn paivamaaraan. TJ-paivamaara annettava
10 # tietenkin etta toimii, oletuksena skripti asettaa (uudelle kayttajalle)
11 # sen hetkisen ajan + 180 aamua. Esimerkkeja kaytosta:
12 # !tj [nick]
13 # /msg TheBot tj [nick]
14 #
15 # Ja TJ:n asetus toimii nain:
16 # !tjaamut <[-]aamujen lkm tasta hetkesta laskien> [+/- tunnit]
17 # !tjset dd.mm.yyyy hh:mm
18 #
19 ############################################################################
20
21 # Default starting TJ
22 set tj_defstarttj 180
23
24
25
26 ############################################################################
27 # No need to look below this line
28 ############################################################################
29 set tj_message "TJ (SA-INT model) v0.60 by ccr/TNSP"
30 set tj_dateident "tjdate"
31 set tj_preferredmsg "PRIVMSG"
32
33 putlog "$tj_message"
34 bind pub - !tj tj_pubmsg
35 bind pub - !tjaamut tj_pubaamut
36 bind pub - !tjset tj_pubset
37
38 # -------------------------------------------------------------------------
39 proc tj_correctnickcase { jnick } {
40
41 if {![validuser $jnick]} { return "" }
42 set nicklwr [string tolower $jnick]
43 foreach juser [userlist] {
44 if {[string tolower $juser] == $nicklwr} {
45 unset nicklwr
46 return "$juser"
47 }
48 }
49
50 return ""
51 }
52
53
54 # -------------------------------------------------------------------------
55 proc tj_smsg {udest umsg} {
56 global tj_preferredmsg
57
58 putserv "$tj_preferredmsg $udest :$umsg"
59 }
60
61
62 # -------------------------------------------------------------------------
63 proc tj_pubmsg {nick uhost hand chan args} {
64 if {$args == "{}" || $args == ""} { set args $hand }
65 set args [lindex [split $args " "] 0]
66
67 tj_smsg $chan [tj_gettj $args $chan]
68 return 1
69 }
70
71
72 # -------------------------------------------------------------------------
73 proc tj_ctime { utime } {
74 return [clock format $utime -format "%d.%m.%Y %H:%M"]
75 }
76
77
78 # -------------------------------------------------------------------------
79 proc tj_pubaamut {unick uhost uhand uchan uargs} {
80 set foo [split $uargs " "]
81 set tjdays [lindex $foo 0]
82 set tjhours [lindex $foo 1]
83 if {$tjdays == ""} {
84 tj_smsg $uchan "Hälärm."
85 return 1
86 }
87
88 if {$tjhours == ""} { set tjhours 0 }
89
90 set udate [expr [unixtime] + ($tjdays * 86400) + ($tjhours * 3600)]
91 tj_smsg $uchan [tj_settj $uhand $unick $udate]
92 return 1
93 }
94
95
96 # -------------------------------------------------------------------------
97 proc tj_pubset {unick uhost uhand uchan uargs} {
98
99 set udate [clock scan $uargs -format "%d.%N.%Y %H:%M"]
100 tj_smsg $uchan [tj_settj $uhand $unick $udate]
101 return 1
102 }
103
104
105 # -------------------------------------------------------------------------
106 proc tj_settj { uuser unick udate } {
107 global tj_dateident
108
109 if {![validuser $uuser]} {
110 return "Tuntematon käyttäjä $uuser."
111 }
112
113 setuser $uuser XTRA $tj_dateident $udate
114 return "$unick:n ($uuser) TJ asetettu. ([tj_ctime $udate])"
115 }
116
117
118 # -------------------------------------------------------------------------
119 proc tj_gettj {ihandle ichan} {
120 global tj_defstarttj
121 global tj_dateident
122
123 # Tarkistetaan onko kayttaja OK
124 if {![validuser $ihandle]} {
125 if {$ichan == ""} {
126 return "$ihandle, Mene pois."
127 } else {
128 if {$ihandle == "*"} {
129 return "En tiedä kuka olet, mene pois."
130 } else {
131 return "En tiedä kuka $ihandle on."
132 }
133 }
134 }
135
136 set chandle [tj_correctnickcase $ihandle]
137
138 # Haetaan TJ aloitus paivamaara
139 set tjpaiva [getuser $chandle XTRA $tj_dateident]
140
141 if {$tjpaiva == ""} {
142 return "$chandle ei ole asettanut itselleen TJ päivämäärää."
143 }
144
145 # Lasketaan tamanhetkinen TJ aika
146 set deltatj [expr $tjpaiva - [unixtime]]
147
148 if {$deltatj < 0} {
149 set tmp [expr [unixtime] - $tjpaiva]
150 } else {
151 set tmp $deltatj
152 }
153
154 # Lasketaan TJ aamut, tunnit jne
155 set aamut [expr ($tmp / 86400)]
156 set tunnit [expr (($tmp % 86400) / 3600)]
157
158 # Maaritetaan sanalause
159 if {$ichan != ""} {
160 set tjmt "$chandle:lla on"
161 set tjmi "$chandle on"
162 } else {
163 set tjmt "Sinulla on"
164 set tjmi "Sinä olet"
165 }
166
167 if {$aamut > 0} {
168 set lause "$aamut aamua"
169 } else {
170 set lause ""
171 }
172
173 if {$tunnit > 0} {
174 if {$aamut > 0} { set lause "$lause ja" }
175 set lause "$lause $tunnit tuntia"
176 }
177
178 if {$aamut == 0 && $deltatj > 0} {
179 if {$tunnit == 0} {
180 return "$tjmt TOSI WÄINÖ! TJ 0!!"
181 } else {
182 return "$tjmt AIKA WÄBÄ -- TJ $tunnit tuntia!"
183 }
184 } else {
185 if {$deltatj > 0} {
186 return "$tjmt $lause jäljellä... ([tj_ctime $tjpaiva])"
187 } else {
188 return "$tjmi ollut reservissä jo $lause! ([tj_ctime $tjpaiva])"
189 }
190 }
191
192 }
193
194 # -------------------------------------------------------------------------