Mercurial > hg > egg-tcls
comparison weather.tcl @ 588:dae8f6ad12c2
weather: Fix weather_cmd return values.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 27 Jan 2021 10:24:59 +0200 |
parents | 03d3ec856e4d |
children | b07ff5123baf |
comparison
equal
deleted
inserted
replaced
587:03d3ec856e4d | 588:dae8f6ad12c2 |
---|---|
303 | 303 |
304 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} { | 304 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} { |
305 foreach ukey $weather_messages(help_full) { | 305 foreach ukey $weather_messages(help_full) { |
306 weather_msg $upublic $unick $uchan $ukey | 306 weather_msg $upublic $unick $uchan $ukey |
307 } | 307 } |
308 return 0 | 308 return 1 |
309 } | 309 } |
310 | 310 |
311 if {$rcmd == "asemat" || $rcmd == "stations"} { | 311 if {$rcmd == "asemat" || $rcmd == "stations"} { |
312 # List stations/locations matching the given pattern | 312 # List stations/locations matching the given pattern |
313 if {[llength $rarglist] < 2} { | 313 if {[llength $rarglist] < 2} { |
314 weather_msg $upublic $unick $uchan "help_stations" | 314 weather_msg $upublic $unick $uchan "help_stations" |
315 return 0 | 315 return 1 |
316 } | 316 } |
317 | 317 |
318 set rmatch [join [lrange $rarglist 1 end] " "] | 318 set rmatch [join [lrange $rarglist 1 end] " "] |
319 set result {} | 319 set result {} |
320 | 320 |
333 } else { | 333 } else { |
334 set res [weather_qm "stations_no_matches"] | 334 set res [weather_qm "stations_no_matches"] |
335 } | 335 } |
336 | 336 |
337 weather_msg $upublic $unick $uchan "stations_list" [list $res] | 337 weather_msg $upublic $unick $uchan "stations_list" [list $res] |
338 return 0 | 338 return 1 |
339 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} { | 339 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} { |
340 # List stations nearest to given coordinates | 340 # List stations nearest to given coordinates |
341 set qargs [join [lrange $rarglist 1 end] ""] | 341 set qargs [join [lrange $rarglist 1 end] ""] |
342 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} { | 342 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} { |
343 weather_msg $upublic $unick $uchan "help_nearest" | 343 weather_msg $upublic $unick $uchan "help_nearest" |
344 return 0 | 344 return 1 |
345 } | 345 } |
346 | 346 |
347 # Check argument types | 347 # Check argument types |
348 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} { | 348 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} { |
349 weather_msg $upublic $unick $uchan "nearest_invalid" | 349 weather_msg $upublic $unick $uchan "nearest_invalid" |
350 return 0 | 350 return 1 |
351 } | 351 } |
352 | 352 |
353 # Calculate distances between given coordinates for each location | 353 # Calculate distances between given coordinates for each location |
354 set result {} | 354 set result {} |
355 foreach {ukey uvalue} [array get weather_data] { | 355 foreach {ukey uvalue} [array get weather_data] { |
371 } | 371 } |
372 | 372 |
373 # Print out the result | 373 # Print out the result |
374 set res [join $uresult " ; "] | 374 set res [join $uresult " ; "] |
375 weather_msg $upublic $unick $uchan "nearest_stations" [list $d_lat $d_lng $res] | 375 weather_msg $upublic $unick $uchan "nearest_stations" [list $d_lat $d_lng $res] |
376 return 0 | 376 return 1 |
377 } elseif {$rcmd == "vakio" || $rcmd == "default" || $rcmd == "vakiot" || $rcmd == "defaults"} { | 377 } elseif {$rcmd == "vakio" || $rcmd == "default" || $rcmd == "vakiot" || $rcmd == "defaults"} { |
378 # List or set the default weather station name patterns for this user | 378 # List or set the default weather station name patterns for this user |
379 | 379 |
380 # Access check | 380 # Access check |
381 if {![utl_valid_user $uhand]} { | 381 if {![utl_valid_user $uhand]} { |
382 weather_msg $upublic $unick $uchan "user_not_known" | 382 weather_msg $upublic $unick $uchan "user_not_known" |
383 return 0 | 383 return 1 |
384 } | 384 } |
385 | 385 |
386 if {[llength $rarglist] == 1} { | 386 if {[llength $rarglist] == 1} { |
387 set lista [getuser $uhand XTRA "weather_locations"] | 387 set lista [getuser $uhand XTRA "weather_locations"] |
388 if {$lista == "" || $lista == "{}"} { | 388 if {$lista == "" || $lista == "{}"} { |
401 setuser $uhand XTRA "weather_locations" [join $nlist ";"] | 401 setuser $uhand XTRA "weather_locations" [join $nlist ";"] |
402 } else { | 402 } else { |
403 weather_msg $upublic $unick $uchan "help_def_set" | 403 weather_msg $upublic $unick $uchan "help_def_set" |
404 } | 404 } |
405 } | 405 } |
406 return 0 | 406 return 1 |
407 } elseif {$rcmd == "alias"} { | 407 } elseif {$rcmd == "alias"} { |
408 # Alias a string to another, only certain users have access (+n flag) | 408 # Alias a string to another, only certain users have access (+n flag) |
409 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { | 409 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { |
410 weather_msg $upublic $unick $uchan "no_access" | 410 weather_msg $upublic $unick $uchan "no_access" |
411 return 0 | 411 return 1 |
412 } | 412 } |
413 | 413 |
414 set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*=\s*}] | 414 set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*=\s*}] |
415 set nlist [lsearch -all -inline -not -exact $qlist ""] | 415 set nlist [lsearch -all -inline -not -exact $qlist ""] |
416 if {[llength $nlist] < 2} { | 416 if {[llength $nlist] < 2} { |
417 weather_msg $upublic $unick $uchan "help_alias" | 417 weather_msg $upublic $unick $uchan "help_alias" |
418 return 0 | 418 return 1 |
419 } | 419 } |
420 | 420 |
421 set ualias [lindex $nlist 0] | 421 set ualias [lindex $nlist 0] |
422 set uname [lindex $nlist 1] | 422 set uname [lindex $nlist 1] |
423 | 423 |
428 } | 428 } |
429 | 429 |
430 set weather_aliases($ualias) $uname | 430 set weather_aliases($ualias) $uname |
431 | 431 |
432 weather_save_aliases | 432 weather_save_aliases |
433 return 0 | 433 return 1 |
434 } elseif {$rcmd == "unalias"} { | 434 } elseif {$rcmd == "unalias"} { |
435 # Remove one alias, only certain users have access (+n flag) | 435 # Remove one alias, only certain users have access (+n flag) |
436 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { | 436 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { |
437 weather_msg $upublic $unick $uchan "no_access" | 437 weather_msg $upublic $unick $uchan "no_access" |
438 return 0 | 438 return 1 |
439 } | 439 } |
440 | 440 |
441 if {[llength $rarglist] < 2} { | 441 if {[llength $rarglist] < 2} { |
442 weather_msg $upublic $unick $uchan "help_unalias" | 442 weather_msg $upublic $unick $uchan "help_unalias" |
443 return 0 | 443 return 1 |
444 } | 444 } |
445 | 445 |
446 set ualias [lindex $rarglist 1] | 446 set ualias [lindex $rarglist 1] |
447 | 447 |
448 if {![info exists weather_aliases($ualias)]} { | 448 if {![info exists weather_aliases($ualias)]} { |
449 weather_msg $upublic $unick $uchan "alias_not_exist" [list $ualias] | 449 weather_msg $upublic $unick $uchan "alias_not_exist" [list $ualias] |
450 return 0 | 450 return 1 |
451 } | 451 } |
452 | 452 |
453 weather_msg $upublic $unick $uchan "alias_unset" [list $ualias $weather_aliases($ualias)] | 453 weather_msg $upublic $unick $uchan "alias_unset" [list $ualias $weather_aliases($ualias)] |
454 unset weather_aliases($ualias) | 454 unset weather_aliases($ualias) |
455 weather_save_aliases | 455 weather_save_aliases |
456 | 456 |
457 return 0 | 457 return 1 |
458 } elseif {$rcmd == "list"} { | 458 } elseif {$rcmd == "list"} { |
459 # List all currently defined aliases | 459 # List all currently defined aliases |
460 set ulist {} | 460 set ulist {} |
461 set ulistitem [weather_qm "alias_item"] | 461 set ulistitem [weather_qm "alias_item"] |
462 set ulistsep [weather_qm "alias_list_sep"] | 462 set ulistsep [weather_qm "alias_list_sep"] |
464 foreach {ukey uvalue} [array get weather_aliases] { | 464 foreach {ukey uvalue} [array get weather_aliases] { |
465 lappend ulist [utl_str_map_values $ulistitem [list $ukey $uvalue]] | 465 lappend ulist [utl_str_map_values $ulistitem [list $ukey $uvalue]] |
466 } | 466 } |
467 | 467 |
468 weather_msg $upublic $unick $uchan "alias_list" [list [join $ulist $ulistsep]] | 468 weather_msg $upublic $unick $uchan "alias_list" [list [join $ulist $ulistsep]] |
469 return 0 | 469 return 1 |
470 } | 470 } |
471 | 471 |
472 # Get args or default location(s) | 472 # Get args or default location(s) |
473 set rargs [join $rarglist " "] | 473 set rargs [join $rarglist " "] |
474 if {$rargs == "" && $uhand != "" && $uhand != "{}" && $uhand != "*"} { | 474 if {$rargs == "" && $uhand != "" && $uhand != "{}" && $uhand != "*"} { |
509 incr ufound | 509 incr ufound |
510 } | 510 } |
511 | 511 |
512 # Check for results limit | 512 # Check for results limit |
513 if {$nresults >= $weather_max_results} { | 513 if {$nresults >= $weather_max_results} { |
514 return 0 | 514 return 1 |
515 } | 515 } |
516 } | 516 } |
517 | 517 |
518 if {$ufound == 0} { | 518 if {$ufound == 0} { |
519 weather_msg $upublic $unick $uchan "no_data_for_location" [list $rarg] | 519 weather_msg $upublic $unick $uchan "no_data_for_location" [list $rarg] |
520 } | 520 } |
521 } | 521 } |
522 | 522 |
523 # Check for results limit | 523 # Check for results limit |
524 if {$nresults >= $weather_max_results} { | 524 if {$nresults >= $weather_max_results} { |
525 return 0 | 525 return 1 |
526 } | 526 } |
527 } | 527 } |
528 return 0 | 528 return 1 |
529 } | 529 } |
530 | 530 |
531 | 531 |
532 #------------------------------------------------------------------------- | 532 #------------------------------------------------------------------------- |
533 proc weather_cmd_pub {unick uhost uhand uchan uargs} { | 533 proc weather_cmd_pub {unick uhost uhand uchan uargs} { |