changeset 594:a488be0f45e0

urllog: More cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 28 Jan 2021 12:47:20 +0200
parents 3bd5a5e072ad
children 7f7d8048ecb5
files config.urllog.example urllog.tcl
diffstat 2 files changed, 36 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/config.urllog.example	Wed Jan 27 17:14:11 2021 +0200
+++ b/config.urllog.example	Thu Jan 28 12:47:20 2021 +0200
@@ -7,8 +7,8 @@
 ###
 ### Bind commands
 ###
-bind pub - !urlfind urllog_cmd_pub_find
-bind msg - !urlfind urllog_cmd_msg_find
+bind pub - !urlfind urllog_cmd_pub_search
+bind msg - !urlfind urllog_cmd_msg_search
 bind pubm - *.* urllog_check_line
 bind topc - *.* urllog_check_line
 
@@ -92,7 +92,7 @@
 
 # 1 = Enable showing of ShortURLs
 # 0 = ShortURLs not shown in any bot actions
-set urllog_shorturl 1
+set urllog_shorturl_enable 1
 
 
 # Web server URL that handles redirects of ShortURLs
@@ -122,12 +122,19 @@
 ###
 ### Message related settings
 ###
-# Max length of original URL to be shown, rest is chopped
-# off if the URL is longer than the specified amount.
-set urllog_shorturl_max_orig 35
+# Max length of original URL to be shown when adding
+set urllog_add_url_max 100
+
+# Max length of title to be shown when adding
+set urllog_add_title_max 100
+
+# Max length of original URL to be shown on search
+# results IF ShortURLs are enabled and is available.
+# If ShortURLs are NOT enabled, full URL is used!
+set urllog_search_url_max 50
 
 # Max length of title to be shown on search results
-set urllog_title_max 35
+set urllog_search_title_max 50
 
 
 # Message texts (informal, errors, etc.)
@@ -159,7 +166,7 @@
   "url_known_long" "wanha!"
 
 
-  "search_result_title" "'@2@' "
+  "search_result_has_title" "'@2@' "
   "search_result_no_title" ""
 
   "search_result_short" "#@1@: @4@@5@ @6@ (@2@ @ @3@)"
--- a/urllog.tcl	Wed Jan 27 17:14:11 2021 +0200
+++ b/urllog.tcl	Thu Jan 28 12:47:20 2021 +0200
@@ -136,22 +136,9 @@
 }
 
 
