annotate quotedb.tcl @ 37:c3c597cac4b6

Add helper function qdb_sql_exec for simplifying certain SQL operations.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Sep 2011 18:21:32 +0300
parents 6e381916b016
children 428f498b6030
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 # QuoteDB v1.0 by ccr/TNSP <ccr@tnsp.org>
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 # (C) Copyright 2003-2011 Tecnic Software productions (TNSP)
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 # Not for public use or distribution. If you happen to find this,
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 # send your questions and/or problems to /dev/null, thank you.
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 ### General options
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 # Path and filename of the SQLite database
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 set qdb_file "quotedb.sqlite"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 # 1 = Verbose: Say messages PUBLIC when SPEDE is OK, bad, etc.
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 # 0 = Quiet : Say privately
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 set qdb_verbose 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 # 1 = Put some info to bot's Logfile when doing stuff...
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 # 0 = Don't.
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 set qdb_logmsg 1
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 # What IRC "command" should we use to send messages:
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 # (Valid alternatives are "PRIVMSG" and "NOTICE")
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 set qdb_preferredmsg "PRIVMSG"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
30 # Foo.
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
31 set qdb_max_deltime 15
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
32
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 ### Search related settings
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 # How many SPEDE's should the !spedefind command show (maximum limit)
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 set qdb_showmax_pub 3
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 # For private-search, this is the default limit (user can change it)
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 set qdb_showmax_priv 5
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 # No need to look below this line
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 set qdb_name "QuoteDB"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 set qdb_version "1.0"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 ### Binding initializations
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 bind pub - !spedefind spede_pub_find
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 bind pub - !spedeadd spede_pub_add
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
56 bind pub - !spededel spede_pub_del
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 bind pub - !spede spede_pub_get
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 bind msg - spedefind spede_msg_find
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 bind msg - spede spede_msg_get
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 proc spede_pub_get {unick uhost uhand uchan utext} { qdb_msg 0 $uchan "" [qdb_get "spededb" $unick $uhand $utext] }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 proc spede_msg_get {unick uhost uhand utext} { qdb_msg 0 $unick "" [qdb_get "spededb" $unick $uhand $utext] }
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
63 proc spede_pub_add {unick uhost uhand uchan utext} { qdb_add "spededb" $utext $uhand $unick $uhost $uchan 1 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
64 proc spede_pub_del {unick uhost uhand uchan utext} { qdb_del "spededb" $utext $uhand $unick $uchan 1 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 proc spede_pub_find {unick uhost uhand uchan utext} { qdb_find "spededb" $unick $uhand $uchan $utext 1 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 proc spede_msg_find {unick uhost uhand utext} { qdb_find "spededb" $unick $uhand "" $utext 0 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
68 bind pub - !mnfind mn_pub_find
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
69 bind pub - !mnadd mn_pub_add
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
70 bind pub - !mndel mn_pub_del
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
71 bind pub - !mn mn_pub_get
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
72 bind msg - mnfind mn_msg_find
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
73 bind msg - mn mn_msg_get
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
74
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
75 proc mn_pub_get {unick uhost uhand uchan utext} { qdb_msg 0 $uchan "" [qdb_get "mndb" $unick $uhand $utext] }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
76 proc mn_msg_get {unick uhost uhand utext} { qdb_msg 0 $unick "" [qdb_get "mndb" $unick $uhand $utext] }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
77 proc mn_pub_add {unick uhost uhand uchan utext} { qdb_add "mndb" $utext $uhand $unick $uhost $uchan 1 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
78 proc mn_pub_del {unick uhost uhand uchan utext} { qdb_del "mndb" $utext $uhand $unick $uchan 1 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
79 proc mn_pub_find {unick uhost uhand uchan utext} { qdb_find "mndb" $unick $uhand $uchan $utext 1 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
80 proc mn_msg_find {unick uhost uhand utext} { qdb_find "mndb" $unick $uhand "" $utext 0 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
83 bind pub - !tuksufind tuksu_pub_find
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
84 bind pub - !tuksuadd tuksu_pub_add
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
85 bind pub - !tuksudel tuksu_pub_del
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
86 bind pub - !tuksu tuksu_pub_get
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
87 bind msg - tuksufind tuksu_msg_find
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
88 bind msg - tuksu tuksu_msg_get
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
89
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
90 proc tuksu_pub_get {unick uhost uhand uchan utext} { qdb_msg 0 $uchan "" [qdb_get "tuksudb" $unick $uhand $utext] }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
91 proc tuksu_msg_get {unick uhost uhand utext} { qdb_msg 0 $unick "" [qdb_get "tuksudb" $unick $uhand $utext] }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
92 proc tuksu_pub_add {unick uhost uhand uchan utext} { qdb_add "tuksudb" $utext $uhand $unick $uhost $uchan 1 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
93 proc tuksu_pub_del {unick uhost uhand uchan utext} { qdb_del "tuksudb" $utext $uhand $unick $uchan 1 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
94 proc tuksu_pub_find {unick uhost uhand uchan utext} { qdb_find "tuksudb" $unick $uhand $uchan $utext 1 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
95 proc tuksu_msg_find {unick uhost uhand utext} { qdb_find "tuksudb" $unick $uhand "" $utext 0 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 ### Initialization messages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 set qdb_message "$qdb_name v$qdb_version by ccr/TNSP"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 putlog "$qdb_message"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 ### Require packages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 package require sqlite3
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 ### SQLite database initialization
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 if {[catch {sqlite3 quotedb $qdb_file} uerrmsg]} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 putlog " Could not open SQLite3 database '$qdb_file': $uerrmsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 exit 2
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 ### Utility functions
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 proc qdb_log {jarg} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 global qdb_logmsg qdb_name
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 if {$qdb_logmsg != 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 putlog "$qdb_name: $jarg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 proc qdb_ctime {utime} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 if {$utime == "" || $utime == "*"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 set utime 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 return [clock format $utime -format "%d.%m.%Y %H:%M"]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 proc qdb_msg {apublic anick achan amsg} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 global qdb_preferredmsg
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 if {$apublic == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 putserv "$qdb_preferredmsg $anick :$amsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 putserv "$qdb_preferredmsg $achan :$anick, $amsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 proc qdb_escape {str} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 return [string map {' ''} $str]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
37
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
145 proc qdb_sql_exec { upublic unick uchan usql } {
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
146 global quotedb
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
147 if {[catch {quotedb eval $usql} uerrmsg]} {
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
148 qdb_log "$uerrmsg on SQL:\n$usql"
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
149 qdb_msg $upublic $unick $uchan "virhe sörkittäessä tietokantaa. uliskaa."
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
150 return 0
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
151 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
152 return 1
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
153 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
154
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 #-------------------------------------------------------------------------
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
157 proc qdb_add {utable utext uhand unick uhost uchan upublic} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 global quotedb
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
160 if {"x$utext" == "x" || "$uhand" == "x" || $uhand == {}} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 qdb_msg $upublic $unick $uchan "pyh."
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
165 set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[qdb_escape $utext]', '[qdb_escape $uhand]', '[qdb_escape $uhost]', '[qdb_escape $uchan]')"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 if {[catch {quotedb eval $usql} uerrmsg]} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 qdb_log "$uerrmsg on SQL:\n$sql"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 qdb_msg $upublic $unick $uchan "virhe sörkittäessä tietokantaa. uliskaa."
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 set quoteID [quotedb last_insert_rowid]
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
173 set numQuotes 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
174 # set numQuotes [quotedb ]
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 ### Log some data
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
177 qdb_log "Added SPEDE #$quoteID ($unick/$uhand@$uchan): $utext"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 ### Report success to user
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
180 qdb_msg $upublic $unick $uchan "tietokantaa sörkitty (#$quoteID / $numQuotes), kiitos."
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 return 1
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 #-------------------------------------------------------------------------
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
186 proc qdb_del {utable utext uhand unick uchan upublic} {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
187 global quotedb qdb_max_deltime
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
188
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
189 if {"x$utext" == "x" || "$uhand" == "x" || $uhand == {}} {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
190 qdb_msg $upublic $unick $uchan "pyh."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
191 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
192 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
193
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
194 set maxdiff [expr $qdb_max_deltime * 60]
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
195
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
196 if {[regexp "(\[0-9\]+)" $utext umatch unum]} {
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
197 set quoteID $unum
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
198 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable WHERE id=$unum AND user='[qdb_escape $uhand]'"
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
199 } else {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
200 qdb_msg $upublic $unick $uchan "ID # annettava."
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
201 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
202 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
203
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
204 quotedb eval $usql {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
205 set udiff [expr [unixtime] - $utime]
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
206 if {$udiff < $maxdiff} {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
207 set usql "DELETE FROM $utable WHERE id=$quoteID AND user='[qdb_escape $uhand]'"
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
208 if {[catch {quotedb eval $usql} uerrmsg]} {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
209 qdb_log "$uerrmsg on SQL:\n$sql"
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
210 qdb_msg $upublic $unick $uchan "virhe sörkittäessä tietokantaa. uliskaa."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
211 } else {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
212 qdb_msg $upublic $unick $uchan "$utable ID #$quoteID poistettu."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
213 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
214 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
215 } else {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
216 qdb_msg $upublic $unick $uchan "$utable quote #$quoteID vanhempi kuin $qdb_max_deltime minuuttia, ei poisteta."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
217 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
218 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
219 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
220
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
221 qdb_msg $upublic $unick $uchan "#$quoteID ei löydy, tai se ei kuulu käyttäjälle '$uhand'."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
222 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
223
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
224
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
225 #-------------------------------------------------------------------------
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 proc qdb_get {utable unick uhand uindex} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 global quotedb
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable"
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
230 if {[regexp "(\[0-9\]+)" $uindex umatch unum]} {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
231 set usql "$usql WHERE id=$unum"
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
232 qdb_log "$unick/$uhand searched $utable #$unum"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 set usql "$usql ORDER BY RANDOM() LIMIT 1"
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
235 qdb_log "$unick/$uhand get random $utable"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 quotedb eval $usql {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 return "#${quoteID}: $utext ($uuser)"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 return "ei löydy."
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 proc qdb_find {utable unick uhand uchan utext upublic} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 global quotedb qdb_showmax_pub qdb_showmax_priv
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 if {$upublic == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 set ulimit $qdb_showmax_priv
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 set ulimit $qdb_showmax_pub
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 ### Parse the given command
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 qdb_log "$unick/$uhand/$uchan searched $utable: $utext"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 set ftokens [split $utext " "]
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
260 set fpatlist ""
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 foreach ftoken $ftokens {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 set fprefix [string range $ftoken 0 0]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 set fpattern [string range $ftoken 1 end]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 if {$fprefix == "-"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 lappend fpatlist "utext NOT LIKE '%[qdb_escape $fpattern]%'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 } elseif {$fprefix == "%"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 lappend fpatlist "user='[qdb_escape $fpattern]'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 } elseif {$fprefix == "@"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 # foo
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 lappend fpatlist "utext LIKE '%[qdb_escape $ftoken]%'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 }
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
275 if {[llength $fpatlist] > 0} {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
276 set fquery "WHERE [join $fpatlist " AND "]"
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
277 } else {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
278 set fquery ""
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
279 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 set uresults 0
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
282 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable $fquery ORDER BY utime DESC LIMIT $ulimit"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 quotedb eval $usql {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 incr uresults
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[qdb_ctime $utime])"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 if {$uresults == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 qdb_msg $upublic $unick $uchan "ei löydy."
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 # end of script