# HG changeset patch # User Matti Hamalainen # Date 1613835340 -7200 # Node ID 8bde8f798188bc0654aaa619fb72e7eb98890827 # Parent bb6aea76cdb49b37379d899ab6e35605aa1d4cf4 feeds: Use command matching helpers. diff -r bb6aea76cdb4 -r 8bde8f798188 config.feeds.example --- a/config.feeds.example Sat Feb 20 17:35:07 2021 +0200 +++ b/config.feeds.example Sat Feb 20 17:35:40 2021 +0200 @@ -45,6 +45,17 @@ } +# Sub-command name regexp patterns +array set feeds_commands { + "help" {^(\?|help|apua)$} + "latest" {^(last|latest|uusin?)$} + "force" {^(force?|fet|fetch)$} + "list" {^(list|listaa?)$} + "history" {^(hist|historia)$} + "all" {^(all|long|kaikki)$} +} + + # Proc for fetching the feeds data, called by fetch_feeds.tcl proc feeds_fetch { } { #fetch_poliisi "http://www.poliisi.fi/oulu/tiedotteet/1/0?all1/0" "Poliisi/Oulu" "http://www.poliisi.fi" diff -r bb6aea76cdb4 -r 8bde8f798188 feeds.tcl --- a/feeds.tcl Sat Feb 20 17:35:07 2021 +0200 +++ b/feeds.tcl Sat Feb 20 17:35:40 2021 +0200 @@ -65,6 +65,12 @@ } +proc feeds_cmd_match { uid ustr } { + global feeds_commands + return [utl_cmd_match feeds_commands $uid $ustr] +} + + # ------------------------------------------------------------------------ proc feeds_check_do {uforce upublic unick uchan} { global feeds_db_file feeds_dbh feeds_sync_limit feeds_channels @@ -165,14 +171,12 @@ set rcmd [lindex $rarglist 0] set rargs [lrange $rarglist 1 end] - if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} { + if {[feeds_cmd_match "help" $rcmd]} { + # Show help foreach ukey $feeds_messages(help_full) { feeds_msg $upublic $unick $uchan $ukey } - return 0 - } - - if {$rcmd == "last" || $rcmd == "latest" || $rcmd == "uusin"} { + } elseif {[feeds_cmd_match "latest" $rcmd]} { # Show latest entry or latest entry of specified feed set ufound 0 set utext [string tolower [join $rargs " "]] @@ -191,18 +195,18 @@ if {$ufound == 0} { feeds_msg $upublic $unick $uchan "search_no_matches" [list $utext] } - } elseif {[string match "forc*" $rcmd] || [string match "fet*" $rcmd]} { + } elseif {[feeds_cmd_match "force" $rcmd]} { # Force check for new entries if {![matchattr $uhand n]} { feeds_msg $upublic $unick $uchan "no_access" } feeds_check_do 1 $upublic $unick $uchan - } elseif {[string match "list*" $rcmd]} { + } elseif {[feeds_cmd_match "list" $rcmd]} { # List feeds set uarg [lindex $rargs 0] - if {$uarg == "all" || $uarg == "long" || $uarg == "kaikki"} { + if {[feeds_cmd_match "all" $uarg]} { # Long list set utext [string tolower [join [lrange $rargs 1 end] " "]] @@ -226,6 +230,7 @@ } else { feeds_msg $upublic $unick $uchan "feed_list_all" [list [join $ulist $ulistsep]] } + } elseif {$uarg != ""} { # List feeds with a name filter set utext [string tolower [join $rargs " "]] @@ -258,7 +263,7 @@ feeds_msg $upublic $unick $uchan "feed_list_active" [list [utl_ctime $uold] [join $ulist $ulistsep]] } - } elseif {[string match "hist*" $rcmd]} { + } elseif {[feeds_cmd_match "history" $rcmd]} { # Show history of a feed if {[llength $rarglist] < 2} { feeds_msg $upublic $unick $uchan "help_history" @@ -290,6 +295,8 @@ # Help/usage feeds_msg $upublic $unick $uchan "help_short" } + + return 0 }