Mercurial > hg > egg-tcls
annotate quotedb.tcl @ 288:135e6c628164
quotedb: Add nick to parameters.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 25 Jan 2015 15:34:27 +0200 |
parents | 5b997bee1745 |
children | 42ba48d54324 |
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 # |
261
e82ae84408ca
quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
3 # QuoteDB v2.2 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
e82ae84408ca
quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
4 # (C) Copyright 2003-2015 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 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 ########################################################################## |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 # No need to look below this line |
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 set qdb_name "QuoteDB" |
261
e82ae84408ca
quotedb: Move settings/config into separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
21 set qdb_version "2.2" |
25
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 #------------------------------------------------------------------------- |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 ### Initialization messages |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 set qdb_message "$qdb_name v$qdb_version by ccr/TNSP" |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 putlog "$qdb_message" |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 ### Require packages |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 package require sqlite3 |
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 ### 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
|
32 if {[catch {sqlite3 qdb_handle $qdb_file} uerrmsg]} { |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 putlog " Could not open SQLite3 database '$qdb_file': $uerrmsg" |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 exit 2 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
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 ### Utility functions |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 proc qdb_log {jarg} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 global qdb_logmsg qdb_name |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 if {$qdb_logmsg != 0} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 putlog "$qdb_name: $jarg" |
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 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 proc qdb_ctime {utime} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 if {$utime == "" || $utime == "*"} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 set utime 0 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 return [clock format $utime -format "%d.%m.%Y %H:%M"] |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
56 proc qdb_msg_do {apublic anick achan amsg} { |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 global qdb_preferredmsg |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 if {$apublic == 0} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 putserv "$qdb_preferredmsg $anick :$amsg" |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 } else { |
40
3c118e1d1137
Don't use nickname in QuoteDB's public messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
39
diff
changeset
|
62 putserv "$qdb_preferredmsg $achan :$amsg" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
66 proc qdb_msg {apublic anick achan amsg {aargs {}}} { |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
67 set narg 1 |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
68 foreach marg $aargs { |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
69 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
|
70 incr narg |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
71 } |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
72 qdb_msg_do $apublic $anick $achan $amsg |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
73 } |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
74 |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
75 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 proc qdb_escape {str} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 return [string map {' ''} $str] |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
37
c3c597cac4b6
Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
80 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
|
81 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
|
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" |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
84 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
|
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 |
55
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
90 proc qdb_split {str maxlen} { |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
91 set pos 0 |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
92 set len [string length $str] |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
93 set ulen 0 |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
94 set ustr "" |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
95 set result {} |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
96 while {$pos < $len} { |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
97 set end [string wordend $str $pos] |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
98 set new [expr $end - $pos + 1] |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
99 if {$ulen + $new < $maxlen} { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
100 append ustr [string range $str $pos $end] |
55
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
101 set ulen [expr $ulen + $new] |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
102 } else { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
103 append ustr [string range $str $pos $end] |
55
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
104 lappend result $ustr |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
105 set ustr "" |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
106 set ulen 0 |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
107 } |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
108 set pos [expr $end + 1] |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
109 } |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
110 if {$ustr != ""} { |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
111 lappend result $ustr |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
112 } |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
113 return $result |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
114 } |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
115 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
116 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
|
117 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
|
118 if {$uhand == "" || $uhand == {}} { |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
119 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
|
120 return 0 |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
121 } |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
122 return 1 |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
123 } |
25
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 #------------------------------------------------------------------------- |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
126 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
|
127 global qdb_handle qdb_msg_add_success |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
129 if {![qdb_valid_user $upublic $unick $uchan $uhand]} { |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 return 0 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
133 if {$utext == "" || $utext == {}} { |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
134 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
|
135 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
136 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
137 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
138 set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[qdb_escape $utext]', '[qdb_escape $uhand]', '[qdb_escape $uhost]', '[qdb_escape $uchan]')" |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
139 if {![qdb_sql_exec $upublic $unick $uchan $usql]} { |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 return 0 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
143 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
|
144 # 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
|
145 # 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
|
146 # if {![qdb_sql_exec $upublic $unick $uchan $usql]} { return 0 } |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 ### 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
|
149 qdb_log "Added $utable #$quoteID ($unick/$uhand@$uchan): $utext" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 ### 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
|
152 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
|
153 return 1 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 #------------------------------------------------------------------------- |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
158 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
|
159 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
|
160 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
161 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
|
162 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
163 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
|
164 return 0 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
165 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
166 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
167 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
|
168 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
|
169 return 0 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
170 } |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
171 |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
172 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
|
173 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
|
174 if {$qoverride == 0} { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
175 append usql " AND user='[qdb_escape $uhand]'" |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
176 set qextra "" |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
177 } else { |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
178 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
|
179 } |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
180 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
181 qdb_handle eval $usql { |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 return 0 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
187 } 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
|
188 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
|
189 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
|
190 return 0 |
965b728c2a9d
Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
191 } |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
192 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
|
193 return 1 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
194 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
195 } 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
|
196 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
|
197 return 0 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
198 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
199 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
200 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
201 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
|
202 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
203 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
204 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
205 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
206 #------------------------------------------------------------------------- |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
211 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
|
212 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
213 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
|
214 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
215 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
216 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
217 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
|
218 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
|
219 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
220 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
221 |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
222 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
|
223 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
|
224 if {$qoverride == 0} { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
225 append usql " AND user='[qdb_escape $uhand]'" |
64
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
226 set qextra "" |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
227 } else { |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
228 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
|
229 } |
cd9fd4ec82a9
quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
230 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
231 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
|
232 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
|
233 if {$udiff < $maxdiff || $qoverride} { |
60
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
234 set usql "UPDATE $utable SET utext='[qdb_escape $uquote]', utime=[unixtime] WHERE id=$unum" |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
235 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
|
236 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
237 } else { |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
238 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
|
239 return 1 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
240 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
241 } else { |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
242 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
|
243 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
244 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
245 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
246 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
247 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
|
248 return 0 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
249 } |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
250 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
251 |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
252 #------------------------------------------------------------------------- |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
253 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
|
254 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
|
255 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
256 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
|
257 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
|
258 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
259 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
260 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
261 set uresults 0 |
44
f0694e61ae45
Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
262 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
|
263 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
|
264 incr uresults |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
265 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
|
266 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
267 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
268 return 0 |
26
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
269 } |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
270 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
271 |
3f999371de82
Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
272 #------------------------------------------------------------------------- |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
273 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
|
274 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
|
275 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
276 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
|
277 return 0 |
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 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
280 set uvote 1 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
281 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
|
282 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
|
283 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
|
284 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
|
285 } 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
|
286 } 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
|
287 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
|
288 return 0 |
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 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
291 # 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
|
292 set uresults 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 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
|
297 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
298 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
299 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
300 # Check if user has previously voted this item |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
301 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[qdb_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
|
302 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
|
303 # 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
|
304 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
|
305 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { |
45
18eb2f6d6c3e
Log voting of quotes in bot log.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
306 qdb_log "$uhand changed vote to $uvote on #$uid / $utable" |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
307 qdb_msg $upublic $unick $uchan $qdb_msg_vote_updated [list $uid $uvote] |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
308 return 1 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
309 } else { |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
310 return 0 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
311 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
312 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
313 |
148 | 314 # No previous votes, insert new |
315 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[qdb_escape $uhand]',$uid,$uvote)" | |
316 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { | |
317 qdb_log "$uhand voted $uvote on #$uid / $utable" | |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
318 qdb_msg $upublic $unick $uchan $qdb_msg_you_voted [list $uid $uvote] |
39
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 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
321 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
322 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
323 #------------------------------------------------------------------------- |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
324 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
|
325 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
|
326 |
149
fc2654064339
quotedb: Show quote addition date.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
327 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
|
328 if {$uindex >= 0} { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
329 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
|
330 qdb_log "$unick searched $utable #$uindex" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 } else { |
66
140f0492dcd3
quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
332 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
|
333 qdb_log "$unick get random $utable" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
336 qdb_handle eval $usql { |
149
fc2654064339
quotedb: Show quote addition date.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
337 set qtmp [qdb_split "#${quoteID}: $utext ($uuser@[qdb_ctime $utime], $uvote)" 450] |
55
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
338 foreach qstr $qtmp { |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
339 qdb_msg $upublic $unick $uchan $qstr |
f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
340 } |
48
506ce7f074e4
Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
341 return 1 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 } |
48
506ce7f074e4
Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
343 |
288
135e6c628164
quotedb: Add nick to parameters.
Matti Hamalainen <ccr@tnsp.org>
parents:
283
diff
changeset
|
344 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
|
345 return 0 |
25
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 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 #------------------------------------------------------------------------- |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
350 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
|
351 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
|
352 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 if {$upublic == 0} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 set ulimit $qdb_showmax_priv |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 } else { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 set ulimit $qdb_showmax_pub |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 ### Parse the given command |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 qdb_log "$unick/$uhand/$uchan searched $utable: $utext" |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 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
|
363 set fpatlist "" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 foreach ftoken $ftokens { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 set fprefix [string range $ftoken 0 0] |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 set fpattern [string range $ftoken 1 end] |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 if {$fprefix == "-"} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 lappend fpatlist "utext NOT LIKE '%[qdb_escape $fpattern]%'" |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 } elseif {$fprefix == "%"} { |
110
4aa1e1d545ed
urllog and quotedb: Use SQL LIKE operator for username search terms to avoid unnecessary case-sensitivity.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
371 lappend fpatlist "user LIKE '[qdb_escape $fpattern]'" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 } elseif {$fprefix == "@"} { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 # foo |
109
74cb254dbf09
urllog and quotedb: Handle "+"-prefix in searches as it is documented.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
374 } elseif {$fprefix == "+"} { |
74cb254dbf09
urllog and quotedb: Handle "+"-prefix in searches as it is documented.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
375 lappend fpatlist "utext LIKE '%[qdb_escape $fpattern]%'" |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 } else { |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 lappend fpatlist "utext LIKE '%[qdb_escape $ftoken]%'" |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
379 } |
27
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
380 if {[llength $fpatlist] > 0} { |
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
381 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
|
382 } else { |
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
383 set fquery "" |
6e381916b016
Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
384 } |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
386 ### Query the database and output results |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 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
|
388 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
|
389 qdb_handle eval $usql { |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 incr uresults |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
391 qdb_msg $upublic $unick $uchan $qdb_msg_search_fmt [list $quoteID $utext $uuser $utime [qdb_ctime $utime]] |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 if {$uresults == 0} { |
288
135e6c628164
quotedb: Add nick to parameters.
Matti Hamalainen <ccr@tnsp.org>
parents:
283
diff
changeset
|
395 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
|
396 return 0 |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 } |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
398 return 1 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
399 } |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
400 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
401 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
402 #------------------------------------------------------------------------- |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
403 proc qdb_command {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
|
404 global qdb_msg_help |
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
405 |
54
301df7d15861
quotedb: Using [join utext " "] on command input string is harmful. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
406 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
|
407 |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
408 if {$utext == "" || $utext == {}} { |
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
409 # No arguments, assume random query |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
410 qdb_get $ucmd $utable $unick $uchan -1 $upublic |
39
428f498b6030
Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
411 } 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
|
412 # Numeric argument, assume index query |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
413 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
|
414 } 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
|
415 # Toplist of quotes |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
416 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
|
417 } 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
|
418 # Add quote |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
419 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
|
420 } 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
|
421 # Delete quote |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
422 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
|
423 } 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
|
424 # Modify/update quote |
ce327469582c
quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
425 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
|
426 } 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
|
427 # Find quote(s) |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
428 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
|
429 } 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
|
430 # Vote |
56
aff22ba168b0
quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
431 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
|
432 } else { |
283
5b997bee1745
quotedb: Move various message texts to configuration file. Not everything yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
433 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
|
434 } |
25
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 } |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 #------------------------------------------------------------------------- |
65f94adedc98
Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 # end of script |