annotate quotedb.tcl @ 466:a8eb80bbffa5

quotedb: Add 'stats' command.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 09 May 2018 20:04:13 +0300
parents ba7ed8f6d2ab
children 32f0aba3ab9b
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 #
427
86f39989df4b quotedb: Bump copyright and version.
Matti Hamalainen <ccr@tnsp.org>
parents: 426
diff changeset
3 # QuoteDB v2.5 by Matti 'ccr' Hamalainen <ccr@tnsp.org>
86f39989df4b quotedb: Bump copyright and version.
Matti Hamalainen <ccr@tnsp.org>
parents: 426
diff changeset
4 # (C) Copyright 2003-2017 Tecnic Software productions (TNSP)
25
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
261
e82ae84408ca quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
11 ### The configuration should be in config.quotedb in same directory
e82ae84408ca quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
12 ### as this script. Or change the line below to point where ever
e82ae84408ca quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
13 ### you wish. See "config.quotedb.example" for an example config file.
e82ae84408ca quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
14 source [file dirname [info script]]/config.quotedb
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
293
42ba48d54324 quotedb: Use utillib string splitting.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
16 ### Required utillib.tcl
42ba48d54324 quotedb: Use utillib string splitting.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
17 source [file dirname [info script]]/utillib.tcl
42ba48d54324 quotedb: Use utillib string splitting.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
18
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
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 # No need to look below this line
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 set qdb_name "QuoteDB"
427
86f39989df4b quotedb: Bump copyright and version.
Matti Hamalainen <ccr@tnsp.org>
parents: 426
diff changeset
24 set qdb_version "2.5"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 ### Initialization messages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 set qdb_message "$qdb_name v$qdb_version by ccr/TNSP"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 putlog "$qdb_message"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 ### Require packages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 package require sqlite3
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 ### SQLite database initialization
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
35 if {[catch {sqlite3 qdb_handle $qdb_file} uerrmsg]} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 putlog " Could not open SQLite3 database '$qdb_file': $uerrmsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 exit 2
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 }
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
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 ### Utility functions
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 proc qdb_log {jarg} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 global qdb_logmsg qdb_name
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 if {$qdb_logmsg != 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 putlog "$qdb_name: $jarg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
426
84d3d7abeb8a Add utl_msg_do() function into utillib and refactor out similar things in quotedb and weather scripts.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
51 proc qdb_msg {apublic anick achan amsg {aargs {}}} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 global qdb_preferredmsg
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
53 set narg 1
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
54 foreach marg $aargs {
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
55 set amsg [string map [list "%$narg" $marg] $amsg]
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
56 incr narg
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
57 }
426
84d3d7abeb8a Add utl_msg_do() function into utillib and refactor out similar things in quotedb and weather scripts.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
58 utl_msg_do $qdb_preferredmsg $apublic $anick $achan $amsg
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
59 }
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
60
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
61
37
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
62 proc qdb_sql_exec { upublic unick uchan usql } {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
63 global qdb_handle qdb_msg_sql_error
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
64 if {[catch {qdb_handle eval $usql} uerrmsg]} {
37
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
65 qdb_log "$uerrmsg on SQL:\n$usql"
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
66 qdb_msg $upublic $unick $uchan $qdb_msg_sql_error
37
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
67 return 0
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
68 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
69 return 1
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
70 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
71
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
72 proc qdb_valid_user {upublic unick uchan uhand} {
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
73 global qdb_msg_invalid_user
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
74 if {$uhand == "" || $uhand == {}} {
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
75 qdb_msg $upublic $unick $uchan $qdb_msg_invalid_user
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
76 return 0
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
77 }
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
78 return 1
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
79 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
82 proc qdb_add {ucmd utable unick uhost uhand uchan utext upublic} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
83 global qdb_handle qdb_msg_add_success
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
85 if {![qdb_valid_user $upublic $unick $uchan $uhand]} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
89 if {$utext == "" || $utext == {}} {
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
90 qdb_msg $upublic $unick $uchan "$ucmd add <teksti>"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
91 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
92 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
93
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
94 set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[utl_escape $utext]', '[utl_escape $uhand]', '[utl_escape $uhost]', '[utl_escape $uchan]')"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
95 if {![qdb_sql_exec $upublic $unick $uchan $usql]} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 return 0
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
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
99 set quoteID [qdb_handle last_insert_rowid]
58
0da3461eb871 quotedb: Retrieving total number of quotes in the table does not seem to be working, so commenting out the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
100 # set numQuotes 0
0da3461eb871 quotedb: Retrieving total number of quotes in the table does not seem to be working, so commenting out the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
101 # set usql "SELECT count(*) AS numQuotes FROM $utable"
0da3461eb871 quotedb: Retrieving total number of quotes in the table does not seem to be working, so commenting out the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
102 # if {![qdb_sql_exec $upublic $unick $uchan $usql]} { return 0 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 ### Log some data
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
105 qdb_log "Added $utable #$quoteID ($unick/$uhand@$uchan): $utext"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 ### Report success to user
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
108 qdb_msg $upublic $unick $uchan $qdb_msg_add_success [list $utable $quoteID]
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 return 1
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 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
114 proc qdb_delete {ucmd utable unick uhand uchan utext upublic} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
115 global qdb_handle qdb_max_deltime qdb_msg_not_found
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
116
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
117 set maxdiff [expr $qdb_max_deltime * 60]
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
118
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
119 if {![qdb_valid_user $upublic $unick $uchan $uhand]} {
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
120 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
121 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
122
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
123 if {![regexp {^\s*([0-9]+)$} $utext umatch unum]} {
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
124 qdb_msg $upublic $unick $uchan "$ucmd del <id>"
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
125 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
126 }
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
127
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
128 set qoverride [matchattr $uhand n]
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
129 set usql "SELECT utime AS utime FROM $utable WHERE id=$unum"
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
130 if {$qoverride == 0} {
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
131 append usql " AND user='[utl_escape $uhand]'"
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
132 set qextra ""
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
133 } else {
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
134 set qextra " (owner/time override)"
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
135 }
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
136
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
137 qdb_handle eval $usql {
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
138 set udiff [expr [unixtime] - $utime]
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
139 if {$udiff < $maxdiff || $qoverride} {
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
140 set usql "DELETE FROM $utable WHERE id=$unum"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
141 if {![qdb_sql_exec $upublic $unick $uchan $usql]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
142 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
143 } else {
59
415c47fcc518 quotedb: Cleanups. We do not need to SELECT quoteID for these operations, we already know what it is.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
144 set usql "DELETE FROM ${utable}_votes WHERE urlid=$unum"
43
965b728c2a9d Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
145 if {![qdb_sql_exec $upublic $unick $uchan $usql]} {
965b728c2a9d Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
146 return 0
965b728c2a9d Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
147 }
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
148 qdb_msg $upublic $unick $uchan "$utable #$unum poistettu$qextra."
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
149 return 1
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
150 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
151 } else {
59
415c47fcc518 quotedb: Cleanups. We do not need to SELECT quoteID for these operations, we already know what it is.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
152 qdb_msg $upublic $unick $uchan "$utable quote #$unum vanhempi kuin $qdb_max_deltime minuuttia, ei poisteta."
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
153 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
154 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
155 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
156
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
157 qdb_msg $upublic $unick $uchan $qdb_msg_not_found [list $utable $unum $uhand]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
158 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
159 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
160
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
161
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
162 #-------------------------------------------------------------------------
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
163 proc qdb_update {ucmd utable unick uhand uchan utext upublic} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
164 global qdb_handle qdb_max_modtime qdb_msg_update_override
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
165 global qdb_msg_update_ok qdb_msg_update_too_old qdb_msg_not_found
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
166
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
167 set maxdiff [expr $qdb_max_modtime * 60]
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
168
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
169 if {![qdb_valid_user $upublic $unick $uchan $uhand]} {
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
170 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
171 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
172
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
173 if {![regexp {^\s*([0-9]+)\s+(.+)$} $utext umatch unum uquote]} {
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
174 qdb_msg $upublic $unick $uchan "$ucmd update <id> <teksti>"
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
175 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
176 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
177
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
178 set qoverride [matchattr $uhand n]
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
179 set usql "SELECT utime AS utime FROM $utable WHERE id=$unum"
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
180 if {$qoverride == 0} {
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
181 append usql " AND user='[utl_escape $uhand]'"
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
182 set qextra ""
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
183 } else {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
184 set qextra $qdb_msg_update_override
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
185 }
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
186
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
187 qdb_handle eval $usql {
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
188 set udiff [expr [unixtime] - $utime]
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
189 if {$udiff < $maxdiff || $qoverride} {
459
6acd372d36da quotedb: Do not update quote creation timestamp field when updating quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 439
diff changeset
190 set usql "UPDATE $utable SET utext='[utl_escape $uquote]' WHERE id=$unum"
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
191 if {![qdb_sql_exec $upublic $unick $uchan $usql]} {
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
192 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
193 } else {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
194 qdb_msg $upublic $unick $uchan $qdb_msg_update_ok [list $utable $unum $qextra]
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
195 return 1
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
196 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
197 } else {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
198 qdb_msg $upublic $unick $uchan $qdb_msg_update_too_old [list $utable $unum $qdb_max_modtime]
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
199 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
200 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
201 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
202
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
203 qdb_msg $upublic $unick $uchan $qdb_msg_not_found [list $utable $unum $uhand]
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
204 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
205 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
206
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
207
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
208 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
209 proc qdb_toplist {ucmd utable unick uchan unum upublic} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
210 global qdb_handle qdb_msg_toplist_limit qdb_msg_toplist_fmt
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
211
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
212 if {$unum < 2 || $unum > 5} {
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
213 qdb_msg $upublic $unick $uchan $qdb_msg_toplist_limit [list 2 5]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
214 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
215 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
216
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
217 set uresults 0
44
f0694e61ae45 Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
218 set usql "SELECT total(${utable}_votes.vote) AS rating, ${utable}.id AS quoteID, ${utable}.utext AS utext, ${utable}.utime AS utime,${utable}.user AS uuser, ${utable}.id AS uid FROM ${utable}_votes INNER JOIN $utable ON ${utable}_votes.urlid = ${utable}.id GROUP BY ${utable}.id ORDER BY rating DESC LIMIT $unum"
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
219 qdb_handle eval $usql {
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
220 incr uresults
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
221 qdb_msg $upublic $unick $uchan $qdb_msg_toplist_fmt [list $uresults $quoteID $utext $uuser $rating]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
222 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
223
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
224 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
225 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
226
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
227
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
228 #-------------------------------------------------------------------------
439
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
229 proc qdb_get_rating_for_id {utable uid} {
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
230 set usql "SELECT total(${utable}_votes.vote) AS qrating FROM ${utable}_votes WHERE urlid=${uid}"
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
231 set qrating 0
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
232 qdb_handle eval $usql { set urating $qrating }
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
233 return $qrating
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
234 }
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
235
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
236
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
237 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
238 proc qdb_vote {ucmd utable unick uhand uchan utext upublic} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
239 global qdb_handle qdb_msg_you_voted qdb_msg_quote_does_not_exist qdb_msg_vote_updated
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
240
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
241 if {![qdb_valid_user $upublic $unick $uchan $uhand]} {
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
242 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
243 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
244
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
245 set uvote 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
246 if {$utext == "" || [regexp {^\s*-1$} $utext umatch uvote]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
247 set usql "SELECT max(id) AS qid FROM ${utable}"
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
248 set uid 0
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
249 qdb_handle eval $usql { set uid $qid }
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
250 } elseif {[regexp {^\s*([0-9]+)$} $utext umatch uid]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
251 } elseif {![regexp {^\s*([0-9]+)\s+(-1|1)$} $utext umatch uid uvote]} {
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
252 qdb_msg $upublic $unick $uchan "$ucmd vote \[<id> \[1|-1\]\]"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
253 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
254 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
255
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
256 # Check if given quote ID exists.
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
257 set uresults 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
258 set usql "SELECT id AS qid FROM ${utable} WHERE id=$uid"
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
259 qdb_handle eval $usql { incr uresults }
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
260 if {$uresults == 0} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
261 qdb_msg $upublic $unick $uchan $qdb_msg_quote_does_not_exist [list $uid]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
262 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
263 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
264
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
265 # Check if user has previously voted this item
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
266 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[utl_escape $uhand]' AND urlid=$uid"
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
267 qdb_handle eval $usql {
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
268 # Yes, update the previous vote
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
269 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid"
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
270 if {[qdb_sql_exec $upublic $unick $uchan $usql]} {
439
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
271 set urating [qdb_get_rating_for_id $utable $uid]
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
272 qdb_log "$uhand changed vote to $uvote on #$uid / $utable, total $urating"
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
273 qdb_msg $upublic $unick $uchan $qdb_msg_vote_updated [list $uid $uvote $urating]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
274 return 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
275 } else {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
276 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
277 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
278 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
279
148
2f0c823386b0 quotedb: Simplify a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
280 # No previous votes, insert new
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
281 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)"
148
2f0c823386b0 quotedb: Simplify a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
282 if {[qdb_sql_exec $upublic $unick $uchan $usql]} {
439
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
283 set urating [qdb_get_rating_for_id $utable $uid]
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
284 qdb_log "$uhand voted $uvote on #$uid / $utable, total $urating"
ac66900fd066 quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
285 qdb_msg $upublic $unick $uchan $qdb_msg_you_voted [list $uid $uvote $urating]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
286 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
287 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
288
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
289
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
290 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
291 proc qdb_get {ucmd utable unick uchan uindex upublic} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
292 global qdb_handle qdb_msg_no_matches
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
293
149
fc2654064339 quotedb: Show quote addition date.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
294 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"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
295 if {$uindex >= 0} {
66
140f0492dcd3 quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
296 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
297 qdb_log "$unick searched $utable #$uindex"
465
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
298 } elseif {$uindex == -1} {
66
140f0492dcd3 quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
299 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
300 qdb_log "$unick get random $utable"
465
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
301 } elseif {$uindex == -2} {
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
302 append usql " GROUP BY ${utable}.id ORDER BY ${utable}.id DESC LIMIT 1"
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
303 qdb_log "$unick get latest $utable"
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
304 } else {
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
305 qdb_log "$unick invalid qdb_get $utable index value."
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
306 return 0
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
309 qdb_handle eval $usql {
426
84d3d7abeb8a Add utl_msg_do() function into utillib and refactor out similar things in quotedb and weather scripts.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
310 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)"
48
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
311 return 1
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 }
48
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
313
288
135e6c628164 quotedb: Add nick to parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 283
diff changeset
314 qdb_msg $upublic $unick $uchan $qdb_msg_no_matches [list $unick]
48
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
315 return 0
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 #-------------------------------------------------------------------------
466
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
320 proc qdb_stats {ucmd utable unick uchan upublic} {
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
321 global qdb_handle
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
322
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
323 set usql "SELECT count(*) AS nvotes FROM ${utable}_votes"
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
324 qdb_handle eval $usql {}
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
325
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
326 set usql "SELECT count(*) AS nquotes FROM ${utable}"
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
327 qdb_handle eval $usql {}
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
328
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
329 qdb_msg $upublic $unick $uchan "${utable}-tilastot: ${nquotes} quotea, ${nvotes} annettua ääntä."
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
330 return 0
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
331 }
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
332
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
333
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
334 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
335 proc qdb_find {ucmd utable unick uhand uchan utext upublic} {
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
336 global qdb_handle qdb_showmax_pub qdb_showmax_priv qdb_msg_no_matches qdb_msg_search_fmt
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 if {$upublic == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 set ulimit $qdb_showmax_priv
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 set ulimit $qdb_showmax_pub
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 ### Parse the given command
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 qdb_log "$unick/$uhand/$uchan searched $utable: $utext"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 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
348 set fpatlist ""
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 foreach ftoken $ftokens {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 set fprefix [string range $ftoken 0 0]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 set fpattern [string range $ftoken 1 end]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 if {$fprefix == "-"} {
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
354 lappend fpatlist "utext NOT LIKE '%[utl_escape $fpattern]%'"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 } elseif {$fprefix == "%"} {
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
356 lappend fpatlist "user LIKE '[utl_escape $fpattern]'"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 } elseif {$fprefix == "@"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 # foo
109
74cb254dbf09 urllog and quotedb: Handle "+"-prefix in searches as it is documented.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
359 } elseif {$fprefix == "+"} {
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
360 lappend fpatlist "utext LIKE '%[utl_escape $fpattern]%'"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 } else {
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
362 lappend fpatlist "utext LIKE '%[utl_escape $ftoken]%'"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 }
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
365 if {[llength $fpatlist] > 0} {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
366 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
367 } else {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
368 set fquery ""
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
369 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
371 ### Query the database and output results
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 set uresults 0
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
373 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser FROM $utable $fquery ORDER BY utime DESC LIMIT $ulimit"
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
374 qdb_handle eval $usql {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 incr uresults
422
880a07485275 Add utl_ctime() to utillib and use it elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
376 qdb_msg $upublic $unick $uchan $qdb_msg_search_fmt [list $quoteID $utext $uuser $utime [utl_ctime $utime]]
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 }
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
378
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 if {$uresults == 0} {
288
135e6c628164 quotedb: Add nick to parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 283
diff changeset
380 qdb_msg $upublic $unick $uchan $qdb_msg_no_matches [list $unick]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
381 return 0
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 }
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
383 return 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
384 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
385
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
386
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
387 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
388 proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic} {
346
329ceff76d0c qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 309
diff changeset
389 global qdb_msg_help qdb_channels
329ceff76d0c qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 309
diff changeset
390
329ceff76d0c qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 309
diff changeset
391 if {$upublic && ![utl_match_delim_list $qdb_channels $uchan]} {
329ceff76d0c qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 309
diff changeset
392 return 0
329ceff76d0c qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 309
diff changeset
393 }
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
394
54
301df7d15861 quotedb: Using [join utext " "] on command input string is harmful. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
395 set utext [string trim $utext]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
396
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
397 if {$utext == "" || $utext == {}} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
398 # No arguments, assume random query
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
399 qdb_get $ucmd $utable $unick $uchan -1 $upublic
466
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
400 } elseif {[regexp {^(stat|stats|tilasto|tilastot)$} $utext umatch]} {
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
401 # Statistics
a8eb80bbffa5 quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
402 qdb_stats $ucmd $utable $unick $uchan $upublic
465
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
403 } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} {
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
404 # Latest added
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
405 qdb_get $ucmd $utable $unick $uchan -2 $upublic
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
406 } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
407 # Numeric argument, assume index query
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
408 qdb_get $ucmd $utable $unick $uchan $unum $upublic
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
409 } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
410 # Toplist of quotes
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
411 qdb_toplist $ucmd $utable $unick $uchan $unum $upublic
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
412 } elseif {[regexp {^add\s*(.*)$} $utext umatch unum]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
413 # Add quote
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
414 qdb_add $ucmd $utable $unick $uhost $uhand $uchan $unum $upublic
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
415 } elseif {[regexp {^del\s*([0-9]*)$} $utext umatch unum]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
416 # Delete quote
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
417 qdb_delete $ucmd $utable $unick $uhand $uchan $unum $upublic
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
418 } elseif {[regexp {^update\s*(.*)$} $utext umatch unum]} {
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
419 # Modify/update quote
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
420 qdb_update $ucmd $utable $unick $uhand $uchan $unum $upublic
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
421 } elseif {[regexp {^find\s*(.*)$} $utext umatch unum]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
422 # Find quote(s)
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
423 qdb_find $ucmd $utable $unick $uhand $uchan $unum $upublic
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
424 } elseif {[regexp {^vote\s*(.*)$} $utext umatch unum]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
425 # Vote
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
426 qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
427 } else {
465
ba7ed8f6d2ab quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
428 # Help/usage
283
5b997bee1745 quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
429 qdb_msg $upublic $unick $uchan $qdb_msg_help [list $ucmd]
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
430 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 # end of script