diff options
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | src/api.c | 18 | ||||
-rw-r--r-- | src/i18n.h | 2 |
4 files changed, 29 insertions, 15 deletions
@@ -1,9 +1,20 @@ +DESTDIR=/ + default: - gcc -Wall -pedantic -g -Ilib -Isrc -I. -pthread $$(ncursesw6-config --cflags --libs) src/main.c -lcurl -lformw -lm -odiscord.c -prepare: - wget https://raw.githubusercontent.com/DaveGamble/cJSON/master/cJSON.c -O lib/cJSON.c - wget https://raw.githubusercontent.com/DaveGamble/cJSON/master/cJSON.h -O lib/cJSON.h + gcc -Wall -pedantic -g -Isrc -I. -pthread $$(ncursesw6-config --cflags --libs) src/main.c -lcjson -lcurl -lformw -lm -odiscord.c + +install: + mkdir -p $(DESTDIR)/usr/bin/ + cp discord.c $(DESTDIR)/usr/bin/ + +distclean: + rm discord.c -f + clean: - rm lib/cJSON.c lib/cJSON.h + rm discord.c -f + +prepare: + sudo apt install libncursesw6 libcurl4-openssl-dev libcjson-dev -y + valgrind: valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt --suppressions=/usr/lib/valgrind/ncurses.supp --suppressions=misc/openssl.supp ./discord.c @@ -9,7 +9,8 @@ an alternative client for the discord messaging platform, written in the C progr * GNU compiler collection * GNU Make * libcurl 7.17.0 or newer with HTTPS support -* ncursesw 6 +* ncursesw6 +* libcjson-dev ## instructions @@ -7,8 +7,7 @@ #include <i18n.h> #include <string.h> #include <lib.c> -#include <cJSON.h> -#include <cJSON.c> +#include <cjson/cJSON.h> #include <time.h> #include <stdarg.h> #include <printf.h> @@ -496,14 +495,17 @@ int dc_fetch_channels (struct dc_guild * g) { char * topic = cJSON_GetStringValue(cJSON_GetObjectItem(channel, "topic")); char * name = cJSON_GetStringValue(cJSON_GetObjectItem(channel, "name")); char * id = cJSON_GetStringValue(cJSON_GetObjectItem(channel, "id")); - double type = cJSON_GetNumberValue(cJSON_GetObjectItem(channel, "type")); - double slowmode = cJSON_GetNumberValue(cJSON_GetObjectItem(channel, "rate_limit_per_user")); - if (!id || !name || type == NAN) { - DC_CLIENT_ERROR(c, "!id || !name || type == NAN"); + cJSON * type = cJSON_GetObjectItem(channel, "type"); + cJSON * jsonslowmode = cJSON_GetObjectItem(channel, "rate_limit_per_user"); + if (!cJSON_IsNumber(type) || !id || !name) { + DC_CLIENT_ERROR(c, "!cJSON_IsNumber(jsontype) || !id || !name"); continue; } - if (type != 0) /* if it's not a text channel (z. B. voice channel, category, ...) */ + if (type->valueint != 0) /* if it's not a text channel (z. B. voice channel, category, ...) */ continue; + int slowmode = 0; + if (cJSON_IsNumber(jsonslowmode)) + slowmode = jsonslowmode->valueint; if (!topic) topic = ""; unsigned long long int idull = strtoull(id, NULL, 10); @@ -523,7 +525,7 @@ int dc_fetch_channels (struct dc_guild * g) { g->channels[g->channels_sizeof-1]->guild = g; g->channels[g->channels_sizeof-1]->messages = NULL; g->channels[g->channels_sizeof-1]->messages_sizeof = 0; - g->channels[g->channels_sizeof-1]->slowmode = slowmode != NAN ? slowmode : 0; + g->channels[g->channels_sizeof-1]->slowmode = slowmode; } if (DC_CUE(c, c->guilds_lock)) {rs = -8; goto rc;} rc: @@ -21,6 +21,6 @@ #define DC_I18N_HITRL "zmanjkalo dovoljenih zahtev na strežnik. API nit bo čakala " /* and then print seconds */ #define DC_I18N_UI_CNF "nepoznan ukaz" #define DC_I18N_UI_NOT_JOINED "niste pridruženi v kanal. uporabite ukaz /pridruži" -#define DC_I18N_CHANNEL_WILL_BE_REMOVED "kanal bo odstranjen iz lokalnega seznama kanalov" +#define DC_I18N_CHANNEL_WILL_BE_REMOVED "kanal bo odstranjen z lokalnega seznama kanalov" #define DC_I18N_UI_EMPTYMSG "ne moreš poslati praznega sporočila." #define DC_I18N_UI_SLOWMODE "na tem kanalu po poslanem sporočilu novega ne smeš poslati %ds. počakaj še %ds in poskusi znova." |