changeset 482:0e50c8440ea2

quotedb: Add img: image URL support.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Oct 2019 17:45:22 +0300
parents 4e19db35cdab
children 57443894bd8e
files config.quotedb.example quotedb.tcl
diffstat 2 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/config.quotedb.example	Tue Oct 22 17:43:51 2019 +0300
+++ b/config.quotedb.example	Tue Oct 22 17:45:22 2019 +0300
@@ -107,8 +107,8 @@
 
 bind pub - !mn mn_pub_cmd
 bind msg - !mn mn_msg_cmd
-proc mn_pub_cmd {unick uhost uhand uchan utext}    { qdb_command "!mn" "mndb" $unick $uhost $uhand $uchan $utext 1 ""}
-proc mn_msg_cmd {unick uhost uhand utext}          { qdb_command "!mn" "mndb" $unick $uhost $uhand "" $utext 0 ""}
+proc mn_pub_cmd {unick uhost uhand uchan utext}    { qdb_command "!mn" "mndb" $unick $uhost $uhand $uchan $utext 1 "" "https://tnsp.org/mndb/img/" }
+proc mn_msg_cmd {unick uhost uhand utext}          { qdb_command "!mn" "mndb" $unick $uhost $uhand "" $utext 0 "" "https://tnsp.org/mndb/img/"}
 
 bind pub - !tuksu tuksu_pub_cmd
 bind msg - !tuksu tuksu_msg_cmd
--- a/quotedb.tcl	Tue Oct 22 17:43:51 2019 +0300
+++ b/quotedb.tcl	Tue Oct 22 17:45:22 2019 +0300
@@ -288,7 +288,7 @@
 
 
 #-------------------------------------------------------------------------
-proc qdb_get {ufmt utable unick uchan uindex upublic} {
+proc qdb_get {ufmt utable unick uchan uindex upublic urlprefix} {
   global qdb_handle qdb_msg_no_matches
 
   set usql "SELECT total(${utable}_votes.vote) AS uvote, ${utable}.id AS quoteID, ${utable}.utext AS utext, ${utable}.utime AS utime, ${utable}.user AS uuser FROM ${utable} LEFT JOIN ${utable}_votes ON ${utable}_votes.urlid = ${utable}.id"
@@ -307,6 +307,9 @@
   }
 
   qdb_handle eval $usql {
+    if {[string range $utext 0 3] == "img:"} {
+      set utext "${urlprefix}[string range $utext 4 end]"
+    }
     if {$ufmt != ""} {
       qdb_msg $upublic $unick $uchan $ufmt [list $quoteID $utext $uuser [utl_ctime $utime] $uvote]
     } else {
@@ -389,7 +392,7 @@
 
 
 #-------------------------------------------------------------------------
-proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic ufmt_get} {
+proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic ufmt_get urlprefix} {
   global qdb_msg_help qdb_channels
 
   if {$upublic && ![utl_match_delim_list $qdb_channels $uchan]} {
@@ -400,16 +403,16 @@
 
   if {$utext == "" || $utext == {}} {
     # No arguments, assume random query
-    qdb_get $ufmt_get $utable $unick $uchan -1 $upublic
+    qdb_get $ufmt_get $utable $unick $uchan -1 $upublic $urlprefix
   } elseif {[regexp {^(stat|stats|tilasto|tilastot)$} $utext umatch]} {
     # Statistics
     qdb_stats $utable $unick $uchan $upublic
   } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} {
     # Latest added
-    qdb_get $ufmt_get $utable $unick $uchan -2 $upublic
+    qdb_get $ufmt_get $utable $unick $uchan -2 $upublic $urlprefix
   } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} {
     # Numeric argument, assume index query
-    qdb_get $ufmt_get $utable $unick $uchan $unum $upublic
+    qdb_get $ufmt_get $utable $unick $uchan $unum $upublic $urlprefix
   } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} {
     # Toplist of quotes
     qdb_toplist $utable $unick $uchan $unum $upublic