summaryrefslogtreecommitdiff
path: root/query.c
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2023-03-19 17:04:21 -0700
committerTrumeet <yuuta@yuuta.moe>2023-03-19 17:04:21 -0700
commit261d0f23f25151068c58db88c447289a882b4a6e (patch)
tree04587186ec0df7020775b58d33c75f7d8841b84d /query.c
parent92829eb1abde84916d92b22e107fc3ae7dc4bad2 (diff)
downloadksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.tar
ksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.tar.gz
ksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.tar.bz2
ksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.zip
Use message index instead of URL to save space
Refresh code is not maintained.
Diffstat (limited to 'query.c')
-rw-r--r--query.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/query.c b/query.c
index 1423d65..ff05ff2 100644
--- a/query.c
+++ b/query.c
@@ -21,9 +21,9 @@ static void cb_answer(bool successful, struct TdObject *result, struct TdError *
}
static struct TdInputInlineQueryResultArticle *create_inline_result(char *id,
- char *title,
- char *descr,
- char *text) {
+ char *title,
+ char *descr,
+ char *text) {
struct TdInputInlineQueryResultArticle *r = TdCreateObjectInputInlineQueryResultArticle(
id,
NULL,
@@ -63,7 +63,7 @@ int handle_inline(struct TdUpdateNewInlineQuery *update) {
goto sql_err;
sql_err:
LOGEV("Cannot query: %s.", sqlite3_errstr(r));
- for (int i = 0; i < effective_items_count; i ++) {
+ for (int i = 0; i < effective_items_count; i++) {
TdDestroyObjectInputInlineQueryResultArticle(results_inline[i]);
}
goto cleanup;
@@ -85,7 +85,7 @@ int handle_inline(struct TdUpdateNewInlineQuery *update) {
snprintf(msg_stat, sizeof(msg_stat), "我已经卖了 %d 句菜", personal_stat);
snprintf(id_temp, sizeof(id_temp), "s%lld", update->sender_user_id_);
results_inline[0] = create_inline_result(id_temp, "卖菜统计", "点击发送卖菜统计", msg_stat);
- effective_items_count ++;
+ effective_items_count++;
if (query) {
const size_t raw_query_len = strlen(update->query_);
@@ -101,7 +101,7 @@ int handle_inline(struct TdUpdateNewInlineQuery *update) {
}
for (; effective_items_count < sizeof(results_inline) / sizeof(struct TdInputInlineQueryResultArticle *);
- effective_items_count ++) {
+ effective_items_count++) {
r = sqlite3_step(stmt_query);
if (r == SQLITE_DONE) {
break;
@@ -112,13 +112,16 @@ int handle_inline(struct TdUpdateNewInlineQuery *update) {
int id = sqlite3_column_int(stmt_query, 0);
char *t = (char *) sqlite3_column_text(stmt_query, 1);
- char *url = (char *) sqlite3_column_text(stmt_query, 2);
+ int index = sqlite3_column_int(stmt_query, 2);
+
+ char descr_temp[32];
+ snprintf(descr_temp, sizeof(descr_temp), "#%d", index);
snprintf(id_temp, 32, "x_%d", id);
results_inline[effective_items_count] =
create_inline_result(id_temp,
t,
- url,
+ descr_temp,
t);
}