-proc urllog_chop_url {ustr} {
-  global urllog_shorturl_max_orig
-
-  if {[string length $ustr] > $urllog_shorturl_max_orig} {
-    return "[string range $ustr 0 $urllog_shorturl_max_orig]..."
-  } else {
-    return $ustr
-  }
-}
-
-
-proc urllog_chop_title {ustr} {
-  global urllog_title_max
-
-  if {[string length $ustr] > $urllog_title_max} {
-    return "[string range $ustr 0 $urllog_title_max]..."
+proc urllog_chop_str {ustr umax} {
+  if {[string length $ustr] > $umax} {
+    return "[string range $ustr 0 $umax]..."
   } else {
     return $ustr
   }
@@ -160,7 +147,8 @@
 
 #-------------------------------------------------------------------------
 proc urllog_add_url {urlStr urlNick urlHost urlChan urlTitle} {
-  global urllog_db urllog_shorturl urllog_pub_channels
+  global urllog_db urllog_shorturl_enable urllog_pub_channels
+  global urllog_add_title_max urllog_add_url_max
 
 
   ### Does the URL already exist?
@@ -169,7 +157,7 @@
     urllog_log "URL said by $urlNick ($urlStr) already known"
 
     if {[utl_match_delim_list $urllog_pub_channels $uchan]} {
-      if {$urllog_shorturl != 0} {
+      if {$urllog_shorturl_enable != 0} {
         urllog_verb_msg 1 $urlNick $urlChan "url_known_short" [list $uuser $uchan $uhost [utl_ctime $utime] $utitle $uurl [urllog_get_short $uid]]
       } else {
         urllog_verb_msg 1 $urlNick $urlChan "url_known_long" [list $uuser $uchan $uhost [utl_ctime $utime] $utitle $uurl]
@@ -196,7 +184,7 @@
 
 
   ### Let's say something, to confirm that everything went well.
-  if {$urllog_shorturl != 0} {
+  if {$urllog_shorturl_enable != 0} {
     set urlShort [urllog_get_short $uid]
     set ushort "short"
   } else {
@@ -210,7 +198,7 @@
     set umode "url_added_${ushort}_no_title"
   }
 
-  urllog_verb_msg 1 $urlNick $urlChan $umode [list $urlTitle [urllog_chop_title $urlTitle] $urlStr [urllog_chop_url $urlStr] $urlShort]
+  urllog_verb_msg 1 $urlNick $urlChan $umode [list $urlTitle [urllog_chop_str $urlTitle $urllog_add_title_max] $urlStr [urllog_chop_str $urlStr $urllog_add_url_max] $urlShort]
   return 1
 }
 
@@ -281,7 +269,7 @@
 
 #-------------------------------------------------------------------------
 proc urllog_validate_url { urlNick urlChan urlMStr urlMProto urlMHostName } {
-  global urllog_httprep urllog_shorturl_prefix urllog_shorturl
+  global urllog_httprep urllog_shorturl_prefix urllog_shorturl_enable
 
   upvar $urlMStr urlStr
   upvar $urlMProto urlProto
@@ -561,8 +549,9 @@
 
 #-------------------------------------------------------------------------
 ### Parse arguments, find and show the results
-proc urllog_cmd_find {unick uhand uchan utext upublic} {
-  global urllog_db urllog_shorturl urllog_showmax_pub urllog_showmax_priv
+proc urllog_cmd_search {unick uhand uchan utext upublic} {
+  global urllog_db urllog_shorturl_enable urllog_showmax_pub urllog_showmax_priv
+  global urllog_search_title_max urllog_search_url_max
 
   if {$upublic == 0} {
     set ulimit 5
@@ -605,14 +594,14 @@
   set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, title AS utitle FROM urls $fquery ORDER BY utime DESC LIMIT $ulimit"
   urllog_db eval $usql {
     incr nresult
-    if {[info exists $utitle] && [string length $utitle] > 0} {
-      set stitle [utl_str_map_values [urllog_qm "search_result_title"] [list $utitle [urllog_chop_title $utitle]]]
+    if {[string length $utitle] > 0} {
+      set stitle [utl_str_map_values [urllog_qm "search_result_has_title"] [list $utitle [urllog_chop_str $utitle $urllog_search_title_max]]]
     } else {
       set stitle [urllog_qm "search_result_no_title"]
     }
-    
-    if {$urllog_shorturl != 0 && $uid != ""} {
-      urllog_msg $upublic $unick $uchan "search_result_short" [list $nresult $uuser [utl_ctime $utime] $stitle [urllog_chop_url $uurl] [urllog_get_short $uid]]
+
+    if {$urllog_shorturl_enable != 0 && $uid != ""} {
+      urllog_msg $upublic $unick $uchan "search_result_short" [list $nresult $uuser [utl_ctime $utime] $stitle [urllog_chop_str $uurl $urllog_search_url_max] [urllog_get_short $uid]]
     } else {
       urllog_msg $upublic $unick $uchan "search_result_long" [list $nresult $uuser [utl_ctime $utime] $stitle $uurl]
     }
@@ -629,18 +618,18 @@
 
 #-------------------------------------------------------------------------
 ### Finding binded functions
-proc urllog_cmd_pub_find {unick uhost uhand uchan utext} {
+proc urllog_cmd_pub_search {unick uhost uhand uchan utext} {
   global urllog_search_channels
 
   if {[utl_match_delim_list $urllog_search_channels $uchan]} {
-    return [urllog_cmd_find $unick $uhand $uchan $utext 1]
+    return [urllog_cmd_search $unick $uhand $uchan $utext 1]
   }
   return 0
 }
 
 
-proc urllog_cmd_msg_find {unick uhost uhand utext} {
-  return [urllog_cmd_find $unick $uhand "" $utext 0]
+proc urllog_cmd_msg_search {unick uhost uhand utext} {
+  return [urllog_cmd_search $unick $uhand "" $utext 0]
 }