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