Mercurial > hg > egg-tcls
comparison weather.tcl @ 600:90da5691cc81
weather: Use new command matching.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Feb 2021 12:16:32 +0200 |
parents | 7f7d8048ecb5 |
children | a09401d4ac8c |
comparison
equal
deleted
inserted
replaced
599:76d19fa28753 | 600:90da5691cc81 |
---|---|
289 global weather_data weather_msg_result | 289 global weather_data weather_msg_result |
290 return [weather_get_str $weather_data($ukey) $weather_msg_result] | 290 return [weather_get_str $weather_data($ukey) $weather_msg_result] |
291 } | 291 } |
292 | 292 |
293 | 293 |
294 proc weather_cmd_match { uid ustr } { | |
295 global weather_commands | |
296 return [utl_cmd_match weather_commands $uid $ustr] | |
297 } | |
298 | |
299 | |
294 #------------------------------------------------------------------------- | 300 #------------------------------------------------------------------------- |
295 proc weather_cmd {unick $uhost uhand uchan uargs upublic} { | 301 proc weather_cmd {unick $uhost uhand uchan uargs upublic} { |
296 global weather_default_locations weather_data weather_max_results weather_aliases | 302 global weather_default_locations weather_data weather_max_results weather_aliases |
297 global weather_msg_list_station weather_msg_result weather_messages | 303 global weather_msg_list_station weather_msg_result weather_messages |
298 | 304 |
299 # Check and handle arguments | 305 # Check and handle arguments |
300 set rarglist [::textutil::split::splitx $uargs {\s+}] | 306 set rarglist [::textutil::split::splitx $uargs {\s+}] |
301 set rcmd [lindex $rarglist 0] | 307 set rcmd [lindex $rarglist 0] |
302 | 308 |
303 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} { | 309 if {[weather_cmd_match "help" $rcmd]} { |
310 # Show help | |
304 foreach ukey $weather_messages(help_full) { | 311 foreach ukey $weather_messages(help_full) { |
305 weather_msg $upublic $unick $uchan $ukey | 312 weather_msg $upublic $unick $uchan $ukey |
306 } | 313 } |
307 return 1 | 314 return 1 |
308 } | 315 } elseif {[weather_cmd_match "stations" $rcmd]} { |
309 | |
310 if {$rcmd == "asemat" || $rcmd == "stations"} { | |
311 # List stations/locations matching the given pattern | 316 # List stations/locations matching the given pattern |
312 if {[llength $rarglist] < 2} { | 317 if {[llength $rarglist] < 2} { |
313 weather_msg $upublic $unick $uchan "help_stations" | 318 weather_msg $upublic $unick $uchan "help_stations" |
314 return 1 | 319 return 1 |
315 } | 320 } |
333 set res [weather_qm "stations_no_matches"] | 338 set res [weather_qm "stations_no_matches"] |
334 } | 339 } |
335 | 340 |
336 weather_msg $upublic $unick $uchan "stations_list" [list $res] | 341 weather_msg $upublic $unick $uchan "stations_list" [list $res] |
337 return 1 | 342 return 1 |
338 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} { | 343 } elseif {[weather_cmd_match "nearest" $rcmd]} { |
339 # List stations nearest to given coordinates | 344 # List stations nearest to given coordinates |
340 set qargs [join [lrange $rarglist 1 end] ""] | 345 set qargs [join [lrange $rarglist 1 end] ""] |
341 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} { | 346 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} { |
342 weather_msg $upublic $unick $uchan "help_nearest" | 347 weather_msg $upublic $unick $uchan "help_nearest" |
343 return 1 | 348 return 1 |
371 | 376 |
372 # Print out the result | 377 # Print out the result |
373 set res [join $uresult " ; "] | 378 set res [join $uresult " ; "] |
374 weather_msg $upublic $unick $uchan "nearest_stations" [list $d_lat $d_lng $res] | 379 weather_msg $upublic $unick $uchan "nearest_stations" [list $d_lat $d_lng $res] |
375 return 1 | 380 return 1 |
376 } elseif {$rcmd == "vakio" || $rcmd == "default" || $rcmd == "vakiot" || $rcmd == "defaults"} { | 381 } elseif {[weather_cmd_match "default" $rcmd]} { |
377 # List or set the default weather station name patterns for this user | 382 # List or set the default weather station name patterns for this user |
378 | 383 |
379 # Access check | 384 # Access check |
380 if {![utl_valid_user $uhand]} { | 385 if {![utl_valid_user $uhand]} { |
381 weather_msg $upublic $unick $uchan "user_not_known" | 386 weather_msg $upublic $unick $uchan "user_not_known" |
401 } else { | 406 } else { |
402 weather_msg $upublic $unick $uchan "help_def_set" | 407 weather_msg $upublic $unick $uchan "help_def_set" |
403 } | 408 } |
404 } | 409 } |
405 return 1 | 410 return 1 |
406 } elseif {$rcmd == "alias"} { | 411 } elseif {[weather_cmd_match "alias" $rcmd]} { |
407 # Alias a string to another, only certain users have access (+n flag) | 412 # Alias a string to another, only certain users have access (+n flag) |
408 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { | 413 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { |
409 weather_msg $upublic $unick $uchan "no_access" | 414 weather_msg $upublic $unick $uchan "no_access" |
410 return 1 | 415 return 1 |
411 } | 416 } |
428 | 433 |
429 set weather_aliases($ualias) $uname | 434 set weather_aliases($ualias) $uname |
430 | 435 |
431 weather_save_aliases | 436 weather_save_aliases |
432 return 1 | 437 return 1 |
433 } elseif {$rcmd == "unalias"} { | 438 } elseif {[weather_cmd_match "unalias" $rcmd]} { |
434 # Remove one alias, only certain users have access (+n flag) | 439 # Remove one alias, only certain users have access (+n flag) |
435 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { | 440 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { |
436 weather_msg $upublic $unick $uchan "no_access" | 441 weather_msg $upublic $unick $uchan "no_access" |
437 return 1 | 442 return 1 |
438 } | 443 } |
452 weather_msg $upublic $unick $uchan "alias_unset" [list $ualias $weather_aliases($ualias)] | 457 weather_msg $upublic $unick $uchan "alias_unset" [list $ualias $weather_aliases($ualias)] |
453 unset weather_aliases($ualias) | 458 unset weather_aliases($ualias) |
454 weather_save_aliases | 459 weather_save_aliases |
455 | 460 |
456 return 1 | 461 return 1 |
457 } elseif {$rcmd == "list"} { | 462 } elseif {[weather_cmd_match "list" $rcmd]} { |
458 # List all currently defined aliases | 463 # List all currently defined aliases |
459 set ulist {} | 464 set ulist {} |
460 set ulistitem [weather_qm "alias_item"] | 465 set ulistitem [weather_qm "alias_item"] |
461 set ulistsep [weather_qm "alias_list_sep"] | 466 set ulistsep [weather_qm "alias_list_sep"] |
462 | 467 |