comparison feeds.tcl @ 663:8bde8f798188

feeds: Use command matching helpers.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 20 Feb 2021 17:35:40 +0200
parents bb6aea76cdb4
children 79b5d8944eea
comparison
equal deleted inserted replaced
662:bb6aea76cdb4 663:8bde8f798188
60 } 60 }
61 61
62 62
63 proc feeds_msg {apublic anick achan aid {aargs {}}} { 63 proc feeds_msg {apublic anick achan aid {aargs {}}} {
64 feeds_smsg $apublic $anick $achan [feeds_qm $aid] $aargs 64 feeds_smsg $apublic $anick $achan [feeds_qm $aid] $aargs
65 }
66
67
68 proc feeds_cmd_match { uid ustr } {
69 global feeds_commands
70 return [utl_cmd_match feeds_commands $uid $ustr]
65 } 71 }
66 72
67 73
68 # ------------------------------------------------------------------------ 74 # ------------------------------------------------------------------------
69 proc feeds_check_do {uforce upublic unick uchan} { 75 proc feeds_check_do {uforce upublic unick uchan} {
163 # Check and handle arguments 169 # Check and handle arguments
164 set rarglist [::textutil::split::splitx $uargs {\s+}] 170 set rarglist [::textutil::split::splitx $uargs {\s+}]
165 set rcmd [lindex $rarglist 0] 171 set rcmd [lindex $rarglist 0]
166 set rargs [lrange $rarglist 1 end] 172 set rargs [lrange $rarglist 1 end]
167 173
168 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} { 174 if {[feeds_cmd_match "help" $rcmd]} {
175 # Show help
169 foreach ukey $feeds_messages(help_full) { 176 foreach ukey $feeds_messages(help_full) {
170 feeds_msg $upublic $unick $uchan $ukey 177 feeds_msg $upublic $unick $uchan $ukey
171 } 178 }
172 return 0 179 } elseif {[feeds_cmd_match "latest" $rcmd]} {
173 }
174
175 if {$rcmd == "last" || $rcmd == "latest" || $rcmd == "uusin"} {
176 # Show latest entry or latest entry of specified feed 180 # Show latest entry or latest entry of specified feed
177 set ufound 0 181 set ufound 0
178 set utext [string tolower [join $rargs " "]] 182 set utext [string tolower [join $rargs " "]]
179 183
180 # Validate feed name 184 # Validate feed name
189 } 193 }
190 194
191 if {$ufound == 0} { 195 if {$ufound == 0} {
192 feeds_msg $upublic $unick $uchan "search_no_matches" [list $utext] 196 feeds_msg $upublic $unick $uchan "search_no_matches" [list $utext]
193 } 197 }
194 } elseif {[string match "forc*" $rcmd] || [string match "fet*" $rcmd]} { 198 } elseif {[feeds_cmd_match "force" $rcmd]} {
195 # Force check for new entries 199 # Force check for new entries
196 if {![matchattr $uhand n]} { 200 if {![matchattr $uhand n]} {
197 feeds_msg $upublic $unick $uchan "no_access" 201 feeds_msg $upublic $unick $uchan "no_access"
198 } 202 }
199 203
200 feeds_check_do 1 $upublic $unick $uchan 204 feeds_check_do 1 $upublic $unick $uchan
201 } elseif {[string match "list*" $rcmd]} { 205 } elseif {[feeds_cmd_match "list" $rcmd]} {
202 # List feeds 206 # List feeds
203 set uarg [lindex $rargs 0] 207 set uarg [lindex $rargs 0]
204 208
205 if {$uarg == "all" || $uarg == "long" || $uarg == "kaikki"} { 209 if {[feeds_cmd_match "all" $uarg]} {
206 # Long list 210 # Long list
207 set utext [string tolower [join [lrange $rargs 1 end] " "]] 211 set utext [string tolower [join [lrange $rargs 1 end] " "]]
208 212
209 if {$upublic && ![matchattr $uhand n]} { 213 if {$upublic && ![matchattr $uhand n]} {
210 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] 214 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext]
224 if {$utext != ""} { 228 if {$utext != ""} {
225 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]] 229 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]]
226 } else { 230 } else {
227 feeds_msg $upublic $unick $uchan "feed_list_all" [list [join $ulist $ulistsep]] 231 feeds_msg $upublic $unick $uchan "feed_list_all" [list [join $ulist $ulistsep]]
228 } 232 }
233
229 } elseif {$uarg != ""} { 234 } elseif {$uarg != ""} {
230 # List feeds with a name filter 235 # List feeds with a name filter
231 set utext [string tolower [join $rargs " "]] 236 set utext [string tolower [join $rargs " "]]
232 237
233 set ulistitem [feeds_qm "feed_list_item_short"] 238 set ulistitem [feeds_qm "feed_list_item_short"]
256 } 261 }
257 262
258 feeds_msg $upublic $unick $uchan "feed_list_active" [list [utl_ctime $uold] [join $ulist $ulistsep]] 263 feeds_msg $upublic $unick $uchan "feed_list_active" [list [utl_ctime $uold] [join $ulist $ulistsep]]
259 } 264 }
260 265
261 } elseif {[string match "hist*" $rcmd]} { 266 } elseif {[feeds_cmd_match "history" $rcmd]} {
262 # Show history of a feed 267 # Show history of a feed
263 if {[llength $rarglist] < 2} { 268 if {[llength $rarglist] < 2} {
264 feeds_msg $upublic $unick $uchan "help_history" 269 feeds_msg $upublic $unick $uchan "help_history"
265 return 0 270 return 0
266 } 271 }
288 feeds_msg $upublic $unick $uchan "history_list" [list $fname [join $ulist $ulistsep]] 293 feeds_msg $upublic $unick $uchan "history_list" [list $fname [join $ulist $ulistsep]]
289 } else { 294 } else {
290 # Help/usage 295 # Help/usage
291 feeds_msg $upublic $unick $uchan "help_short" 296 feeds_msg $upublic $unick $uchan "help_short"
292 } 297 }
298
299 return 0
293 } 300 }
294 301
295 302
296 #------------------------------------------------------------------------- 303 #-------------------------------------------------------------------------
297 proc feeds_cmd_pub {unick uhost uhand uchan uargs} { 304 proc feeds_cmd_pub {unick uhost uhand uchan uargs} {