Mercurial > hg > egg-tcls
annotate feeds.tcl @ 676:2737e90aad83
feeds: Bump version.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 23 Feb 2021 15:11:32 +0200 |
parents | 79b5d8944eea |
children |
rev | line source |
---|---|
70 | 1 ########################################################################## |
0 | 2 # |
676 | 3 # FeedCheck v2.1 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
578 | 4 # (C) Copyright 2008-2021 Tecnic Software productions (TNSP) |
0 | 5 # |
265
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
6 # Requires fetch_feeds.tcl to be run as a cronjob, for example |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
7 # 15 * * * * /absolute/path/to/fetch_feeds.tcl |
0 | 8 # |
145 | 9 # See also create_feeds_db.tcl OR convert_feeds_db.tcl, as you will |
10 # need to either create a SQLite3 database or convert old text flat | |
11 # file to SQLite3. | |
12 # | |
0 | 13 # This script is freely distributable under GNU GPL (version 2) license. |
14 # | |
70 | 15 ########################################################################## |
0 | 16 |
265
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
17 ### The configuration should be in config.feeds in same directory |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
18 ### as this script. Or change the line below to point where ever |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
19 ### you wish. See "config.feeds.example" for an example config file. |
908edc54005a
feeds: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
20 source [file dirname [info script]]/config.feeds |
0 | 21 |
422
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
22 ### Required utillib.tcl |
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
23 source [file dirname [info script]]/utillib.tcl |
880a07485275
Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
393
diff
changeset
|
24 |
0 | 25 |
70 | 26 ########################################################################## |
0 | 27 # No need to look below this line |
70 | 28 ########################################################################## |
423
44c9128097cd
feeds: Remember to require sqlite3 package.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
29 package require sqlite3 |
44c9128097cd
feeds: Remember to require sqlite3 package.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
30 |
0 | 31 set feeds_name "FeedCheck" |
676 | 32 set feeds_message "$feeds_name v2.1 by ccr/TNSP" |
0 | 33 |
34 | |
70 | 35 # ------------------------------------------------------------------------ |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
36 ### Utility functions |
0 | 37 proc feeds_log {umsg} { |
550
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
38 global feeds_log_enable feeds_name |
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
39 if {$feeds_log_enable != 0} { |
595 | 40 putlog "${feeds_name}: $umsg" |
526
eb9921ae5c7a
feeds: Add feeds_logmsg setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
41 } |
0 | 42 } |
43 | |
534 | 44 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
45 proc feeds_qm {uid} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
46 global feeds_messages |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
47 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
48 if {[info exists feeds_messages($uid)]} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
49 return $feeds_messages($uid) |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
50 } else { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
51 return $uid |
0 | 52 } |
53 } | |
54 | |
55 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
56 proc feeds_smsg {apublic anick achan amsg {aargs {}}} { |
564
f85b5c572292
feeds: Add configuration setting feeds_cmd_name.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
57 global feeds_preferredmsg feeds_cmd_name |
f85b5c572292
feeds: Add configuration setting feeds_cmd_name.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
58 set amsg [string map [list "@cmd@" $feeds_cmd_name] $amsg] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
59 utl_msg_args $feeds_preferredmsg $apublic $anick $achan $amsg $aargs |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
60 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
61 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
62 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
63 proc feeds_msg {apublic anick achan aid {aargs {}}} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
64 feeds_smsg $apublic $anick $achan [feeds_qm $aid] $aargs |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
65 } |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
66 |
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
67 |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
68 proc feeds_cmd_match { uid ustr } { |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
69 global feeds_commands |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
70 return [utl_cmd_match feeds_commands $uid $ustr] |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
71 } |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
72 |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
73 |
70 | 74 # ------------------------------------------------------------------------ |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
75 proc feeds_check_do {uforce upublic unick uchan} { |
608 | 76 global feeds_db_file feeds_dbh feeds_sync_limit feeds_channels |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
77 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
78 # Get old time, if it exists |
0 | 79 set oldtime 0 |
608 | 80 if {![catch {set ufile [open "${feeds_db_file}.time" r 0600]} uerrmsg]} { |
0 | 81 gets $ufile oldtime |
82 close $ufile | |
83 } else { | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
84 feeds_log "Could not open timefile for reading: ${uerrmsg}" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
85 set oldtime [clock seconds] |
0 | 86 } |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
87 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
88 # Check for new items |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
89 set nresults [feeds_dbh onecolumn "SELECT COUNT(*) FROM feeds WHERE utime > $oldtime"] |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
90 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
91 if {$nresults > $feeds_sync_limit} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
92 # Too many items, don't spam the channels |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
93 feeds_log "${nresults} new entries since [utl_ctime $oldtime], probably unsynchronized. Ignoring." |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
94 if {$uforce} { |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
95 feeds_msg $upublic $unick $uchan "chk_unsync_entries" [list $nresults [utl_ctime $oldtime]] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
96 } |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
97 } elseif {$nresults > 0 || $uforce} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
98 # Spam the channels with new items |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
99 feeds_log "${nresults} new entries since [utl_ctime $oldtime] .." |
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
100 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
101 if {$uforce} { |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
102 feeds_msg $upublic $unick $uchan "chk_new_entries" [list $nresults [utl_ctime $oldtime] $oldtime] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
103 } |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
104 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
105 set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
106 feeds_dbh eval $usql { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
107 # Message all relevant channels |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
108 foreach {qchan ufilter} [array get feeds_channels] { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
109 foreach umatch [split $ufilter "|"] { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
110 if {[string match -nocase $umatch $ufeed]} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
111 feeds_msg 1 "NULL" $qchan "chk_entry" [list $ufeed $utitle $uurl [utl_ctime $utime]] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
112 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
113 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
114 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
115 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
116 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
117 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
118 if {$nresults > 0} { |
605
1d39db72e190
feeds: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
119 if {![catch {set ufile [open "${feeds_db_file}.time" w 0600]} uerrmsg]} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
120 puts $ufile [clock seconds] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
121 close $ufile |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
122 } else { |
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
123 feeds_log "Could not write timefile: ${uerrmsg}" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
124 } |
0 | 125 } |
126 } | |
127 | |
534 | 128 |
0 | 129 proc feeds_exec {} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
130 global feeds_check_period feeds_running |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
423
diff
changeset
|
131 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
132 feeds_check_do 0 0 "NULL" "NULL" |
141
c99df41a691a
Work on making the feeds script use the SQLite3 backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
133 |
144 | 134 set feeds_running [clock seconds] |
135 timer $feeds_check_period feeds_exec | |
0 | 136 } |
137 | |
146
7106dd8db4de
Improve entity parsing, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
138 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
139 proc feeds_validate_name {upublic unick uchan upattern ufname} { |
565 | 140 global feeds_dbh |
596 | 141 upvar $ufname afname |
565 | 142 |
143 # Check value | |
144 if {$upattern == ""} { | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
145 set afname "" |
565 | 146 return 1 |
147 } | |
148 | |
149 # Check if there are multiple matches | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
150 set usql "SELECT COUNT(DISTINCT(feed)) AS nfeeds,feed AS afname FROM feeds WHERE feed LIKE '%[utl_escape $upattern]%'" |
565 | 151 feeds_dbh eval $usql {} |
152 | |
153 if {$nfeeds > 1} { | |
154 feeds_msg $upublic $unick $uchan "multiple_matches" [list $upattern] | |
155 return 0 | |
156 } elseif {$nfeeds == 0} { | |
157 feeds_msg $upublic $unick $uchan "no_matches" [list $upattern] | |
158 return 0 | |
159 } else { | |
160 return 1 | |
161 } | |
162 } | |
163 | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
164 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
165 # ------------------------------------------------------------------------ |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
166 proc feeds_cmd {unick uhost uhand uchan uargs upublic} { |
565 | 167 global feeds_dbh feeds_messages feeds_history_limit |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
168 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
169 # Check and handle arguments |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
170 set rarglist [::textutil::split::splitx $uargs {\s+}] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
171 set rcmd [lindex $rarglist 0] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
172 set rargs [lrange $rarglist 1 end] |
666
79b5d8944eea
feeds: Improve admin checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
173 set qadmin [matchattr $uhand n] |
79b5d8944eea
feeds: Improve admin checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
174 # set qadmin 0 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
175 |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
176 if {[feeds_cmd_match "help" $rcmd]} { |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
177 # Show help |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
178 foreach ukey $feeds_messages(help_full) { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
179 feeds_msg $upublic $unick $uchan $ukey |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
180 } |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
181 } elseif {[feeds_cmd_match "latest" $rcmd]} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
182 # Show latest entry or latest entry of specified feed |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
183 set ufound 0 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
184 set utext [string tolower [join $rargs " "]] |
565 | 185 |
186 # Validate feed name | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
187 if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { |
565 | 188 return 0 |
189 } | |
190 | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
191 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" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
192 feeds_dbh eval $usql { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
193 feeds_msg $upublic $unick $uchan "search_latest_feed" [list $ufeed [utl_ctime $utime] $utitle $uurl] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
194 set ufound 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
195 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
196 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
197 if {$ufound == 0} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
198 feeds_msg $upublic $unick $uchan "search_no_matches" [list $utext] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
199 } |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
200 } elseif {[feeds_cmd_match "force" $rcmd]} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
201 # Force check for new entries |
666
79b5d8944eea
feeds: Improve admin checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
202 if {!$qadmin} { |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
203 feeds_msg $upublic $unick $uchan "no_access" |
666
79b5d8944eea
feeds: Improve admin checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
204 return 0 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
205 } |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
206 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
207 feeds_check_do 1 $upublic $unick $uchan |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
208 } elseif {[feeds_cmd_match "list" $rcmd]} { |
565 | 209 # List feeds |
210 set uarg [lindex $rargs 0] | |
211 | |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
212 if {[feeds_cmd_match "all" $uarg]} { |
565 | 213 # Long list |
214 set utext [string tolower [join [lrange $rargs 1 end] " "]] | |
215 | |
666
79b5d8944eea
feeds: Improve admin checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
216 if {$upublic && !$qadmin} { |
565 | 217 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] |
218 return 0 | |
219 } | |
220 | |
221 set ulistitem [feeds_qm "feed_list_item_long"] | |
222 set ulistsep [feeds_qm "feed_list_sep_long"] | |
223 | |
224 set usql "SELECT feed AS ufeed, MAX(utime) AS ulatest, MIN(utime) AS uoldest, COUNT(feed) AS nitems FROM feeds WHERE feed LIKE '%[utl_escape $utext]%' GROUP BY feed" | |
225 set ulist {} | |
226 | |
227 feeds_dbh eval $usql { | |
228 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
229 } | |
230 | |
231 if {$utext != ""} { | |
232 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]] | |
233 } else { | |
234 feeds_msg $upublic $unick $uchan "feed_list_all" [list [join $ulist $ulistsep]] | |
235 } | |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
236 |
565 | 237 } elseif {$uarg != ""} { |
238 # List feeds with a name filter | |
239 set utext [string tolower [join $rargs " "]] | |
240 | |
241 set ulistitem [feeds_qm "feed_list_item_short"] | |
242 set ulistsep [feeds_qm "feed_list_sep_short"] | |
243 | |
244 set usql "SELECT feed AS ufeed, MAX(utime) AS ulatest, MIN(utime) AS uoldest, COUNT(feed) AS nitems FROM feeds WHERE feed LIKE '%[utl_escape $utext]%' GROUP BY feed" | |
245 set ulist {} | |
246 | |
247 feeds_dbh eval $usql { | |
248 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
249 } | |
250 | |
251 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]] | |
252 } else { | |
253 # List any active feeds | |
254 set uold [expr [clock seconds] - 60*60*24*365] | |
255 | |
256 set ulistitem [feeds_qm "feed_list_item_short"] | |
257 set ulistsep [feeds_qm "feed_list_sep_short"] | |
258 | |
259 set usql "SELECT feed AS ufeed, MAX(utime) AS ulatest, MIN(utime) AS uoldest, COUNT(feed) AS nitems FROM feeds GROUP BY feed HAVING ulatest >= $uold" | |
260 set ulist {} | |
261 | |
262 feeds_dbh eval $usql { | |
263 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
264 } | |
265 | |
266 feeds_msg $upublic $unick $uchan "feed_list_active" [list [utl_ctime $uold] [join $ulist $ulistsep]] | |
267 } | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
268 |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
269 } elseif {[feeds_cmd_match "history" $rcmd]} { |
565 | 270 # Show history of a feed |
271 if {[llength $rarglist] < 2} { | |
272 feeds_msg $upublic $unick $uchan "help_history" | |
273 return 0 | |
274 } | |
275 | |
276 set utext [string tolower [join $rargs " "]] | |
666
79b5d8944eea
feeds: Improve admin checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
277 if {$upublic && !$qadmin} { |
565 | 278 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] |
279 return 0 | |
280 } | |
281 | |
282 # Validate feed name | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
283 if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { |
565 | 284 return 0 |
285 } | |
286 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
287 set ulistitem [feeds_qm "history_list_item"] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
288 set ulistsep [feeds_qm "history_list_sep"] |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
289 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}" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
290 set ulist {} |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
291 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
292 feeds_dbh eval $usql { |
565 | 293 lappend ulist [utl_str_map_values $ulistitem [list $uurl $utitle [utl_ctime $utime]]] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
294 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
295 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
296 feeds_msg $upublic $unick $uchan "history_list" [list $fname [join $ulist $ulistsep]] |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
297 } else { |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
298 # Help/usage |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
299 feeds_msg $upublic $unick $uchan "help_short" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
300 } |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
301 |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
302 return 0 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
303 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
304 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
305 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
306 #------------------------------------------------------------------------- |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
307 proc feeds_cmd_pub {unick uhost uhand uchan uargs} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
308 global feeds_channels |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
309 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
310 foreach {ukey uvalue} [array get feeds_channels] { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
311 if {[string match $ukey $uchan]} { |
662
bb6aea76cdb4
feeds: Fix binds to actually work.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
312 feeds_cmd $unick $uhost $uhand $uchan $uargs 1 |
bb6aea76cdb4
feeds: Fix binds to actually work.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
313 return 1 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
314 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
315 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
316 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
317 return 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
318 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
319 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
320 proc feeds_cmd_msg {unick uhost uhand uargs} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
321 feeds_cmd $unick $uhost $uhand "PRIV" $uargs 0 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
322 return 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
323 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
324 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
325 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
326 #------------------------------------------------------------------------- |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
327 # Script initialization |
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
328 #------------------------------------------------------------------------- |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
329 putlog "$feeds_message" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
330 |
605
1d39db72e190
feeds: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
331 if {[catch {sqlite3 feeds_dbh $feeds_db_file} uerrmsg]} { |
1d39db72e190
feeds: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
332 putlog "Could not open SQLite3 database '${feeds_db_file}': ${uerrmsg}" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
333 exit 2 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
334 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
335 |
144 | 336 if {[info exists feeds_running]} { |
337 set feeds_last [expr [clock seconds] - $feeds_running] | |
338 } else { | |
339 set feeds_last -1 | |
340 } | |
341 | |
342 if {$feeds_last < 0 || $feeds_last > [expr $feeds_check_period * 60]} { | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
343 putlog " - Starting timed feed check." |
154
7a549487fba3
feeds: Cleanups, minor bugfix in feed update checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
344 feeds_exec |
0 | 345 } |
346 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
347 putlog " - Executing feeds_init()" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
348 feeds_init |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
349 putlog " - feeds_init() done." |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
350 |
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
351 # end of script |