changeset 219:4e09bcc48851

urllog: Add settings for specifying channels where URL logging is active, and where !urlfind functionality works (separately, if so desired.)
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 30 Sep 2014 14:47:58 +0300
parents 861a49abee22
children 03579553233b
files urllog.tcl
diffstat 1 files changed, 33 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/urllog.tcl	Mon Sep 29 05:49:22 2014 +0300
+++ b/urllog.tcl	Tue Sep 30 14:47:58 2014 +0300
@@ -45,6 +45,13 @@
 ### General options
 ###
 
+# Channels where URLLog records links/URLs
+# set urllog_log_channels "#foobar;#baz"
+# You can use * to match substrings or everything
+set urllog_log_channels "*"
+
+
+
 # Filename of the SQLite URL database file
 set urllog_db_file "urllog.sqlite"
 
@@ -68,10 +75,9 @@
 ### Search related settings
 ###
 
-# 0 = No search-commands available
-# 1 = Search enabled
-set urllog_search 1
-
+# Channels where !urlfind and other commands can be used.
+# By default this is set to be the same as urllog_log_channels
+set urllog_search_channels $urllog_log_channels
 
 # Limit how many URLs should the "!urlfind" command show at most.
 set urllog_showmax_pub 3
@@ -167,11 +173,8 @@
 package require http
 
 ### Binding initializations
-if {$urllog_search != 0} {
-  bind pub - !urlfind urllog_pub_urlfind
-  bind msg - !urlfind urllog_msg_urlfind
-}
-
+bind pub - !urlfind urllog_pub_urlfind
+bind msg - !urlfind urllog_msg_urlfind
 bind pubm - *.* urllog_checkmsg
 bind topc - *.* urllog_checkmsg
 
@@ -210,10 +213,6 @@
   putlog " (Verbose mode enabled)"
 }
 
-if {$urllog_search != 0} {
-  putlog " (Search commands enabled)"
-}
-
 #-------------------------------------------------------------------------
 ### Utility functions
 proc urllog_log {arg} {
@@ -603,17 +602,27 @@
 
 
 #-------------------------------------------------------------------------
+
+
 proc urllog_checkmsg {unick uhost uhand uchan utext} {
+  global urllog_log_channels
+
   ### Check the nick
   if {$unick == "*"} {
     urllog_log "urllog_checkmsg: nick was wc, this should not happen."
     return 0
   }
 
-  ### Do the URL checking
-  foreach str [split $utext " "] {
-    if {[regexp "(ftp|http|https)://|www\..+|ftp\..*" $str]} {
-      urllog_checkurl $str $unick $uhost $uchan
+  ### Check the channel
+  foreach akey [split $urllog_log_channels] {
+    if {[string match $akey $uchan]} {
+      ### Do the URL checking
+      foreach str [split $utext " "] {
+        if {[regexp "(ftp|http|https)://|www\..+|ftp\..*" $str]} {
+          urllog_checkurl $str $unick $uhost $uchan
+        }
+      }
+      return 0
     }
   }
 
@@ -686,7 +695,13 @@
 #-------------------------------------------------------------------------
 ### Finding binded functions
 proc urllog_pub_urlfind {unick uhost uhand uchan utext} {
-  urllog_find $unick $uhand $uchan $utext 1
+  global urllog_search_channels
+
+  foreach akey [split $urllog_search_channels ";"] {
+    if {[string match $akey $uchan]} {
+      return [urllog_find $unick $uhand $uchan $utext 1]
+    }
+  }
   return 0
 }