summaryrefslogtreecommitdiff
path: root/stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'stat.c')
-rw-r--r--stat.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/stat.c b/stat.c
new file mode 100644
index 0000000..387bab6
--- /dev/null
+++ b/stat.c
@@ -0,0 +1,46 @@
+/*
+ * Created by yuuta on 4/5/22.
+ */
+
+#include "logic.h"
+#include "log.h"
+#include "tdutils.h"
+#include "db.h"
+
+void stat(struct TdMessage *msg) {
+ int r;
+ char m[2048];
+ sqlite3_stmt *stmt = NULL;
+ if ((r = sqlite3_prepare_v2(db, "SELECT COUNT(user), SUM(i) FROM stats;", -1, &stmt, NULL))) {
+ goto sql_err;
+ sql_err:
+ {
+ snprintf(m, 1024, "Cannot query statistics: %s.", sqlite3_errstr(r));
+ LOGEV("%s", m);
+ if (stmt) sqlite3_finalize(stmt);
+ goto send;
+ }
+ }
+ if ((r = sqlite3_step(stmt)) != SQLITE_ROW) goto sql_err;
+ snprintf(m, 1024, "普天之下,莫非 K 土。TGCN 共有 %d 位 K 教授的虔诚学生卖了 %d 句菜。",
+ sqlite3_column_int(stmt, 0),
+ sqlite3_column_int(stmt, 1));
+ sqlite3_finalize(stmt);
+ goto send;
+ send:
+ td_send(TdCreateObjectSendMessage(msg->chat_id_,
+ 0,
+ msg->id_,
+ TdCreateObjectMessageSendOptions(false, false, true, NULL),
+ NULL,
+ (struct TdInputMessageContent *)
+ TdCreateObjectInputMessageText(
+ TdCreateObjectFormattedText(m,
+ (struct TdVectorTextEntity *)
+ TdCreateObjectVectorObject(
+ 0, NULL)
+ ),
+ false,
+ false)),
+ NULL, NULL);
+} \ No newline at end of file