summaryrefslogtreecommitdiff
path: root/utils.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 /utils.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 'utils.c')
-rw-r--r--utils.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/utils.c b/utils.c
new file mode 100644
index 0000000..8215174
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,28 @@
+/*
+ * Created by yuuta on 3/19/23.
+ */
+
+#include "utils.h"
+
+#include <inttypes.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+
+uint32_t tg_url_get_index(const char *url) {
+ char *tok = strrchr(url, '/');
+
+ if (!tok) {
+ return 0;
+ }
+
+ char *endptr;
+ uintmax_t unum = strtoumax(tok + 1, &endptr, 10);
+ if (strcmp(endptr, "") != 0 || (unum == UINTMAX_MAX && errno == ERANGE)) {
+ return 0;
+ }
+ if (unum > UINT32_MAX) {
+ return 0;
+ }
+ return (uint32_t) unum;
+}