annotate quotedb.tcl @ 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.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Sep 2011 17:49:50 +0300
parents 301df7d15861
children aff22ba168b0
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 #
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
3 # QuoteDB v2.0 by ccr/TNSP <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 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 ### General options
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 # Path and filename of the SQLite database
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 set qdb_file "quotedb.sqlite"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 # 1 = Verbose: Say messages PUBLIC when SPEDE is OK, bad, etc.
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 # 0 = Quiet : Say privately
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 set qdb_verbose 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 # 1 = Put some info to bot's Logfile when doing stuff...
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 # 0 = Don't.
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 set qdb_logmsg 1
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 # What IRC "command" should we use to send messages:
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 # (Valid alternatives are "PRIVMSG" and "NOTICE")
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 set qdb_preferredmsg "PRIVMSG"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
30 # Foo.
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
31 set qdb_max_deltime 15
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
32
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 ### Search related settings
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 ###
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 # How many SPEDE's should the !spedefind command show (maximum limit)
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 set qdb_showmax_pub 3
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 # For private-search, this is the default limit (user can change it)
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 set qdb_showmax_priv 5
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 # No need to look below this line
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 ##########################################################################
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 set qdb_name "QuoteDB"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
49 set qdb_version "2.0"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 ### Binding initializations
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
54 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
55 bind msg - spede spede_msg_cmd
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
56 proc spede_pub_cmd {unick uhost uhand uchan utext} { qdb_command "spededb" $unick $uhost $uhand $uchan $utext 1 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
57 proc spede_msg_cmd {unick uhost uhand utext} { qdb_command "spededb" $unick $uhost $uhand "" $utext 0 }
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
58
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
59 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
60 bind msg - mn mn_msg_cmd
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
61 proc mn_pub_cmd {unick uhost uhand uchan utext} { qdb_command "mndb" $unick $uhost $uhand $uchan $utext 1 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
62 proc mn_msg_cmd {unick uhost uhand utext} { qdb_command "mndb" $unick $uhost $uhand "" $utext 0 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
64 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
65 bind msg - tuksu tuksu_msg_cmd
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
66 proc tuksu_pub_cmd {unick uhost uhand uchan utext} { qdb_command "tuksudb" $unick $uhost $uhand $uchan $utext 1 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
67 proc tuksu_msg_cmd {unick uhost uhand utext} { qdb_command "tuksudb" $unick $uhost $uhand "" $utext 0 }
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
68
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 ### Initialization messages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 set qdb_message "$qdb_name v$qdb_version by ccr/TNSP"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 putlog "$qdb_message"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 ### Require packages
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 package require sqlite3
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 ### SQLite database initialization
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 if {[catch {sqlite3 quotedb $qdb_file} uerrmsg]} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 putlog " Could not open SQLite3 database '$qdb_file': $uerrmsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 exit 2
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
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 ### Utility functions
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 proc qdb_log {jarg} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 global qdb_logmsg qdb_name
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 if {$qdb_logmsg != 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 putlog "$qdb_name: $jarg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 proc qdb_ctime {utime} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 if {$utime == "" || $utime == "*"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 set utime 0
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
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 return [clock format $utime -format "%d.%m.%Y %H:%M"]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 proc qdb_msg {apublic anick achan amsg} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 global qdb_preferredmsg
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 if {$apublic == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 putserv "$qdb_preferredmsg $anick :$amsg"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 } else {
40
3c118e1d1137 Don't use nickname in QuoteDB's public messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
110 putserv "$qdb_preferredmsg $achan :$amsg"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 proc qdb_escape {str} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 return [string map {' ''} $str]
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
37
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
118 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
119 global quotedb
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
120 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
121 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
122 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
123 return 0
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
124 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
125 return 1
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
126 }
c3c597cac4b6 Add helper function qdb_sql_exec for simplifying certain SQL operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
127
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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 if {$ulen + $new < $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
138 set ustr "$ustr[string range $str $pos $end]"
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
139 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
140 } else {
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 set ustr "$ustr[string range $str $pos $end]"
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 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
143 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
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 }
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 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
147 }
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 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
149 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
150 }
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
151 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
152 }
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
25
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 #-------------------------------------------------------------------------
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
156 proc qdb_add {utable unick uhost uhand uchan utext upublic} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 global quotedb
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
159 if {$uhand == "" || $uhand == {}} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 qdb_msg $upublic $unick $uchan "pyh."
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
164 if {$utext == "" || $utext == {}} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
165 qdb_msg $upublic $unick $uchan "wtf! add <teksti>"
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
166 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
167 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
168
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
169 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
170 if {![qdb_sql_exec $upublic $unick $uchan $usql]} {
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 return 0
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 set quoteID [quotedb last_insert_rowid]
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
175 set numQuotes 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
176 # set numQuotes [quotedb ]
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 ### 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
179 qdb_log "Added $utable #$quoteID ($unick/$uhand@$uchan): $utext"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 ### Report success to user
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
182 qdb_msg $upublic $unick $uchan "tietokantaa sörkitty (#$quoteID / $numQuotes), kiitos."
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 return 1
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
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 #-------------------------------------------------------------------------
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
188 proc qdb_delete {utable unick uhand uchan utext upublic} {
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
189 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
190 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
191
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
192 if {$uhand == "" || $uhand == {}} {
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
193 qdb_msg $upublic $unick $uchan "pyh."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
194 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
195 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
196
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
197 if {![regexp {^\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
198 qdb_msg $upublic $unick $uchan "del <id>"
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
199 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
200 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
201
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
202 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable WHERE id=$unum AND user='[qdb_escape $uhand]'"
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
203 quotedb eval $usql {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
204 set udiff [expr [unixtime] - $utime]
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
205 if {$udiff < $maxdiff} {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
206 set usql "DELETE FROM $utable WHERE id=$quoteID AND user='[qdb_escape $uhand]'"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
207 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
208 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
209 } else {
43
965b728c2a9d Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
210 set usql "DELETE FROM ${utable}_votes WHERE urlid=$quoteID"
965b728c2a9d Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
211 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
212 return 0
965b728c2a9d Delete the votes/ratings too, when deleting a quote.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
213 }
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
214 qdb_msg $upublic $unick $uchan "$utable ID #$quoteID poistettu."
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
215 return 1
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
216 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
217 } else {
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
218 qdb_msg $upublic $unick $uchan "$utable quote #$quoteID vanhempi kuin $qdb_max_deltime minuuttia, ei poisteta."
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
219 return 0
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
220 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
221 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
222
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
223 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
224 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
225 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
226
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
227
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
228 #-------------------------------------------------------------------------
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
229 proc qdb_toplist {utable unick uchan unum upublic} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
230 global quotedb
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
231
41
636fa4bf0814 Remove some commented out debugging stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
232 if {$unum < 2 || $unum > 4} {
636fa4bf0814 Remove some commented out debugging stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
233 # 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
234 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
235 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
236
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
237 set uresults 0
44
f0694e61ae45 Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
238 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"
f0694e61ae45 Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
239 # putlog "s=$usql"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
240 quotedb eval $usql {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
241 incr uresults
44
f0694e61ae45 Change one local variable name.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
242 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
243 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
244
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
245 return 0
26
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
246 }
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
247
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
248
3f999371de82 Actually fix the quotedb script to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
249 #-------------------------------------------------------------------------
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
250 proc qdb_vote {utable unick uhand uchan utext upublic} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
251 global quotedb
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
252
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
253 if {$uhand == "" || $uhand == {}} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
254 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
255 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
256 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
257
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
258 set uvote 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
259 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
260 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
261 set uid 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
262 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
263 } 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
264 } elseif {![regexp {^\s*([0-9]+)\s+(-1|1)$} $utext umatch uid uvote]} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
265 qdb_msg $upublic $unick $uchan "vote <id> \[1 | -1\]"
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
266 return 0
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
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
269 # 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
270 set uresults 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
271 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
272 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
273 if {$uresults == 0} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
274 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
275 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
276 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
277
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
278 # 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
279 set uresults 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
280 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
281 quotedb eval $usql {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
282 incr uresults
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
283 # 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
284 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
285 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
286 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
287 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
288 return 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
289 } else {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
290 return 0
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
291 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
292 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
293
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
294 if {$uresults == 0} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
295 # No previous votes, insert new
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
296 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[qdb_escape $uhand]',$uid,$uvote)"
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
297 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
298 qdb_log "$uhand voted $uvote on #$uid / $utable"
18eb2f6d6c3e Log voting of quotes in bot log.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
299 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
300 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
301 }
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
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
305 #-------------------------------------------------------------------------
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
306 proc qdb_get {utable unick uchan uindex upublic} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
307 global quotedb
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
308
47
6cf21069ac10 Show score/rating for single quotedb quotes when requested by index or as random.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
309 set usql "SELECT total(${utable}_votes.vote) AS uvote, ${utable}.id AS quoteID, ${utable}.utext AS utext, ${utable}.user AS uuser FROM ${utable} LEFT JOIN ${utable}_votes ON ${utable}_votes.urlid = ${utable}.id"
6cf21069ac10 Show score/rating for single quotedb quotes when requested by index or as random.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
310 # set usql "$usql GROUP BY ${utable}.id"
6cf21069ac10 Show score/rating for single quotedb quotes when requested by index or as random.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
311 # set usql "SELECT id AS quoteID, utext AS utext, user AS uuser FROM $utable"
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
312 if {$uindex >= 0} {
47
6cf21069ac10 Show score/rating for single quotedb quotes when requested by index or as random.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
313 set usql "$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
314 qdb_log "$unick searched $utable #$uindex"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 } else {
47
6cf21069ac10 Show score/rating for single quotedb quotes when requested by index or as random.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
316 set usql "$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
317 qdb_log "$unick get random $utable"
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 quotedb eval $usql {
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
321 set qtmp [qdb_split "#${quoteID}: $utext ($uuser, $uvote)" 450]
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
322 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
323 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
324 }
48
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
325 return 1
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 }
48
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
327
506ce7f074e4 Cleanups. Add "not found" message for certain quote lookup requests.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
328 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
329 return 0
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 proc qdb_find {utable unick uhand uchan utext upublic} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 global quotedb qdb_showmax_pub qdb_showmax_priv
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 if {$upublic == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 set ulimit $qdb_showmax_priv
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 set ulimit $qdb_showmax_pub
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 ### Parse the given command
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 qdb_log "$unick/$uhand/$uchan searched $utable: $utext"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 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
347 set fpatlist ""
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 foreach ftoken $ftokens {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 set fprefix [string range $ftoken 0 0]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 set fpattern [string range $ftoken 1 end]
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 if {$fprefix == "-"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 lappend fpatlist "utext NOT LIKE '%[qdb_escape $fpattern]%'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 } elseif {$fprefix == "%"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 lappend fpatlist "user='[qdb_escape $fpattern]'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 } elseif {$fprefix == "@"} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 # foo
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 } else {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 lappend fpatlist "utext LIKE '%[qdb_escape $ftoken]%'"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 }
27
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
362 if {[llength $fpatlist] > 0} {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
363 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
364 } else {
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
365 set fquery ""
6e381916b016 Some fixes in the query mechanisms of QuoteDB and URLLog.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
366 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
368 ### Query the database and output results
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 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
370 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
371 quotedb eval $usql {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 incr uresults
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[qdb_ctime $utime])"
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 if {$uresults == 0} {
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 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
378 return 0
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 }
39
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
380 return 1
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
381 }
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
382
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
383
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
384 #-------------------------------------------------------------------------
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
385 proc qdb_command {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
386 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
387
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
388 if {$utext == "" || $utext == {}} {
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
389 # No arguments, assume random query
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
390 qdb_get $utable $unick $uchan -1 $upublic
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
391 } 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
392 # Numeric argument, assume index query
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
393 qdb_get $utable $unick $uchan $unum $upublic
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
394 } 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
395 # Toplist of quotes
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
396 qdb_toplist $utable $unick $uchan $unum $upublic
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
397 } 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
398 # Add quote
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
399 qdb_add $utable $unick $uhost $uhand $uchan $unum $upublic
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
400 } 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
401 # Delete quote
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
402 qdb_delete $utable $unick $uhand $uchan $unum $upublic
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
403 } 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
404 # Find quote(s)
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
405 qdb_find $utable $unick $uhand $uchan $unum $upublic
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
406 } 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
407 # Vote
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
408 qdb_vote $utable $unick $uhand $uchan $unum $upublic
428f498b6030 Refactor QuoteDB some more, for modularity. Bot commands are now aggregated
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
409 } else {
46
80fa09f868d4 Barebones help message for quotedb sub-commands.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
410 qdb_msg $upublic $unick $uchan "add <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
411 }
25
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 }
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 #-------------------------------------------------------------------------
65f94adedc98 Import refactored QuoteDB script.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 # end of script