summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-10-22 18:13:54 -0700
committerTrumeet <yuuta@yuuta.moe>2022-10-22 18:13:54 -0700
commit59ed4b1857b9f4885a6e4d5bc8f3c3a548953b56 (patch)
tree3b16ad453383df91478c6defbf8fadfe0f227380
parent57bd18ef88e48c18abf156b2635675df56c4a67e (diff)
downloadksyxbot-59ed4b1857b9f4885a6e4d5bc8f3c3a548953b56.tar
ksyxbot-59ed4b1857b9f4885a6e4d5bc8f3c3a548953b56.tar.gz
ksyxbot-59ed4b1857b9f4885a6e4d5bc8f3c3a548953b56.tar.bz2
ksyxbot-59ed4b1857b9f4885a6e4d5bc8f3c3a548953b56.zip
Add running time to /stat
-rw-r--r--botd.h3
-rw-r--r--main.c1
-rw-r--r--stat.c5
3 files changed, 8 insertions, 1 deletions
diff --git a/botd.h b/botd.h
index 5bdd8fe..84ae7f2 100644
--- a/botd.h
+++ b/botd.h
@@ -6,10 +6,13 @@
#define KSYXBOT_BOTD_H
#include <stdbool.h>
+#include <time.h>
#define ADMIN 2122005901
#define CHANNEL -1001794945713
+extern time_t start_time;
+
extern int td;
typedef struct cmd_s {
diff --git a/main.c b/main.c
index c9a9a33..f30a01f 100644
--- a/main.c
+++ b/main.c
@@ -27,6 +27,7 @@ static void ate(void) {
}
int main(int argc, char **argv) {
+ start_time = time(NULL);
atexit(&ate);
parse_cmdline(argc, argv);
db_init();
diff --git a/stat.c b/stat.c
index 5f0a631..2c1323e 100644
--- a/stat.c
+++ b/stat.c
@@ -6,6 +6,7 @@
#include "log.h"
#include "tdutils.h"
#include "db.h"
+#include "botd.h"
#include <stdlib.h>
#include <string.h>
@@ -41,7 +42,9 @@ void stat(struct TdMessage *msg) {
if ((r = sqlite3_prepare_v2(db, "SELECT COUNT(t) FROM says;", -1, &stmt, NULL))) goto sql_err;
if ((r = sqlite3_step(stmt)) != SQLITE_ROW) goto sql_err;
size_t len = strlen(m);
- snprintf(&m[len], 1024 - len, "\n\n共有 %d 句教授语录。", sqlite3_column_int(stmt, 0));
+ snprintf(&m[len], 1024 - len, "\n\n共有 %d 句教授语录。\nBot 已运行 %ld 秒。",
+ sqlite3_column_int(stmt, 0),
+ time(NULL) - start_time);
sqlite3_finalize(stmt);
goto send;
send: