comparison weather.tcl @ 558:e0ff67318a99

weather: Rename some message ids, cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 Jul 2020 12:41:52 +0300
parents b6b92f64013c
children 15bc88a1477a
comparison
equal deleted inserted replaced
557:0ce432c3f03f 558:e0ff67318a99
23 # No need to look below this line 23 # No need to look below this line
24 ########################################################################## 24 ##########################################################################
25 package require textutil::split 25 package require textutil::split
26 26
27 set weather_name "Weather" 27 set weather_name "Weather"
28 set weather_version "2.0.0" 28 set weather_message "$weather_name v2.0.0 (C) 2014-2020 ccr/TNSP"
29 29
30 30
31 ### Initialization messages 31 #-------------------------------------------------------------------------
32 set weather_message "$weather_name v$weather_version (C) 2014-2020 ccr/TNSP" 32 ### Utility functions
33 putlog "$weather_message"
34
35
36 #-------------------------------------------------------------------------
37 proc weather_log {umsg} { 33 proc weather_log {umsg} {
38 global weather_log_enable weather_name 34 global weather_log_enable weather_name
39 if {$weather_log_enable != 0} { 35 if {$weather_log_enable != 0} {
40 putlog "$weather_name: $umsg" 36 putlog "$weather_name: $umsg"
41 } 37 }
291 # Check and handle arguments 287 # Check and handle arguments
292 set rarglist [::textutil::split::splitx $uargs {\s+}] 288 set rarglist [::textutil::split::splitx $uargs {\s+}]
293 set rcmd [lindex $rarglist 0] 289 set rcmd [lindex $rarglist 0]
294 290
295 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} { 291 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} {
296 foreach ukey $weather_messages(usage_full) { 292 foreach ukey $weather_messages(help_full) {
297 weather_msg $upublic $unick $uchan $ukey 293 weather_msg $upublic $unick $uchan $ukey
298 } 294 }
299 return 0 295 return 0
300 } 296 }
301 297
302 if {$rcmd == "asemat" || $rcmd == "stations"} { 298 if {$rcmd == "asemat" || $rcmd == "stations"} {
303 # List stations/locations matching the given pattern 299 # List stations/locations matching the given pattern
304 if {[llength $rarglist] < 2} { 300 if {[llength $rarglist] < 2} {
305 weather_msg $upublic $unick $uchan "usage_stations" 301 weather_msg $upublic $unick $uchan "help_stations"
306 return 0 302 return 0
307 } 303 }
308 304
309 set rmatch [join [lrange $rarglist 1 end] " "] 305 set rmatch [join [lrange $rarglist 1 end] " "]
310 set result {} 306 set result {}
329 return 0 325 return 0
330 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} { 326 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} {
331 # List stations nearest to given coordinates 327 # List stations nearest to given coordinates
332 set qargs [join [lrange $rarglist 1 end] ""] 328 set qargs [join [lrange $rarglist 1 end] ""]
333 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} { 329 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} {
334 weather_msg $upublic $unick $uchan "usage_nearest" 330 weather_msg $upublic $unick $uchan "help_nearest"
335 return 0 331 return 0
336 } 332 }
337 333
338 # Check argument types 334 # Check argument types
339 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} { 335 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} {
389 385
390 if {[llength $nlist] > 0} { 386 if {[llength $nlist] > 0} {
391 weather_msg $upublic $unick $uchan "def_set_to" [list [join $nlist " ; "]] 387 weather_msg $upublic $unick $uchan "def_set_to" [list [join $nlist " ; "]]
392 setuser $uhand XTRA "weather_locations" [join $nlist ";"] 388 setuser $uhand XTRA "weather_locations" [join $nlist ";"]
393 } else { 389 } else {
394 weather_msg $upublic $unick $uchan "usage_def_set" 390 weather_msg $upublic $unick $uchan "help_def_set"
395 } 391 }
396 } 392 }
397 return 0 393 return 0
398 } elseif {$rcmd == "alias"} { 394 } elseif {$rcmd == "alias"} {
399 # Alias a string to another, only certain users have access (+n flag) 395 # Alias a string to another, only certain users have access (+n flag)
403 } 399 }
404 400
405 set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*=\s*}] 401 set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*=\s*}]
406 set nlist [lsearch -all -inline -not -exact $qlist ""] 402 set nlist [lsearch -all -inline -not -exact $qlist ""]
407 if {[llength $nlist] < 2} { 403 if {[llength $nlist] < 2} {
408 weather_msg $upublic $unick $uchan "usage_alias" 404 weather_msg $upublic $unick $uchan "help_alias"
409 return 0 405 return 0
410 } 406 }
411 407
412 set ualias [lindex $nlist 0] 408 set ualias [lindex $nlist 0]
413 set uname [lindex $nlist 1] 409 set uname [lindex $nlist 1]
428 weather_msg $upublic $unick $uchan "no_access" 424 weather_msg $upublic $unick $uchan "no_access"
429 return 0 425 return 0
430 } 426 }
431 427
432 if {[llength $rarglist] < 2} { 428 if {[llength $rarglist] < 2} {
433 weather_msg $upublic $unick $uchan "usage_unalias" 429 weather_msg $upublic $unick $uchan "help_unalias"
434 return 0 430 return 0
435 } 431 }
436 432
437 set ualias [lindex $rarglist 1] 433 set ualias [lindex $rarglist 1]
438 434
537 533
538 534
539 #------------------------------------------------------------------------- 535 #-------------------------------------------------------------------------
540 # Script initialization 536 # Script initialization
541 #------------------------------------------------------------------------- 537 #-------------------------------------------------------------------------
538 putlog "$weather_message"
539
542 540
543 if {![info exists weather_data]} { 541 if {![info exists weather_data]} {
544 array set weather_data {} 542 array set weather_data {}
545 } 543 }
546 544