annotate quotedb.tcl @ 178:9b8ec700ede4

Clean up the weather data parser backend a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 03 Jun 2014 15:10:47 +0300
parents fc2654064339
children 44593f1fb916
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #
114
593874678e45 Clarify authorship by doing sed "s/ccr\/TNSP/Matti 'ccr' Hamalainen/g".
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
3 # QuoteDB v2.1 by Matti 'ccr' Hamalainen <ccr@tnsp.org>
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 # (C) Copyright 2003-2011 Tecnic Software productions (TNSP)
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 # Not for public use or distribution. If you happen to find this,
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 # send your questions and/or problems to /dev/null, thank you.
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 ##########################################################################
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
10 #
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
11 #
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
12 ##########################################################################
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 ### General options
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 # Path and filename of the SQLite database
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 set qdb_file "quotedb.sqlite"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
20 # Verbosity (1 = be verbose, 0 = be quiet)
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 set qdb_verbose 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
23
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
24 # 1 = Enable logging of various script actions into bot's log
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 # 0 = Don't.
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 set qdb_logmsg 1
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
28
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 # What IRC "command" should we use to send messages:
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 # (Valid alternatives are "PRIVMSG" and "NOTICE")
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 set qdb_preferredmsg "PRIVMSG"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
33 # Foo.
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
34 set qdb_max_deltime 15
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
35 set qdb_max_modtime 30
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
36
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
37
25
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 ### Search related settings
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
81
17e542b7985a urllog, quotedb: Improve documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
42 # Limit how many quotes should the "!<cmd> find" command show at most.
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 set qdb_showmax_pub 3
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
45 # Same as above, but for private message search.
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 set qdb_showmax_priv 5
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
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 # No need to look below this line
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 set qdb_name "QuoteDB"
67
eb728cebfe2c quotedb: Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
53 set qdb_version "2.1"
25
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
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 ### Binding initializations
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
58
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
59
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
60 # EXAMPLE!
85
a8278d55c6db quotedb: Add in !quote command.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
61 bind pub - !quote quote_pub_cmd
a8278d55c6db quotedb: Add in !quote command.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
62 bind msg - quote quote_msg_cmd
a8278d55c6db quotedb: Add in !quote command.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
63 proc quote_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!quote" "quotedb" $unick $uhost $uhand $uchan $utext 1 }
a8278d55c6db quotedb: Add in !quote command.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
64 proc quote_msg_cmd {unick uhost uhand utext} { qdb_command "quote" "quotedb" $unick $uhost $uhand "" $utext 0 }
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
65
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
66
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
67 bind pub - !spede spede_pub_cmd
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
68 bind msg - spede spede_msg_cmd
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
69 proc spede_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!spede" "spededb" $unick $uhost $uhand $uchan $utext 1 }
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
70 proc spede_msg_cmd {unick uhost uhand utext} { qdb_command "spede" "spededb" $unick $uhost $uhand "" $utext 0 }
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
71
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
72 bind pub - !mn mn_pub_cmd
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
73 bind msg - mn mn_msg_cmd
77
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
74 proc mn_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!mn" "mndb" $unick $uhost $uhand $uchan $utext 1 }
bae07e52591d quotedb: Cosmetics, add some commented out examples for future, improve documentation of settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
75 proc mn_msg_cmd {unick uhost uhand utext} { qdb_command "mn" "mndb" $unick $uhost $uhand "" $utext 0 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
77 bind pub - !tuksu tuksu_pub_cmd
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
78 bind msg - tuksu tuksu_msg_cmd
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
79 proc tuksu_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!tuksu" "tuksudb" $unick $uhost $uhand $uchan $utext 1 }
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
80 proc tuksu_msg_cmd {unick uhost uhand utext} { qdb_command "tuksu" "tuksudb" $unick $uhost $uhand "" $utext 0 }
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
81
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 ### Initialization messages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 set qdb_message "$qdb_name v$qdb_version by ccr/TNSP"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 putlog "$qdb_message"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 ### Require packages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 package require sqlite3
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 ### SQLite database initialization
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 if {[catch {sqlite3 quotedb $qdb_file} uerrmsg]} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 putlog " Could not open SQLite3 database '$qdb_file': $uerrmsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 exit 2
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 ### Utility functions
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 proc qdb_log {jarg} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 global qdb_logmsg qdb_name
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 if {$qdb_logmsg != 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 putlog "$qdb_name: $jarg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 proc qdb_ctime {utime} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 if {$utime == "" || $utime == "*"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 set utime 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 return [clock format $utime -format "%d.%m.%Y %H:%M"]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 proc qdb_msg {apublic anick achan amsg} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 global qdb_preferredmsg
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 if {$apublic == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 putserv "$qdb_preferredmsg $anick :$amsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 } else {
40
3c118e1d1137 Don't use nickname in QuoteDB's public messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
123 putserv "$qdb_preferredmsg $achan :$amsg"
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 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 proc qdb_escape {str} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 return [string map {' ''} $str]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
37
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
131 proc qdb_sql_exec { upublic unick uchan usql } {
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
132 global quotedb
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
133 if {[catch {quotedb eval $usql} uerrmsg]} {
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
134 qdb_log "$uerrmsg on SQL:\n$usql"
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
135 qdb_msg $upublic $unick $uchan "virhe sörkittäessä tietokantaa. uliskaa."
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
136 return 0
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
137 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
138 return 1
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
139 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
140
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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 } else {
66
140f0492dcd3 quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
154 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
155 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
156 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
157 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
158 }
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
159 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
160 }
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
161 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
162 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
163 }
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
164 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
165 }
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
166
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
169 proc qdb_add {ucmd utable unick uhost uhand uchan utext upublic} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 global quotedb
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
172 if {$uhand == "" || $uhand == {}} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 qdb_msg $upublic $unick $uchan "pyh."
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
177 if {$utext == "" || $utext == {}} {
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
178 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
179 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
180 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
181
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
182 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
183 if {![qdb_sql_exec $upublic $unick $uchan $usql]} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 set quoteID [quotedb 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
188 # 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
189 # 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
190 # if {![qdb_sql_exec $upublic $unick $uchan $usql]} { return 0 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 ### 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
193 qdb_log "Added $utable #$quoteID ($unick/$uhand@$uchan): $utext"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 ### Report success to user
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
196 qdb_msg $upublic $unick $uchan "tietokantaa $utable sörkitty (#$quoteID), kiitos."
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 return 1
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
202 proc qdb_delete {ucmd utable unick uhand uchan utext upublic} {
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
203 global quotedb qdb_max_deltime
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
204 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
205
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
206 if {$uhand == "" || $uhand == {}} {
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
207 qdb_msg $upublic $unick $uchan "pyh."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
208 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
209 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
210
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
211 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
212 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
213 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
214 }
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
215
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
216 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
217 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
218 if {$qoverride == 0} {
66
140f0492dcd3 quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
219 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
220 set qextra ""
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
221 } else {
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
222 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
223 }
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
224
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
225 quotedb eval $usql {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
226 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
227 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
228 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
229 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
230 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
231 } 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
232 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
233 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
234 return 0
965b728c2a9d Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
235 }
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
236 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
237 return 1
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
238 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
239 } 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
240 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
241 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
242 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
243 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
244
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
245 qdb_msg $upublic $unick $uchan "#$unum ei löydy, tai se ei kuulu käyttäjälle '$uhand'."
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
246 return 0
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
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
249
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
250 #-------------------------------------------------------------------------
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
251 proc qdb_update {ucmd utable unick uhand uchan utext upublic} {
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
252 global quotedb qdb_max_modtime
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
253 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
254
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
255 if {$uhand == "" || $uhand == {}} {
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
256 qdb_msg $upublic $unick $uchan "pyh."
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
257 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
258 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
259
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
260 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
261 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
262 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
263 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
264
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
265 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
266 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
267 if {$qoverride == 0} {
66
140f0492dcd3 quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
268 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
269 set qextra ""
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
270 } else {
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
271 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
272 }
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
273
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
274 quotedb eval $usql {
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
275 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
276 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
277 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
278 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
279 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
280 } else {
64
cd9fd4ec82a9 quotedb: Add in +n flag override for deleting and updating quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
281 qdb_msg $upublic $unick $uchan "$utable #$unum päivitetty$qextra."
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
282 return 1
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
283 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
284 } else {
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
285 qdb_msg $upublic $unick $uchan "$utable quote #$unum vanhempi kuin $qdb_max_modtime minuuttia, ei voida päivittää."
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
286 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
287 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
288 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
289
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
290 qdb_msg $upublic $unick $uchan "#$unum ei löydy, tai se ei kuulu käyttäjälle '$uhand'."
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
291 return 0
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
292 }
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
293
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
294
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
295 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
296 proc 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
297 global quotedb
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
298
41
636fa4bf0814 Remove some commented out debugging stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
299 if {$unum < 2 || $unum > 4} {
636fa4bf0814 Remove some commented out debugging stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
300 # qdb_msg $upublic $unick $uchan "top-listan pituus oltava 2-4."
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
301 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
302 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
303
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
304 set uresults 0
44
f0694e61ae45 Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
305 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"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
306 quotedb eval $usql {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
307 incr uresults
44
f0694e61ae45 Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
308 qdb_msg $upublic $unick $uchan "${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
309 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
310
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
311 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
312 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
313
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
314
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
315 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
316 proc qdb_vote {ucmd utable unick uhand uchan utext upublic} {
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
317 global quotedb
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 if {$uhand == "" || $uhand == {}} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
320 qdb_msg $upublic $unick $uchan "pyh."
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
321 return 0
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
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
324 set uvote 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
325 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
326 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
327 set uid 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
328 quotedb eval $usql { set uid $qid }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
329 } 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
330 } 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
331 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
332 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
333 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
334
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
335 # 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
336 set uresults 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
337 set usql "SELECT id AS qid FROM ${utable} WHERE id=$uid"
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
338 quotedb eval $usql { incr uresults }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
339 if {$uresults == 0} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
340 qdb_msg $upublic $unick $uchan "quotea #$uid ei ole."
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
341 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
342 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
343
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
344 # 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
345 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[qdb_escape $uhand]' AND urlid=$uid"
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
346 quotedb eval $usql {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
347 # 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
348 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
349 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
350 qdb_log "$uhand changed vote to $uvote on #$uid / $utable"
18eb2f6d6c3e Log voting of quotes in bot log.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
351 qdb_msg $upublic $unick $uchan "ääni päivitetty #$uid -> $uvote"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
352 return 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
353 } else {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
354 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
355 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
356 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
357
148
2f0c823386b0 quotedb: Simplify a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
358 # No previous votes, insert new
2f0c823386b0 quotedb: Simplify a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
359 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[qdb_escape $uhand]',$uid,$uvote)"
2f0c823386b0 quotedb: Simplify a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
360 if {[qdb_sql_exec $upublic $unick $uchan $usql]} {
2f0c823386b0 quotedb: Simplify a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
361 qdb_log "$uhand voted $uvote on #$uid / $utable"
2f0c823386b0 quotedb: Simplify a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
362 qdb_msg $upublic $unick $uchan "äänestit #$uid -> $uvote"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
363 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
364 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
365
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
366
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
367 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
368 proc qdb_get {ucmd utable unick uchan uindex upublic} {
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
369 global quotedb
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
370
149
fc2654064339 quotedb: Show quote addition date.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
371 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
372 if {$uindex >= 0} {
66
140f0492dcd3 quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
373 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
374 qdb_log "$unick searched $utable #$uindex"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 } else {
66
140f0492dcd3 quotedb: Use TCL function append instead of set foo "$foo..."
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
376 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
377 qdb_log "$unick get random $utable"
25
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
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 quotedb eval $usql {
149
fc2654064339 quotedb: Show quote addition date.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
381 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
382 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
383 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
384 }
48
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
385 return 1
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 }
48
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
387
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
388 qdb_msg $upublic $unick $uchan "ei löydy."
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
389 return 0
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391
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 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
394 proc qdb_find {ucmd utable unick uhand uchan utext upublic} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 global quotedb qdb_showmax_pub qdb_showmax_priv
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 if {$upublic == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 set ulimit $qdb_showmax_priv
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 set ulimit $qdb_showmax_pub
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 ### Parse the given command
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 qdb_log "$unick/$uhand/$uchan searched $utable: $utext"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 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
407 set fpatlist ""
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 foreach ftoken $ftokens {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 set fprefix [string range $ftoken 0 0]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 set fpattern [string range $ftoken 1 end]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 if {$fprefix == "-"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 lappend fpatlist "utext NOT LIKE '%[qdb_escape $fpattern]%'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 } 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
415 lappend fpatlist "user LIKE '[qdb_escape $fpattern]'"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 } elseif {$fprefix == "@"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 # foo
109
74cb254dbf09 urllog and quotedb: Handle "+"-prefix in searches as it is documented.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
418 } elseif {$fprefix == "+"} {
74cb254dbf09 urllog and quotedb: Handle "+"-prefix in searches as it is documented.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
419 lappend fpatlist "utext LIKE '%[qdb_escape $fpattern]%'"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 lappend fpatlist "utext LIKE '%[qdb_escape $ftoken]%'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 }
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
424 if {[llength $fpatlist] > 0} {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
425 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
426 } else {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
427 set fquery ""
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
428 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
430 ### Query the database and output results
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 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
432 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser FROM $utable $fquery ORDER BY utime DESC LIMIT $ulimit"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 quotedb eval $usql {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 incr uresults
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[qdb_ctime $utime])"
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 if {$uresults == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 qdb_msg $upublic $unick $uchan "ei löydy."
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
440 return 0
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 }
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
442 return 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
443 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
444
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
445
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
446 #-------------------------------------------------------------------------
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
447 proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic} {
54
301df7d15861 quotedb: Using [join utext " "] on command input string is harmful. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
448 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
449
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
450 if {$utext == "" || $utext == {}} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
451 # No arguments, assume random query
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
452 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
453 } 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
454 # Numeric argument, assume index query
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
455 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
456 } 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
457 # Toplist of quotes
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
458 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
459 } 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
460 # Add quote
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
461 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
462 } 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
463 # Delete quote
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
464 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
465 } 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
466 # Modify/update quote
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
467 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
468 } 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
469 # Find quote(s)
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
470 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
471 } 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
472 # Vote
56
aff22ba168b0 quotedb: Show command name in the short helps.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
473 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
474 } else {
60
ce327469582c quotedb: Add "update" sub-command for modifying/updating recently added quotes.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
475 qdb_msg $upublic $unick $uchan "$ucmd add <teksti>|update <id> <teksti>|del <id>|find <parametrit>|vote|top3"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
476 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 # end of script