# HG changeset patch # User Matti Hamalainen # Date 1594496459 -10800 # Node ID 4cd72a178cbf518bda5aaced689ce275b9f2cdb1 # Parent cd5dd38466cf31a10ae8469aabd3a2e967c64146 feeds: More work and bugfixing. diff -r cd5dd38466cf -r 4cd72a178cbf config.feeds.example --- a/config.feeds.example Fri Jul 10 01:22:55 2020 +0300 +++ b/config.feeds.example Sat Jul 11 22:40:59 2020 +0300 @@ -119,36 +119,38 @@ array set feeds_messages { "help_full" {"help_latest" "help_list" "help_history" "help_force"} - "help_latest" "@cmd@ latest \[\]" + "help_short" "@cmd@ latest \[\] \002|\002 hist \[\] \002|\002 list \[long\] \[\]" - "chk_unsync_entries" "Epäsynkki." - "chk_new_entries" "@1@ uutta." + "help_latest" "@cmd@ latest \[\]" + + "chk_unsync_entries" "Epäsynkki tai liikaa uusia feedejä." + "chk_new_entries" "@1@ uutta sitten ajankohdan @2@ / @3@." "chk_entry" "@1@: @4@ \002@2@\002 -- @3@" - "search_latest_feed" "Uusin '@1@' / @2@: @3@ -- @4@" - "search_no_matches" "Ei osumia haulla '@1@'." + "search_latest_feed" "Uusin '\002@1@\002' / @2@: @3@ -- @4@" + "search_no_matches" "Ei osumia haulla '\002@1@\002'." - "feed_list_active" "Aktiiviset feedit (uudemmat kuin @1@) -- @2@" + "feed_list_active" "Aktiiviset feedit (uudemmat kuin \002@1@\002) -- @2@" "feed_list_all" "Kaikki feedit:\n@1@" - "feed_list_filter" "Kaikki '@1@' mätsäävät feedit:\n@2@" + "feed_list_filter" "Kaikki '\002@1@\002' mätsäävät feedit:\n@2@" "feed_list_item_short" "@1@ (@2@)" "feed_list_sep_short" ", " "feed_list_item_long" "@1@ (@2@) @3@ @4@" "feed_list_sep_long" "\n" + "feed_list_long_denied" "EIII PYSTY, koita privana @cmd@ @1@" - "help_list" "@cmd@ list \[long\] \[feedin nimi patterni\]" "history_list" "Feedin '@1@' historia:\n@2@" "history_list_item" "@3@: '@2@' -- @1@" "history_list_sep" "\n" - "help_history" "@cmd@ hist " + "help_history" "@cmd@ hist " - "multiple_matches" "'@1@' mätsää useampaan kuin yhteen." - "no_matches" "Ei feediä haulla '@1@'." + "multiple_matches" "'@1@' mätsää useampaan kuin yhteen feedin nimeen." + "no_matches" "Ei löydy feediä haulla '@1@'." "help_force" "@cmd@ force" } diff -r cd5dd38466cf -r 4cd72a178cbf feeds.tcl --- 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" } }