diff options
author | Trumeet <yuuta@yuuta.moe> | 2023-03-19 17:04:21 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2023-03-19 17:04:21 -0700 |
commit | 261d0f23f25151068c58db88c447289a882b4a6e (patch) | |
tree | 04587186ec0df7020775b58d33c75f7d8841b84d /utils.c | |
parent | 92829eb1abde84916d92b22e107fc3ae7dc4bad2 (diff) | |
download | ksyxbot-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.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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; +} |