-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathurl2irc2.1.tcl
512 lines (463 loc) · 22.2 KB
/
url2irc2.1.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# URL 2 IRC by Lily (https://github.com/starlilyth)
# Scans links in IRC channels and returns titles and tinyurl, and logs to a webpage.
# Will tag weblog entries NSFW if that appears in the line with the link.
# Has duplicate link detection - displays newest entry only, with link count and poster list.
# For Eggdrop bots. Has been tested on eggdrop 1.9.1.
# You must ".chanset #channel +url2irc" for each chan you wish to use this in.
# Requires TCL8.4 or greater with tcllib, tcltls, and the sqlite3 tcl library. (not mysql!)
# For deb/ubuntu, the packages needed are tcllib and libsqlite3-tcl. Adjust for your flavor.
#
# YouTube search is an optional component. Enable it by adding a Google/YouTube API key
# Get your key here: https://developers.google.com/youtube/v3/getting-started
# This needs to be set to a bot writable directory for the web log pages.
set url2irc(path) /var/www/html/urllog
# Google/YouTube API key. Put your key in quotes to enable !yt searching and extended YouTube info
set url2irc(apikey) ""
# Use ASCII colors?
set url2irc(color) true
# Dark mode for the web page?
set url2irc(darkmode) true
# Show runtime: "(11s ago)".
set url2irc(runtime) true
# Optional space separated list of domains/URLs/keywords to ignore. Entries are * expanded both ways, you have been warned.
set url2irc(iglist) "rotten.com lemonparty.org terriblepicture.jpg"
# You may want to change these, but they are set pretty well.
set url2irc(maxdays) 7 ;# maximum number of days to save on log page
set url2irc(tlength) 90 ;# minimum url length for tinyurl (tinyurl is 18 chars..)
set url2irc(pubmflags) "-|-" ;# user flags required for use
# Fine tuning, safe to ignore.
set url2irc(ignore) "bkq|kq" ;# user flags script will ignore
set url2irc(length) 12 ;# minimum url length for title (12 chars is the shortest url possible, equalling all)
set url2irc(clength) 90 ;# log page url display length
set url2irc(delay) 2 ;# minimum seconds between use
set url2irc(timeout) 90000 ;# geturl timeout
set url2irc(maxsize) 1500000 ;# max page size in bytes
set url2irc(debug) false ;# show error handling
# 01 - Basic features set 20090521
# 02 - Build logger web page function and title regexp cleanup 20101130
# 05 - Fix logger for multiple chans, user agent string, web dir check 20101204
# 07 - s/regexp/htmlparse/, truncate long url display on log page 20101212
# 09 - some ::http cleanup volunteered by Steve (thanks!) 20110220: Check Content-Type; only get title for text pages
# - under maxsize, otherwise display mime-type. Follow http redirect (not meta refresh or javascript).
# 10 - converted to sqlite3, main loop cleanup 20110305
# 11 - secure URL handler, NSFW tagger 20110308
# 12 - site blacklist, comment cleanup, chanflag removal (just one now) 20110309
# 14 - post counts, day dividers, dupe detection - display newest w/ counter and poster list, carryover NSFW flag. 20110310
# 1.2 - fixed shortlink redirects, dbfile varname change, 20120821
# 1.3 - integrated google search. 20120821
# 1.5 - fixed redir/reloc. YouTube ignore flag. added output colors for some urls. 20150825
# - Removed google search; they wont support anything that does not show ads.
# 1.7 - updated user agent, added html charset, error handling, comments.
# - fixed: TLS, redirection, metadata case, title regexp, tinyurl, yt ignore. 20230323
# - TLS solution found at: http://forum.egghelp.org/viewtopic.php?t=20503
# 1.8 - JS only sites output, color flag, runtime output, code optimization, error handling. 20230328
# 2.0 - file name change, integrated youtube details and search function - 20230418
# 2.1 - HTML fixes, colors and darkmode - 20230412
# No edits below here unless you will submit a patch.
################################################
package require http
package require htmlparse
package require json
package require tls
package require sqlite3
set url2irc(udbfile) "./urllog.db"
set url2irc(agent) "Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15"
set url2irc(last) 111
setudef flag url2irc
bind pubm $url2irc(pubmflags) {*://*} pub_url2irc
proc pub_url2irc {nick host user chan text} {
global url2irc
if {([channel get $chan url2irc]) && ([expr [unixtime] - $url2irc(delay)] > $url2irc(last)) && (![matchattr $user $url2irc(ignore)])} {
set url2irc(starttime) [clock seconds]
# set NSFW flag
if {[string match -nocase "*nsfw*" $text]} { set lflag NSFW } else { set lflag {} }
# get URL
foreach word [split $text] {
if {[string length $word] >= $url2irc(length) && [regexp {^http(s|)://} $word] && ![regexp {://([^/:]*:([^/]*@|\d+(/|$))|.*/\.)} $word]} {
set url2irc(last) [unixtime]
# check for ignored
foreach item $url2irc(iglist) {if {[string match "*$item*" $word]} {return 0}}
# get the title
if {[regexp -nocase {(youtube|youtu.be)} $word] && ($url2irc(apikey) ne "")} {
set urltitle [yt_title $word]
} else {
set urltitle [get_title $word]
}
# add database entry
set lTime [clock seconds]
regsub "#" $chan "" cname
sqlite3 ldb $url2irc(udbfile)
ldb eval {CREATE TABLE IF NOT EXISTS urllog (lTime INTEGER,lchan TEXT,lnick TEXT,lurl TEXT,ltitle TEXT,lflag TEXT)}
ldb eval {INSERT INTO urllog (lTime, lchan, lnick, lurl, ltitle, lflag)VALUES($lTime,$cname,$nick,$word,$urltitle,$lflag)}
ldb close
# tinyurl
if {[string length $word] >= $url2irc(tlength)} {
set shorturl [tinyurl $word]
} else { set shorturl "" }
# channel output
set verbs "linked by"
chanout $nick $chan $urltitle $shorturl $verbs
# web page update
htmlout $chan
}
}
}
}
bind pub $url2irc(pubmflags) !yt yt_search
proc yt_search {nick host user chan text} {
global url2irc
if {$url2irc(apikey) ne ""} {
if {([channel get $chan url2irc]) && ([expr [unixtime] - $url2irc(delay)] > $url2irc(last)) && (![matchattr $user $url2irc(ignore)])} {
set url2irc(starttime) [clock seconds]
set url2irc(last) [unixtime]
#set url
regsub -all {\s+} $text "%20" urltext
set url "https://www.googleapis.com/youtube/v3/search?part=snippet&fields=items(id(videoId),id(channelId),snippet(title))&key=$url2irc(apikey)&q=$urltext&maxResults=1"
# get data
::http::register https 443 tls_socket
set http [::http::config -useragent $url2irc(agent)]
if {[catch {::http::geturl $url -timeout $url2irc(timeout)} http]} {
set status [::http::status $http]
set staterr $http
putlog "URL2IRC: $status using Google API for $text - $staterr"
return "$status - could not get data for $text"
}
set data [::http::data $http] ; ::http::cleanup $http
# process data
if {[info exists data]} {
# parse json
set ids [dict get [json::json2dict $data] items]
set id [lindex $ids 0 1 1]
set type [lindex $ids 0 1 0]
if {$type eq "channelId"} {
# channel
set shorturl "https://www.youtube.com/channel/$id"
set urltitle [lindex $ids 0 3 1]
set urltitle [::htmlparse::mapEscapes $urltitle]
append urltitle " - YouTube"
} else {
# use yt_title function to get full details
set shorturl "https://youtu.be/$id"
set urltitle [yt_title $shorturl]
}
# add database entry
set lTime [clock seconds]
regsub "#" $chan "" cname
if {[string match -nocase "*nsfw*" $urltitle]} { set lflag NSFW } else { set lflag {} }
sqlite3 ldb $url2irc(udbfile)
ldb eval {CREATE TABLE IF NOT EXISTS urllog (lTime INTEGER,lchan TEXT,lnick TEXT,lurl TEXT,ltitle TEXT,lflag TEXT)}
ldb eval {INSERT INTO urllog (lTime, lchan, lnick, lurl, ltitle, lflag)VALUES($lTime,$cname,$nick,$shorturl,$urltitle,$lflag)}
ldb close
#channel output
set verbs "found for"
chanout $nick $chan $urltitle $shorturl $verbs
# web page update
htmlout $chan
} else {
if {$url2irc(debug) eq true} {
putlog "URL2IRC: No data returned for $text"
}
}
}
}
}
proc get_title {url} {
global url2irc
set agent $url2irc(agent)
if {[info exists url] && [string length $url]} {
# get metadata
::http::register https 443 tls_socket
set http [::http::config -useragent $agent]
if {[catch {::http::geturl $url -timeout $url2irc(timeout) -validate 1} http]} {
# timeout will say timeout, not error
set status [::http::status $http]
set staterr $http
putlog "URL2IRC: $status getting metadata for $url - $staterr"
return "$status - could not get metadata"
}
array set meta [::http::meta $http] ; ::http::cleanup $http
# process redirection
if {[info exists meta(Location)]} {set meta(location) $meta(Location)}
set url2irc(redirects) 0
while {[info exists meta(location)] && [incr url2irc(redirects)] < 10} {
set location $meta(location)
# location can be relative, get domain if missing
if {![string match -nocase "https://*" $location]} {
regexp {(https://.*?/).*?} $url match host
set location $host$location
}
set startloc $location
# get new location
::http::register https 443 tls_socket
set http [::http::config -useragent $agent]
if {[catch {::http::geturl $location -timeout $url2irc(timeout) -validate 1} http]} {
set status [::http::status $http]
set staterr $http
putlog "URL2IRC: $url redirect failed - $staterr"
return $status
}
array set meta [::http::meta $http] ; ::http::cleanup $http
# process NEW metadata
if {[info exists meta(Location)]} {
set meta(location) $meta(Location)
}
if {![string match -nocase "https://*" $meta(location)]} {
regexp {(https://.*?/).*?} $url match host
set location $host$meta(location)
}
# break if we are looping
if {$startloc eq $location} {
set url $startloc
break
}
}
# process content type and length
if {[info exists meta(Content-Type)]} {set meta(content-type) $meta(Content-Type)}
if {[info exists meta(content-type)]} {
set content_type [lindex [split $meta(content-type) ";"] 0]
} else {
set content_type "Unknown"
}
if {[info exists meta(Content-Length)]} {set meta(content-length) $meta(Content-Length)}
if {[info exists meta(content-length)]} {
set content_length $meta(content-length)
} else {
set content_length 0
}
# get html page data
if {$content_length <= $url2irc(maxsize) && [string match -nocase "text/*" $content_type]} {
::http::register https 443 tls_socket
set http [::http::config -useragent $agent]
if {[catch {::http::geturl $url -timeout $url2irc(timeout)} http]} {
set status [::http::status $http]
return $status
}
set data [split [::http::data $http] \n] ; ::http::cleanup $http
}
# parse title from html data
if {[info exists data] && [regexp -nocase {<title.*?>(.*?)</title>} $data match title]} {
set title [::htmlparse::mapEscapes $title]
regsub -all {[\{\}\\]} $title "" title
regsub -all " +" $title " " title
regsub -all "';" $title "'" title
regsub -all "\";" $title "\"" title
regsub -all "&;" $title "&" title
set title [string trim $title]
# Thanks, Google.
if {![string match "302 Moved" $title]} {
return $title
}
}
# some diagnotics if we are still here
if {$url2irc(debug) eq true} {
if {$content_length > $url2irc(maxsize) && [string match -nocase "text/*" $content_type]} {
putlog "URL2IRC: $url exceeded maxsize ($content_length > $url2irc(maxsize)"
}
if {[info exists data]} {
putlog "URL2IRC: $url title data not matched"
} elseif {![regexp -nocase {(youtube)} $url]} {
putlog "URL2IRC: $url is type $content_type"
}
}
# Some sites/pages incorrectly require JavaScript or cookie acceptance to render any title.
# This provides a sitename if no title was returned.
if {[regexp -nocase {i.imgur} $url]} {return "Imgur \[$content_type\]"}
if {[regexp -nocase {imgur} $url]} {return "Imgur"}
if {[regexp -nocase {twitter} $url]} {return "Twitter"}
if {[regexp -nocase {twitch} $url]} {return "Twitch"}
if {[regexp -nocase {(youtube|youtu.be)} $url]} {return "YouTube"}
if {[regexp -nocase {(google|goo.gl)} $url]} {return "Google"}
if {[regexp -nocase {spotify} $url]} {return "Spotify"}
# if we still have not returned a title yet
return "$content_type"
} else {
return "URL ERROR"
}
}
proc yt_title {word} {
global url2irc
set url2irc(starttime) [clock seconds]
set url2irc(last) [unixtime]
# get id
regexp -nocase {(?:youtube.com\/watch\?.*v=|youtu.be\/)([\w-]{11})} $word match id
if {![info exists id]} {
set urltitle [get_title $word]
return $urltitle
}
set url "https://www.googleapis.com/youtube/v3/videos?id=$id&key=$url2irc(apikey)&part=snippet,statistics,contentDetails&fields=items(snippet(title,channelTitle,publishedAt),statistics(viewCount),contentDetails(duration))"
# get data
::http::register https 443 tls_socket
set http [::http::config -useragent $url2irc(agent)]
if {[catch {::http::geturl $url -timeout $url2irc(timeout)} http]} {
set status [::http::status $http]
set staterr $http
putlog "URL2IRC: $status using Google API for $text - $staterr"
return "$status - could not get data for $text"
}
set data [::http::data $http] ; ::http::cleanup $http
# process data
if {[info exists data]} {
# parse json
set ids [dict get [json::json2dict $data] items]
# get the title, user, viewcount
set title [lindex $ids 0 1 3]
set user [lindex $ids 0 1 5]
set views [lindex $ids 0 5 1]
regsub -all {\d(?=(\d{3})+($|\.))} $views {\0,} views
# published date
set pubiso [lindex $ids 0 1 1]
set pubiso [string map {"T" " " ".000Z" "" "Z" ""} $pubiso]
set pubtime [clock format [clock scan $pubiso] -format {%b %d %Y}]
# duration
set isotime [lindex $ids 0 3 1]
if { [string index $isotime 0] == "0" || $isotime == "P0D" } {
set isotime "live"
} else {
# for m00nie..
regexp -all {P(?:(\d+)D)?T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?} $isotime match ydays yhours ymins ysecs
if {$ysecs == ""} {set ysecs "00"} else {set ysecs [format "%02d" $ysecs]}
if {$ymins == ""} {set ymins "00"}
if {$yhours == ""} {
set isotime "$ymins:$ysecs"
} else {
set ymins [format "%02d" $ymins]
set isotime "$yhours:$ymins:$ysecs"
}
if {$ydays != ""} {set isotime "${ydays}d $isotime"}
}
# output
return "$title \[$isotime\] (by $user on $pubtime : $views views) - YouTube"
}
}
proc tinyurl {url} {
global url2irc
set agent $url2irc(agent)
if {[info exists url] && [string length $url]} {
set http [::http::config -useragent $agent]
# tinyurl does not work with httpS - in 2023
set http [::http::geturl "http://tinyurl.com/create.php" -query [::http::formatQuery "url" $url] -timeout $url2irc(timeout)]
set data [split [::http::data $http] \n] ; ::http::cleanup $http
for {set index [llength $data]} {$index >= 0} {incr index -1} {
if {[regexp {href="https://tinyurl\.com/\w+"} [lindex $data $index] url]} {
return [string map { {href=} "" \" "" } $url]
}
}
}
return ""
}
proc chanout {nick chan urltitle shorturl verbs} {
global url2irc
if {$url2irc(color) eq true} {
# channel output formatting (colors)
# Color reference: https://clients.sisrv.net/knowledgebase/137/EggDrop-colors-and-formatting-codes.html
regsub -all "YouTube" $urltitle "\00301,00You\00300,04Tube\003" urltitle
regsub -all "Google" $urltitle "\00302,15G\00304o\00308o\00302g\00303l\00304e\003" urltitle
regsub -all "Facebook" $urltitle "\00302Facebook\003" urltitle
regsub -all "Imgur" $urltitle "\00309Imgur\003" urltitle
regsub -all "Spotify" $urltitle "\00309Spotify\003" urltitle
regsub -all "Twitter" $urltitle "\00311Twitter\003" urltitle
regsub -all "Twitch" $urltitle "\00306Twitch\003" urltitle
}
# channel output
set runtime ""
set totaltime [expr [clock seconds] - $url2irc(starttime)]
if {$url2irc(runtime) eq true} {set runtime "(${totaltime}s ago)"}
if {[string length $shorturl]} {
puthelp "PRIVMSG $chan :\002$urltitle\002\017 ( $shorturl ), $verbs $nick $runtime"
} else {
puthelp "PRIVMSG $chan :\002$urltitle\002\017, $verbs $nick $runtime"
}
}
proc htmlout {chan} {
global url2irc
global botnick
if {[file isdirectory $url2irc(path)] && [file writable $url2irc(path)]} {
regsub "#" $chan "" cname
sqlite3 ldb $url2irc(udbfile)
# update database
set rtime [expr [clock seconds] - ($url2irc(maxdays) * 86400)]
ldb eval {DELETE FROM urllog WHERE lTime < $rtime}
set logday 0000
# page setup
set bgcolor "white"
set fontcolor "black"
if {$url2irc(darkmode) eq "true"} {
set bgcolor "black"
set fontcolor "ivory"
}
set headerhtml "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"600\" /><style> * { font-family: sans-serif; background-color: $bgcolor; color: $fontcolor }</style>"
set footerhtml "<p style='text-align: center'><small><b>URL 2 IRC</b> by Lily (<a href=\"https://github.com/starlilyth\" target=\"_blank\">https://github.com/starlilyth</a>)</small></body></html>"
# channel page
set htmlpage [ open "$url2irc(path)/$cname.html" w+ ]
puts $htmlpage "$headerhtml <title>URL Log for $chan</title><head>"
set lcount [ldb eval {SELECT COUNT(distinct lurl) FROM urllog where lchan = $cname}]
set tdays [expr (([clock seconds] - [ldb eval {SELECT lTime FROM urllog where lchan = $cname order by rowid asc limit 1}]) / 86400) +1]
puts $htmlpage "<body><h1>URL Log for $chan</h1>$lcount URLs in $tdays days<br><small>This page reloads itself every 5 minutes.<br>Go back to the <a href=\"./index.html\">Index</a></small><p>Date - Time - <i>Nick</i> - URL<br><b>Title</b></p>"
foreach lrowid [ldb eval {SELECT rowid FROM urllog WHERE lchan = $cname order by rowid desc}] {
set lrurl [ldb eval {SELECT lurl FROM urllog where rowid = $lrowid }]
set lrucount [ldb eval {SELECT COUNT(1) FROM urllog where lurl = $lrurl AND lchan = $cname}]
set lrnick [ldb eval {SELECT DISTINCT lnick FROM urllog where lurl = $lrurl AND lchan = $cname}]
if {$lrucount > 1 } {
if {[ldb eval {SELECT rowid from urllog where lurl = $lrurl AND lchan = $cname order by rowid desc limit 1}]!=$lrowid} {
continue } else {
regsub -all " " $lrnick "/" lrnick
set plrnick "linked $lrucount times by $lrnick"
}
} else {set plrnick $lrnick}
set lrtitle [ldb onecolumn {SELECT ltitle FROM urllog where rowid = $lrowid }]
# fancy colors - https://www.w3schools.com/colors/colors_names.asp
regsub -all "Google" $lrtitle "<span style='color:dodgerblue'>G</span><span style='color:red'>o</span><span style='color:gold'>o</span><span style='color:dodgerblue'>g</span><span style='color:limegreen'>l</span><span style='color:red'>e</span>" lrtitle
regsub -all "YouTube" $lrtitle "You<span style='background-color:tomato;color:white'>Tube</span>" lrtitle
regsub -all "Facebook" $lrtitle "<span style='color:dodgerblue'>Facebook</span>" lrtitle
regsub -all "Imgur" $lrtitle "<span style='color:limegreen'>Imgur</span>" lrtitle
regsub -all "Spotify" $lrtitle "<span style='color:green'>Spotify</span>" lrtitle
regsub -all "Twitter" $lrtitle "<span style='color:deepskyblue'>Twitter</span>" lrtitle
regsub -all "Twitch" $lrtitle "<span style='color:blueviolet'>Twitch</span>" lrtitle
# NSFW tag
if {[ldb eval {SELECT COUNT(1) FROM urllog where lurl = $lrurl AND lchan = $cname and lflag like '%NSFW%'}]} {
set lrf " - (marked <font color=\"red\"><b>NSFW</b></font>)"} else {set lrf ""}
# URL trim
if {[string length $lrurl] >=$url2irc(clength)} {
set plrurl "[string replace $lrurl $url2irc(clength) end ] ..."
} else { set plrurl $lrurl }
# time
set lrTime [ldb eval {SELECT lTime FROM urllog where rowid = $lrowid }]
set tstamp [clock format $lrTime -format {%b. %d - %H:%M}]
# day divider
if {[clock format $lrTime -format {%m%d}] != $logday} {
set plogday [clock format $lrTime -format {%A %B %d}]
puts $htmlpage "<p style='text-align: center'><b>$plogday</b></p><hr>"
set logday [clock format $lrTime -format {%m%d}]
}
# url entry
puts $htmlpage "<p>$tstamp - <i>$plrnick</i> - <a href=\"$lrurl\" target=\"_blank\">$plrurl</a><br><b>$lrtitle</b>$lrf<hr>"
}
puts $htmlpage $footerhtml
close $htmlpage
# index page
set indexpage [ open "$url2irc(path)/index.html" w+ ]
puts $indexpage "$headerhtml <title>URL Log Index for $botnick</title><head>"
set ilcount [ldb eval {SELECT COUNT(distinct lurl) FROM urllog}]
set ichanc [ldb eval {SELECT COUNT(distinct lchan) FROM urllog}]
puts $indexpage "<body><h1>URL Log Index for $botnick</h1>$ilcount URLs in $ichanc channels<br><small>This page reloads itself every 5 minutes.</small><hr>"
foreach chanid [ldb eval {SELECT distinct lchan FROM urllog}] {
set ilcount [ldb eval {SELECT COUNT(distinct lurl) FROM urllog where lchan = $chanid}]
set ilTime [ldb eval {SELECT lTime from urllog where lchan = $chanid order by rowid desc limit 1}]
set itstamp [clock format $ilTime -format {%B %d at %H:%M}]
set iltitle [ldb onecolumn {SELECT ltitle from urllog where lchan = $chanid order by rowid desc limit 1}]
puts $indexpage "<p><a href=\"./$chanid.html\">\#$chanid</a> - $ilcount URLs - last link posted $itstamp<br>Last link title: <b>$iltitle</b></p><hr>"
}
puts $indexpage $footerhtml
close $indexpage
ldb close
} else {
putlog "URL2IRC: Web log path not valid! Not writing html files."
}
}
proc tls_socket {args} {
set opts [lrange $args 0 end-2]
set host [lindex $args end-1]
set port [lindex $args end]
::tls::socket -servername $host {*}$opts $host $port
}
putlog "URL 2 IRC v2.1 script loaded"