Mercurial > hg > egg-tcls
annotate 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 |
rev | line source |
---|---|
70 | 1 ########################################################################## |
0 | 2 # |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
3 # FeedCheck v2.0 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" |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
32 set feeds_message "$feeds_name v2.0 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] |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
173 |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
174 if {[feeds_cmd_match "help" $rcmd]} { |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
175 # Show help |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
176 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
|
177 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
|
178 } |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
179 } 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
|
180 # 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
|
181 set ufound 0 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
182 set utext [string tolower [join $rargs " "]] |
565 | 183 |
184 # Validate feed name | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
185 if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { |
565 | 186 return 0 |
187 } | |
188 | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
189 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
|
190 feeds_dbh eval $usql { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
191 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
|
192 set ufound 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
193 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
194 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
195 if {$ufound == 0} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
196 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
|
197 } |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
198 } 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
|
199 # Force check for new entries |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
200 if {![matchattr $uhand n]} { |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
201 feeds_msg $upublic $unick $uchan "no_access" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
202 } |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
203 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
204 feeds_check_do 1 $upublic $unick $uchan |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
205 } elseif {[feeds_cmd_match "list" $rcmd]} { |
565 | 206 # List feeds |
207 set uarg [lindex $rargs 0] | |
208 | |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
209 if {[feeds_cmd_match "all" $uarg]} { |
565 | 210 # Long list |
211 set utext [string tolower [join [lrange $rargs 1 end] " "]] | |
212 | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
213 if {$upublic && ![matchattr $uhand n]} { |
565 | 214 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] |
215 return 0 | |
216 } | |
217 | |
218 set ulistitem [feeds_qm "feed_list_item_long"] | |
219 set ulistsep [feeds_qm "feed_list_sep_long"] | |
220 | |
221 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" | |
222 set ulist {} | |
223 | |
224 feeds_dbh eval $usql { | |
225 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
226 } | |
227 | |
228 if {$utext != ""} { | |
229 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]] | |
230 } else { | |
231 feeds_msg $upublic $unick $uchan "feed_list_all" [list [join $ulist $ulistsep]] | |
232 } | |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
233 |
565 | 234 } elseif {$uarg != ""} { |
235 # List feeds with a name filter | |
236 set utext [string tolower [join $rargs " "]] | |
237 | |
238 set ulistitem [feeds_qm "feed_list_item_short"] | |
239 set ulistsep [feeds_qm "feed_list_sep_short"] | |
240 | |
241 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" | |
242 set ulist {} | |
243 | |
244 feeds_dbh eval $usql { | |
245 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
246 } | |
247 | |
248 feeds_msg $upublic $unick $uchan "feed_list_filter" [list $utext [join $ulist $ulistsep]] | |
249 } else { | |
250 # List any active feeds | |
251 set uold [expr [clock seconds] - 60*60*24*365] | |
252 | |
253 set ulistitem [feeds_qm "feed_list_item_short"] | |
254 set ulistsep [feeds_qm "feed_list_sep_short"] | |
255 | |
256 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" | |
257 set ulist {} | |
258 | |
259 feeds_dbh eval $usql { | |
260 lappend ulist [utl_str_map_values $ulistitem [list $ufeed [utl_ctime $ulatest] [utl_ctime $uoldest] $nitems]] | |
261 } | |
262 | |
263 feeds_msg $upublic $unick $uchan "feed_list_active" [list [utl_ctime $uold] [join $ulist $ulistsep]] | |
264 } | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
265 |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
266 } elseif {[feeds_cmd_match "history" $rcmd]} { |
565 | 267 # Show history of a feed |
268 if {[llength $rarglist] < 2} { | |
269 feeds_msg $upublic $unick $uchan "help_history" | |
270 return 0 | |
271 } | |
272 | |
273 set utext [string tolower [join $rargs " "]] | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
274 if {$upublic && ![matchattr $uhand n]} { |
565 | 275 feeds_msg $upublic $unick $uchan "feed_list_long_denied" [list $rcmd $utext] |
276 return 0 | |
277 } | |
278 | |
279 # Validate feed name | |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
280 if {![feeds_validate_name $upublic $unick $uchan $utext fname]} { |
565 | 281 return 0 |
282 } | |
283 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
284 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
|
285 set ulistsep [feeds_qm "history_list_sep"] |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
286 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
|
287 set ulist {} |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
288 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
289 feeds_dbh eval $usql { |
565 | 290 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
|
291 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
292 |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
293 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
|
294 } else { |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
295 # Help/usage |
566
4cd72a178cbf
feeds: More work and bugfixing.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
296 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
|
297 } |
663
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
298 |
8bde8f798188
feeds: Use command matching helpers.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
299 return 0 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
300 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
301 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
302 |
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 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
|
305 global feeds_channels |
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 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
|
308 if {[string match $ukey $uchan]} { |
662
bb6aea76cdb4
feeds: Fix binds to actually work.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
309 feeds_cmd $unick $uhost $uhand $uchan $uargs 1 |
bb6aea76cdb4
feeds: Fix binds to actually work.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
310 return 1 |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
311 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
312 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
313 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
314 return 1 |
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 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
|
318 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
|
319 return 1 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
320 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
321 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
322 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
323 #------------------------------------------------------------------------- |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
324 # Script initialization |
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
325 #------------------------------------------------------------------------- |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
326 putlog "$feeds_message" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
327 |
605
1d39db72e190
feeds: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
596
diff
changeset
|
328 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
|
329 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
|
330 exit 2 |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
331 } |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
332 |
144 | 333 if {[info exists feeds_running]} { |
334 set feeds_last [expr [clock seconds] - $feeds_running] | |
335 } else { | |
336 set feeds_last -1 | |
337 } | |
338 | |
339 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
|
340 putlog " - Starting timed feed check." |
154
7a549487fba3
feeds: Cleanups, minor bugfix in feed update checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
146
diff
changeset
|
341 feeds_exec |
0 | 342 } |
343 | |
549
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
344 putlog " - Executing feeds_init()" |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
345 feeds_init |
c6f389bef58e
feeds: Largely refactor feeds.tcl, bump version to 2.0.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
346 putlog " - feeds_init() done." |
557
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
347 |
0ce432c3f03f
feeds: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
348 # end of script |