Mercurial > hg > egg-tcls
annotate quotedb.tcl @ 698:6ba9f961e463 default tip
quotedb: Bump version and copyright.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 18 Sep 2023 11:38:41 +0300 |
parents | 14d4d4300623 |
children |
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 # |
698
6ba9f961e463
quotedb: Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
697
diff
changeset
|
3 # QuoteDB v2.7.2 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
6ba9f961e463
quotedb: Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
697
diff
changeset
|
4 # (C) Copyright 2003-2023 Tecnic Software productions (TNSP) |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 # |
500
f31cb0b7d0c0
quotedb: Adjust the note in the script header blurb, update copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
482
diff
changeset
|
6 # This script was made for my own use, any questions about it or any |
f31cb0b7d0c0
quotedb: Adjust the note in the script header blurb, update copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
482
diff
changeset
|
7 # problems you may have with it can be sent to /dev/null. |
f31cb0b7d0c0
quotedb: Adjust the note in the script header blurb, update copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
482
diff
changeset
|
8 # |
f31cb0b7d0c0
quotedb: Adjust the note in the script header blurb, update copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
482
diff
changeset
|
9 # This script is freely distributable under GNU GPL (version 2) license. |
25
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 |
261
e82ae84408ca
quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
13 ### 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
|
14 ### 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
|
15 ### 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
|
16 source [file dirname [info script]]/config.quotedb |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
293
42ba48d54324
quotedb: Use utillib string splitting.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
18 ### Required utillib.tcl |
42ba48d54324
quotedb: Use utillib string splitting.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
19 source [file dirname [info script]]/utillib.tcl |
42ba48d54324
quotedb: Use utillib string splitting.
Matti Hamalainen <ccr@tnsp.org>
parents:
288
diff
changeset
|
20 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 |
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 # No need to look below this line |
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 package require sqlite3 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
559 | 27 set qdb_name "QuoteDB" |
698
6ba9f961e463
quotedb: Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
697
diff
changeset
|
28 set qdb_message "$qdb_name v2.7.2 (C) 2003-2023 ccr/TNSP" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
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 #------------------------------------------------------------------------- |
556
e310d223dd12
quotedb: Rename a function argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
550
diff
changeset
|
32 proc qdb_log {umsg} { |
550
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
33 global qdb_log_enable qdb_name |
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
34 if {$qdb_log_enable != 0} { |
595 | 35 putlog "${qdb_name}: $umsg" |
25
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 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
39 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
40 proc qdb_qm {utable uid} { |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
41 global qdb_messages |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
42 set qid "${utable}_${uid}" |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
43 |
648 | 44 # Check if table-specific message exists |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
45 if {[info exists qdb_messages($qid)]} { |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
46 return $qdb_messages($qid) |
648 | 47 # Check if generic message exists |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
48 } elseif {[info exists qdb_messages($uid)]} { |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
49 return $qdb_messages($uid) |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
50 } else { |
648 | 51 # Nothing .. return id string |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
52 return $uid |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
53 } |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
54 } |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
55 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
56 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
57 proc qdb_msg {acmd atable apublic anick achan aid {aargs {}}} { |
529
3046ee0e574d
quotedb: Use utillib version of the function.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
58 global qdb_preferredmsg |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
59 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
60 # Get message |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
61 set amsg [qdb_qm $atable $aid] |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
62 set aname [qdb_qm $atable "name"] |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
63 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
64 # Map constant tokens |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
65 set amsg [string map [list "@cmd@" $acmd] $amsg] |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
66 set amsg [string map [list "@name@" $aname] $amsg] |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
67 |
529
3046ee0e574d
quotedb: Use utillib version of the function.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
68 utl_msg_args $qdb_preferredmsg $apublic $anick $achan $amsg $aargs |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
69 } |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
70 |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
71 |
683
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
72 proc qdb_ctime {ustamp} { |
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
73 if {$ustamp == "" || $ustamp == "*"} { |
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
74 set ustamp 0 |
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
75 } |
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
76 return [clock format $ustamp -format "%d.%m.%Y"] |
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
77 } |
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
78 |
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
79 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
80 proc qdb_sql_exec {ucmd utable upublic unick uchan usql} { |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
81 global qdb_handle |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
82 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
|
83 qdb_log "$uerrmsg on SQL:\n$usql" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
84 qdb_msg $ucmd $utable $upublic $unick $uchan "sql_error" |
37
c3c597cac4b6
Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
85 return 0 |
c3c597cac4b6
Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
86 } |
c3c597cac4b6
Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
87 return 1 |
c3c597cac4b6
Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
88 } |
c3c597cac4b6
Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
89 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
90 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
91 proc qdb_valid_user {ucmd utable upublic unick uchan uhand} { |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
92 if {$uhand == "" || $uhand == {}} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
93 qdb_msg $ucmd $utable $upublic $unick $uchan "invalid_user" |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
94 return 0 |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
95 } |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
96 return 1 |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
97 } |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
99 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
100 proc qdb_get_rating_for_id {utable uid} { |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
101 set usql "SELECT total(${utable}_votes.vote) AS qrating FROM ${utable}_votes WHERE urlid=${uid}" |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
102 set qrating 0 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
103 qdb_handle eval $usql { set urating $qrating } |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
104 return $qrating |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
105 } |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
106 |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
107 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 #------------------------------------------------------------------------- |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
109 proc qdb_add {ucmd utable upublic unick uhost uhand uchan uargs} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
110 global qdb_handle |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
112 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 return 0 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
116 if {$uargs == "" || $uargs == {}} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
117 qdb_msg $ucmd $utable $upublic $unick $uchan "help_add" |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
118 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
119 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
120 |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
121 set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[utl_escape $uargs]', '[utl_escape $uhand]', '[utl_escape $uhost]', '[utl_escape $uchan]')" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
122 if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 return 0 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
126 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
|
127 # 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
|
128 # set usql "SELECT count(*) AS numQuotes FROM $utable" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
129 # if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { return 0 } |
25
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 ### Log some data |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
132 qdb_log "Added ${utable} #${quoteID} (${unick}/${uhand}@${uchan}): ${uargs}" |
25
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 ### Report success to user |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
135 qdb_msg $ucmd $utable $upublic $unick $uchan "add_success" [list $quoteID] |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 return 1 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 } |
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 #------------------------------------------------------------------------- |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
141 proc qdb_delete {ucmd utable upublic unick uhost uhand uchan uargs} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
142 global qdb_handle qdb_max_deltime |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
143 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
144 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
|
145 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
146 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
147 return 0 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
148 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
149 |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
150 if {![regexp {^\s*([0-9]+)$} $uargs -> unum]} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
151 qdb_msg $ucmd $utable $upublic $unick $uchan "help_delete" |
27
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
152 return 0 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
153 } |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
154 |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
155 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
|
156 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
|
157 if {$qoverride == 0} { |
667
88d0e2ba73ca
quotedb: Use LIKE instead of = for user.
Matti Hamalainen <ccr@tnsp.org>
parents:
653
diff
changeset
|
158 append usql " AND user LIKE '[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
|
159 set qextra "" |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
160 } else { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
161 set qextra [qdb_qm $utable "update_override"] |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
162 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
163 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
164 qdb_handle eval $usql { |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
165 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
|
166 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
|
167 set usql "DELETE FROM $utable WHERE id=$unum" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
168 if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
169 return 0 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
170 } 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
|
171 set usql "DELETE FROM ${utable}_votes WHERE urlid=$unum" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
172 if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { |
43
965b728c2a9d
Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
173 return 0 |
965b728c2a9d
Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
174 } |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
175 qdb_msg $ucmd $utable $upublic $unick $uchan "quote_deleted" [list $unum $qextra] |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
176 return 1 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
177 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
178 } else { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
179 qdb_msg $ucmd $utable $upublic $unick $uchan "quote_too_old" [list $unum $qdb_max_deltime] |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
180 return 0 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
181 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
182 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
183 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
184 qdb_msg $ucmd $utable $upublic $unick $uchan "quote_not_found" [list $unum $uhand] |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
185 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
186 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
187 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
188 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
189 #------------------------------------------------------------------------- |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
190 proc qdb_update {ucmd utable upublic unick uhost uhand uchan uargs} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
191 global qdb_handle qdb_max_modtime |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
192 |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
193 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
|
194 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
195 if {![qdb_valid_user $ucmd $utable $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
|
196 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
197 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
198 |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
199 if {![regexp {^\s*([0-9]+)\s+(.+)$} $uargs -> unum uquote]} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
200 qdb_msg $ucmd $utable $upublic $unick $uchan "help_update" |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
201 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
202 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
203 |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
204 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
|
205 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
|
206 if {$qoverride == 0} { |
667
88d0e2ba73ca
quotedb: Use LIKE instead of = for user.
Matti Hamalainen <ccr@tnsp.org>
parents:
653
diff
changeset
|
207 append usql " AND user LIKE '[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
|
208 set qextra "" |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
209 } else { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
210 set qextra [qdb_qm $utable "update_override"] |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
211 } |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
212 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 set usql "UPDATE $utable SET utext='[utl_escape $uquote]' WHERE id=$unum" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
217 if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
218 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
219 } else { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
220 qdb_msg $ucmd $utable $upublic $unick $uchan "update_ok" [list $unum $qextra] |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
221 return 1 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
222 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
223 } else { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
224 qdb_msg $ucmd $utable $upublic $unick $uchan "update_too_old" [list $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
|
225 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
226 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
227 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
228 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
229 qdb_msg $ucmd $utable $upublic $unick $uchan "quote_not_found" [list $unum $uhand] |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
230 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
231 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
232 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
233 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
234 #------------------------------------------------------------------------- |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
235 proc qdb_toplist {ucmd utable upublic unick uhost uhand uchan uargs unum} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
236 global qdb_handle |
508
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
237 global qdb_toplist_min qdb_toplist_max |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
238 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
239 if {$unum == {} || $unum == ""} { |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
240 set unum $qdb_toplist_min |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
241 } |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
242 |
508
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
243 if {$unum < $qdb_toplist_min || $unum > $qdb_toplist_max} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
244 qdb_msg $ucmd $utable $upublic $unick $uchan "toplist_limit" [list $qdb_toplist_min $qdb_toplist_max] |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
245 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
246 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
247 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
248 set uresults 0 |
44
f0694e61ae45
Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
249 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
|
250 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
|
251 incr uresults |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
252 qdb_msg $ucmd $utable $upublic $unick $uchan "fmt_toplist" [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
|
253 } |
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 return 0 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
256 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
257 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
258 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
259 #------------------------------------------------------------------------- |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
260 proc qdb_vote {ucmd utable upublic unick uhost uhand uchan uargs} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
261 global qdb_handle |
439
ac66900fd066
quotedb: Add display of current quote rating when voting for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
262 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
263 if {![qdb_valid_user $ucmd $utable $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
|
264 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
265 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
266 |
684
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
267 set qvote "+" |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
268 if {$uargs == "" || [regexp {^\s*(\+|\-)\s*$} $uargs -> qvote]} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
269 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
|
270 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
|
271 qdb_handle eval $usql { set uid $qid } |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
272 } elseif {[regexp {^\s*([0-9]+)$} $uargs -> uid]} { |
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
273 } elseif {![regexp {^\s*([0-9]+)\s+(\+|\-)$} $uargs -> uid qvote]} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
274 qdb_msg $ucmd $utable $upublic $unick $uchan "help_vote" |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
275 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
276 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
277 |
684
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
278 if {$qvote == "-"} { |
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
279 set qvote [qdb_qm $utable "vote_down"] |
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
280 set uvote -1 |
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
281 } else { |
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
282 set qvote [qdb_qm $utable "vote_up"] |
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
283 set uvote 1 |
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
284 } |
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
285 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
286 # 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
|
287 set uresults 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
288 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
|
289 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
|
290 if {$uresults == 0} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
291 qdb_msg $ucmd $utable $upublic $unick $uchan "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
|
292 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
293 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
294 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
295 # Check if user has previously voted this item |
667
88d0e2ba73ca
quotedb: Use LIKE instead of = for user.
Matti Hamalainen <ccr@tnsp.org>
parents:
653
diff
changeset
|
296 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user LIKE '[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
|
297 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
|
298 # 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
|
299 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
300 if {[qdb_sql_exec $ucmd $utable $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
|
301 set urating [qdb_get_rating_for_id $utable $uid] |
670 | 302 qdb_log "${uhand} changed vote to ${uvote} on #${uid} / ${utable}, total ${urating}" |
684
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
303 qdb_msg $ucmd $utable $upublic $unick $uchan "vote_updated" [list $uid $qvote $urating] |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
304 return 1 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
305 } else { |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
306 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
307 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
308 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
309 |
148 | 310 # No previous votes, insert new |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
311 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)" |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
312 if {[qdb_sql_exec $ucmd $utable $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
|
313 set urating [qdb_get_rating_for_id $utable $uid] |
670 | 314 qdb_log "${uhand} voted ${uvote} on #${uid} / ${utable}, total ${urating}" |
684
5163d582e396
quotedb: Change voting a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
683
diff
changeset
|
315 qdb_msg $ucmd $utable $upublic $unick $uchan "you_voted" [list $uid $qvote $urating] |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
316 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
317 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
318 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
319 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
320 #------------------------------------------------------------------------- |
671
3904fcfeeb9a
quotedb: Rename qdb_get() to qdb_show() and remove extraneous unused argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
670
diff
changeset
|
321 proc qdb_show {ucmd utable upublic unick uhost uhand uchan uindex} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
322 global qdb_handle |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
323 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
324 set usql "SELECT total(${utable}_votes.vote) AS uvote, ${utable}.id AS quoteID, ${utable}.utext AS uquote, ${utable}.utime AS utime, ${utable}.user AS uuser FROM ${utable} LEFT JOIN ${utable}_votes ON ${utable}_votes.urlid = ${utable}.id" |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
325 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
326 if {$uindex >= 0} { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
327 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id" |
670 | 328 qdb_log "${unick} searched ${utable} #${uindex}" |
465
ba7ed8f6d2ab
quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents:
459
diff
changeset
|
329 } elseif {$uindex == -1} { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
330 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1" |
670 | 331 qdb_log "${unick} get random ${utable}" |
465
ba7ed8f6d2ab
quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents:
459
diff
changeset
|
332 } elseif {$uindex == -2} { |
ba7ed8f6d2ab
quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents:
459
diff
changeset
|
333 append usql " GROUP BY ${utable}.id ORDER BY ${utable}.id DESC LIMIT 1" |
670 | 334 qdb_log "${unick} get latest ${utable}" |
465
ba7ed8f6d2ab
quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents:
459
diff
changeset
|
335 } else { |
670 | 336 qdb_log "${unick} invalid qdb_show ${utable} index value." |
465
ba7ed8f6d2ab
quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents:
459
diff
changeset
|
337 return 0 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
340 set urlprefix [qdb_qm $utable "urlprefix"] |
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
341 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
342 qdb_handle eval $usql { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
343 if {[string range $uquote 0 3] == "img:"} { |
672 | 344 set uquote "${urlprefix}[string range $uquote 4 end]" |
482
0e50c8440ea2
quotedb: Add img: image URL support.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
345 } |
683
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
346 qdb_msg $ucmd $utable $upublic $unick $uchan "fmt_get" [list $quoteID $uquote $uuser [qdb_ctime $utime] $uvote] |
48
506ce7f074e4
Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
347 return 1 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 } |
48
506ce7f074e4
Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
349 |
516
4995ee3a95db
quotedb: Adjust some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
514
diff
changeset
|
350 qdb_msg $ucmd $utable $upublic $unick $uchan "quote_does_not_exist" [list $uindex] |
48
506ce7f074e4
Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
351 return 0 |
25
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 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 #------------------------------------------------------------------------- |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
356 proc qdb_stats {ucmd utable upublic unick uhost uhand uchan uargs} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
357 global qdb_handle |
466
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
358 |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
359 set usql "SELECT count(*) AS nvotes FROM ${utable}_votes" |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
360 qdb_handle eval $usql {} |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
361 |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
362 set usql "SELECT count(*) AS nquotes FROM ${utable}" |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
363 qdb_handle eval $usql {} |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
364 |
508
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
365 set nmaxtop 5 |
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
366 |
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
367 set usql "SELECT user,count(*) AS uquotes FROM ${utable} GROUP BY user ORDER BY uquotes DESC LIMIT ${nmaxtop}" |
519
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
368 set ltopusers {} |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
369 set ntopusers 0 |
508
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
370 qdb_handle eval $usql { |
519
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
371 incr ntopusers |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
372 lappend ltopusers "${user} (${uquotes})" |
508
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
373 } |
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
374 |
519
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
375 set nmaxtop 3 |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
376 |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
377 set usql "SELECT count(*) AS uquotes,CAST(strftime('%Y',utime,'unixepoch') AS integer) AS uyear FROM ${utable} GROUP BY uyear ORDER BY uyear DESC LIMIT ${nmaxtop}" |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
378 set llatestyears {} |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
379 set nlatestyears 0 |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
380 qdb_handle eval $usql { |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
381 incr nlatestyears |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
382 lappend llatestyears "${uquotes} (${uyear})" |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
383 } |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
384 |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
385 set usql "SELECT count(*) AS uquotes,CAST(strftime('%Y',utime,'unixepoch') AS integer) AS uyear FROM ${utable} GROUP BY uyear ORDER BY uquotes DESC LIMIT ${nmaxtop}" |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
386 set ltopeyears {} |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
387 set ntopyears 0 |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
388 qdb_handle eval $usql { |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
389 incr ntopyears |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
390 lappend ltopeyears "${uquotes} (${uyear})" |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
391 } |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
392 |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
393 qdb_msg $ucmd $utable $upublic $unick $uchan "stats" [list $nquotes $nvotes] |
1cfa567f9500
quotedb: Improve statistics.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
394 qdb_msg $ucmd $utable $upublic $unick $uchan "stats2" [list $ntopusers [join $ltopusers ", "] $nlatestyears [join $llatestyears ", "] $ntopyears [join $ltopeyears ", "]] |
508
3fc74204dd8b
quotedb: Add new information in statistics sub-command.
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
395 |
466
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
396 return 0 |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
397 } |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
398 |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
399 |
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
400 #------------------------------------------------------------------------- |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
401 proc qdb_find {ucmd utable upublic unick uhost uhand uchan uargs} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
402 global qdb_handle qdb_showmax_pub qdb_showmax_priv |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
404 # Limit results based on public/private |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 if {$upublic == 0} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 set ulimit $qdb_showmax_priv |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 } else { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 set ulimit $qdb_showmax_pub |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 ### Parse the given command |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
412 qdb_log "${unick}/${uhand}/${uchan} searched ${utable}: '${uargs}'" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 |
668 | 414 set fpatlist {} |
694
bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
684
diff
changeset
|
415 set ftokens [::textutil::split::splitx $uargs {\s+}] |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 foreach ftoken $ftokens { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 set fprefix [string range $ftoken 0 0] |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 set fpattern [string range $ftoken 1 end] |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 if {$fprefix == "-"} { |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
421 lappend fpatlist "utext NOT LIKE '%[utl_escape $fpattern]%'" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 } elseif {$fprefix == "%"} { |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
423 lappend fpatlist "user LIKE '[utl_escape $fpattern]'" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
424 } elseif {$fprefix == "@"} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
425 # foo |
109
74cb254dbf09
urllog and quotedb: Handle "+"-prefix in searches as it is documented.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
426 } elseif {$fprefix == "+"} { |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
427 lappend fpatlist "utext LIKE '%[utl_escape $fpattern]%'" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
428 } else { |
295
141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
429 lappend fpatlist "utext LIKE '%[utl_escape $ftoken]%'" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 } |
517
894bc9632ece
quotedb: Check if any search parameters have been given, error out if not.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
432 |
894bc9632ece
quotedb: Check if any search parameters have been given, error out if not.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
433 # Check if any arguments exist |
894bc9632ece
quotedb: Check if any search parameters have been given, error out if not.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
434 if {[llength $fpatlist] == 0} { |
518
7fdc069840cc
quotedb: Show help instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
517
diff
changeset
|
435 qdb_msg $ucmd $utable $upublic $unick $uchan "help_find" |
517
894bc9632ece
quotedb: Check if any search parameters have been given, error out if not.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
436 return 0 |
27
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
437 } |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 |
517
894bc9632ece
quotedb: Check if any search parameters have been given, error out if not.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
439 set fquery "WHERE [join $fpatlist " AND "]" |
894bc9632ece
quotedb: Check if any search parameters have been given, error out if not.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
440 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
441 ### Query the database and output results |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 set uresults 0 |
697
14d4d4300623
quotedb: When searching quotes, inform user if we found more matches than the max matches limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
694
diff
changeset
|
443 set usql "SELECT count(*) AS uresults FROM $utable $fquery" |
14d4d4300623
quotedb: When searching quotes, inform user if we found more matches than the max matches limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
694
diff
changeset
|
444 qdb_handle eval $usql {} |
14d4d4300623
quotedb: When searching quotes, inform user if we found more matches than the max matches limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
694
diff
changeset
|
445 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
446 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
|
447 qdb_handle eval $usql { |
683
7897b795480b
quotedb: Use custon qdb_ctime() instead of utl_ctime() for shorter timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
675
diff
changeset
|
448 qdb_msg $ucmd $utable $upublic $unick $uchan "fmt_search" [list $quoteID $utext $uuser [qdb_ctime $utime]] |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
450 |
697
14d4d4300623
quotedb: When searching quotes, inform user if we found more matches than the max matches limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
694
diff
changeset
|
451 if {$uresults > $ulimit} { |
14d4d4300623
quotedb: When searching quotes, inform user if we found more matches than the max matches limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
694
diff
changeset
|
452 qdb_msg $ucmd $utable $upublic $unick $uchan "num_matches" [list $uresults $ulimit] |
14d4d4300623
quotedb: When searching quotes, inform user if we found more matches than the max matches limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
694
diff
changeset
|
453 } elseif {$uresults == 0} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
454 qdb_msg $ucmd $utable $upublic $unick $uchan "no_matches" |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
455 return 0 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
456 } |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
457 return 1 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
458 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
459 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
460 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
461 #------------------------------------------------------------------------- |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
462 proc qdb_cmd {ucmd utable unick uhost uhand uchan uargs upublic} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
463 global qdb_channels |
346
329ceff76d0c
qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
464 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
465 # Check if command comes from allowed channel or is private |
346
329ceff76d0c
qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
466 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
|
467 return 0 |
329ceff76d0c
qdb: Add support for enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
468 } |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
469 |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
470 # Trim argument text |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
471 set uargs [string trim $uargs] |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
472 |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
473 if {$uargs == "" || $uargs == {}} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
474 # No arguments, assume random query |
671
3904fcfeeb9a
quotedb: Rename qdb_get() to qdb_show() and remove extraneous unused argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
670
diff
changeset
|
475 qdb_show $ucmd $utable $upublic $unick $uhost $uhand $uchan -1 |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
476 } elseif {[regexp {^(stat|stats|tilasto|tilastot)$} $uargs]} { |
466
a8eb80bbffa5
quotedb: Add 'stats' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
477 # Statistics |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
478 qdb_stats $ucmd $utable $upublic $unick $uhost $uhand $uchan $uargs |
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
479 } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $uargs]} { |
465
ba7ed8f6d2ab
quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents:
459
diff
changeset
|
480 # Latest added |
671
3904fcfeeb9a
quotedb: Rename qdb_get() to qdb_show() and remove extraneous unused argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
670
diff
changeset
|
481 qdb_show $ucmd $utable $upublic $unick $uhost $uhand $uchan -2 |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
482 } elseif {[regexp {^([0-9]+)$} $uargs -> unum]} { |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
483 # Numeric argument, assume id query |
671
3904fcfeeb9a
quotedb: Rename qdb_get() to qdb_show() and remove extraneous unused argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
670
diff
changeset
|
484 qdb_show $ucmd $utable $upublic $unick $uhost $uhand $uchan $unum |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
485 } elseif {[regexp {^top\s*([0-9]+)?$} $uargs -> rargs]} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
486 # Toplist of quotes |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
487 qdb_toplist $ucmd $utable $upublic $unick $uhost $uhand $uchan $uargs $rargs |
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
488 } elseif {[regexp {^add\s*(.*)$} $uargs -> rargs]} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
489 # Add quote |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
490 qdb_add $ucmd $utable $upublic $unick $uhost $uhand $uchan $rargs |
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
491 } elseif {[regexp {^del\s*([0-9]*)$} $uargs -> rargs]} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
492 # Delete quote |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
493 qdb_delete $ucmd $utable $upublic $unick $uhost $uhand $uchan $rargs |
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
494 } elseif {[regexp {^update\s*(.*)$} $uargs -> rargs]} { |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
495 # Modify/update quote |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
496 qdb_update $ucmd $utable $upublic $unick $uhost $uhand $uchan $rargs |
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
497 } elseif {[regexp {^find\s*(.*)$} $uargs -> rargs]} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
498 # Find quote(s) |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
499 qdb_find $ucmd $utable $upublic $unick $uhost $uhand $uchan $rargs |
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
500 } elseif {[regexp {^vote\s*(.*)$} $uargs -> rargs]} { |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
501 # Vote |
674
57dd82ac2a06
quotedb: Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
672
diff
changeset
|
502 qdb_vote $ucmd $utable $upublic $unick $uhost $uhand $uchan $rargs |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
503 } else { |
465
ba7ed8f6d2ab
quotedb: Add get latest quote feature.
Matti Hamalainen <ccr@tnsp.org>
parents:
459
diff
changeset
|
504 # Help/usage |
513
8abb0e8d54a2
quotedb: Refactor qdb_msg and message handling in general.
Matti Hamalainen <ccr@tnsp.org>
parents:
510
diff
changeset
|
505 qdb_msg $ucmd $utable $upublic $unick $uchan "help" |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
506 } |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
507 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
508 |
559 | 509 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
510 #------------------------------------------------------------------------- |
559 | 511 # Script initialization |
512 #------------------------------------------------------------------------- | |
513 putlog "$qdb_message" | |
514 | |
606
56f204df1323
quotedb: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
515 if {[catch {sqlite3 qdb_handle $qdb_db_file} uerrmsg]} { |
56f204df1323
quotedb: Rename SQLite3 database filename configuration variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
516 putlog "Could not open SQLite3 database '${qdb_db_file}': ${uerrmsg}" |
559 | 517 exit 2 |
518 } | |
519 | |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 # end of script |