Mercurial > hg > egg-tcls
annotate tj.tcl @ 108:d9de3870b72e
tj: Use append for better string manipulation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 14 Sep 2011 19:34:23 +0300 |
parents | 15fc72bc3f3e |
children | 42cf6a768c46 |
rev | line source |
---|---|
70 | 1 ########################################################################## |
0 | 2 # |
3 # TJ (Army Mornings Left-counter) v0.60 by ccr/TNSP | |
5
5ac4fd6d011a
tj: Handle command arguments better.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
4 # (C) Copyright 2000,2009,2011 Tecnic Software productions (TNSP) |
0 | 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 # | |
70 | 19 ########################################################################## |
0 | 20 |
21 # Default starting TJ | |
22 set tj_defstarttj 180 | |
23 | |
24 | |
25 | |
70 | 26 ########################################################################## |
0 | 27 # No need to look below this line |
70 | 28 ########################################################################## |
5
5ac4fd6d011a
tj: Handle command arguments better.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
29 set tj_message "TJ (SA-INT model) v0.65 by ccr/TNSP" |
0 | 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 | |
70 | 38 # ------------------------------------------------------------------------ |
0 | 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 | |
70 | 54 # ------------------------------------------------------------------------ |
0 | 55 proc tj_smsg {udest umsg} { |
56 global tj_preferredmsg | |
57 | |
58 putserv "$tj_preferredmsg $udest :$umsg" | |
59 } | |
60 | |
61 | |
70 | 62 # ------------------------------------------------------------------------ |
0 | 63 proc tj_pubmsg {nick uhost hand chan args} { |
5
5ac4fd6d011a
tj: Handle command arguments better.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
64 set args [string trim [join $args ""]] |
5ac4fd6d011a
tj: Handle command arguments better.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
65 if {$args == ""} { set args $hand } |
0 | 66 |
67 tj_smsg $chan [tj_gettj $args $chan] | |
68 return 1 | |
69 } | |
70 | |
71 | |
70 | 72 # ------------------------------------------------------------------------ |
0 | 73 proc tj_ctime { utime } { |
74 return [clock format $utime -format "%d.%m.%Y %H:%M"] | |
75 } | |
76 | |
77 | |
70 | 78 # ------------------------------------------------------------------------ |
0 | 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 | |
70 | 96 # ------------------------------------------------------------------------ |
0 | 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 | |
70 | 105 # ------------------------------------------------------------------------ |
0 | 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 | |
70 | 118 # ------------------------------------------------------------------------ |
0 | 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} { | |
108
d9de3870b72e
tj: Use append for better string manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
174 if {$aamut > 0} { append lause " ja " } |
d9de3870b72e
tj: Use append for better string manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
175 append lause "$tunnit tuntia" |
0 | 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 | |
70 | 194 # ------------------------------------------------------------------------ |