Mercurial > hg > egg-tcls
diff feeds.tcl @ 566:4cd72a178cbf
feeds: More work and bugfixing.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jul 2020 22:40:59 +0300 |
parents | cd5dd38466cf |
children | 14dfb925a64a |
line wrap: on
line diff
--- a/feeds.tcl Fri Jul 10 01:22:55 2020 +0300 +++ b/feeds.tcl Sat Jul 11 22:40:59 2020 +0300 @@ -75,27 +75,28 @@ gets $ufile oldtime close $ufile } else { - feeds_log "Could not open timefile: $uerrmsg" + feeds_log "Could not open timefile for reading: ${uerrmsg}" set oldtime [clock seconds] } # Check for new items - set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC" - set nresult [feeds_dbh onecolumn "SELECT COUNT(*) FROM feeds WHERE utime > $oldtime"] + set nresults [feeds_dbh onecolumn "SELECT COUNT(*) FROM feeds WHERE utime > $oldtime"] - if {$nresult > $feeds_sync_limit} { + if {$nresults > $feeds_sync_limit} { # Too many items, don't spam the channels - feeds_log "${nresult} new entries since [utl_ctime $oldtime], probably unsynchronized. Ignoring." + feeds_log "${nresults} new entries since [utl_ctime $oldtime], probably unsynchronized. Ignoring." if {$uforce} { - feeds_msg $upublic $unick $uchan "chk_unsync_entries" [list $nresult [utl_ctime $oldtime]] + feeds_msg $upublic $unick $uchan "chk_unsync_entries" [list $nresults [utl_ctime $oldtime]] } - } else { + } elseif {$nresults > 0 || $uforce} { # Spam the channels with new items - feeds_log "${nresult} new entries since [utl_ctime $oldtime] .." + feeds_log "${nresults} new entries since [utl_ctime $oldtime] .." + if {$uforce} { - feeds_msg $upublic $unick $uchan "chk_new_entries" [list $nresult [utl_ctime $oldtime]] + feeds_msg $upublic $unick $uchan "chk_new_entries" [list $nresults [utl_ctime $oldtime] $oldtime] } + set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC" feeds_dbh eval $usql { # Message all relevant channels foreach {qchan ufilter} [array get feeds_channels] { @@ -108,10 +109,12 @@ } } - if {$nresult > 0} { + if {$nresults > 0} { if {![catch {set ufile [open "${feeds_dbfile}.time" w 0600]} uerrmsg]} { puts $ufile [clock seconds] close $ufile + } else { + feeds_log "Could not write timefile: ${uerrmsg}" } } } @@ -127,18 +130,18 @@ } -proc feeds_validate_name {upublic unick uchan upattern ufeed} { +proc feeds_validate_name {upublic unick uchan upattern ufname} { global feeds_dbh - upvar 1 $ufeed rfeed + upvar 1 $ufname afname # Check value if {$upattern == ""} { - set ufeed "" + set afname "" return 1 } # Check if there are multiple matches - set usql "SELECT COUNT(DISTINCT(feed)) AS nfeeds,feed AS rfeed FROM feeds WHERE feed LIKE '%[utl_escape $upattern]%'" + set usql "SELECT COUNT(DISTINCT(feed)) AS nfeeds,feed AS afname FROM feeds WHERE feed LIKE '%[utl_escape $upattern]%'" feeds_dbh eval $usql {} if {$nfeeds > 1} { @@ -152,6 +155,7 @@ } } + # ------------------------------------------------------------------------ proc feeds_cmd {unick uhost uhand uchan uargs upublic} { global feeds_dbh feeds_messages feeds_history_limit @@ -174,12 +178,11 @@ set utext [string tolower [join $rargs " "]] # Validate feed name - set ufeed "" - if {![feeds_validate_name $upublic $unick $uchan $utext $ufeed]} { + if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { return 0 } - set usql "SELECT url AS uurl, feed AS ufeed, title AS utitle, utime AS utime FROM feeds WHERE feed LIKE '%[utl_escape $utext]%' ORDER BY utime DESC LIMIT 1" + set usql "SELECT url AS uurl, feed AS ufeed, title AS utitle, utime AS utime FROM feeds WHERE feed LIKE '%[utl_escape $fname]%' ORDER BY utime DESC LIMIT 1" feeds_dbh eval $usql { feeds_msg $upublic $unick $uchan "search_latest_feed" [list $ufeed [utl_ctime $utime] $utitle $uurl] set ufound 1 @@ -193,6 +196,7 @@ if {![matchattr $uhand n]} { feeds_msg $upublic $unick $uchan "no_access" } + feeds_check_do 1 $upublic $unick $uchan } elseif {[string match "list*" $rcmd]} { # List feeds @@ -202,7 +206,7 @@ # Long list set utext [string tolower [join [lrange $rargs 1 end] " "]] - if {$upublic} { + if {$upublic && ![matchattr $uhand n]} { feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] return 0 } @@ -262,29 +266,29 @@ } set utext [string tolower [join $rargs " "]] - if {$upublic} { + if {$upublic && ![matchattr $uhand n]} { feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] return 0 } # Validate feed name - if {![feeds_validate_name $upublic $unick $uchan $utext $ufeed]} { + if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { return 0 } set ulistitem [feeds_qm "history_list_item"] set ulistsep [feeds_qm "history_list_sep"] - set usql "SELECT url AS uurl, title AS utitle, utime FROM feeds WHERE feed='[utl_escape $ufeed]' ORDER BY utime DESC LIMIT ${feeds_history_limit}" + set usql "SELECT url AS uurl, title AS utitle, utime FROM feeds WHERE feed='[utl_escape $fname]' ORDER BY utime DESC LIMIT ${feeds_history_limit}" set ulist {} feeds_dbh eval $usql { lappend ulist [utl_str_map_values $ulistitem [list $uurl $utitle [utl_ctime $utime]]] } - feeds_msg $upublic $unick $uchan "history_list" [list $ufeed [join $ulist $ulistsep]] + feeds_msg $upublic $unick $uchan "history_list" [list $fname [join $ulist $ulistsep]] } else { # Help/usage - feeds_msg $upublic $unick $uchan "help" + feeds_msg $upublic $unick $uchan "help_short" } }