summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-05-05 12:56:41 +0200
committersijanec <anton@sijanec.eu>2021-05-05 12:56:41 +0200
commit42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879 (patch)
treeeb9f13bfc2962a62d716975f0fd9a43f683612c0
parentdodal podporo za direct messages (diff)
downloaddiscord.c-42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879.tar
discord.c-42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879.tar.gz
discord.c-42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879.tar.bz2
discord.c-42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879.tar.lz
discord.c-42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879.tar.xz
discord.c-42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879.tar.zst
discord.c-42bdf4a3ee0ad23b4eaf5e1b6a7e61a1f999d879.zip
Diffstat (limited to '')
-rw-r--r--debian/README.Debian17
-rw-r--r--debian/changelog38
-rw-r--r--debian/compat1
-rw-r--r--debian/control16
-rw-r--r--debian/copyright10
-rw-r--r--debian/discord.c.substvars3
-rw-r--r--debian/files3
-rw-r--r--debian/patches/series1
-rwxr-xr-xdebian/rules4
-rw-r--r--debian/source/format1
-rw-r--r--debian/source/local-options2
-rw-r--r--debian/watch2
-rw-r--r--src/api.c23
-rw-r--r--src/i18n.h1
-rw-r--r--src/ui.c5
15 files changed, 118 insertions, 9 deletions
diff --git a/debian/README.Debian b/debian/README.Debian
new file mode 100644
index 0000000..b23ea1f
--- /dev/null
+++ b/debian/README.Debian
@@ -0,0 +1,17 @@
+discord.c for Debian
+
+an alternative client for the discord messaging platform, written in the C programming language.
+
+makes use of libncursesw6, libcurl4-openssl-dev, libcjson-dev
+
+reads email and password from arguments -e and -p to command discord.c or from environment variables DC_E and DC_P
+
+after launching program, start the network thread with command /n 1 - that logs you in and fetches guilds and channels
+
+join a channel with /join, list channels with /channels, list guilds with /guilds
+
+send text with enter key
+
+you can /join and /unjoin many channels, then switch with [TAB] to which channel you will send messages.
+
+ -- Anton Luka Šijanec <anton@sijanec.eu> Mon, 22 Mar 2021 19:45:04 +0100
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..dd8fc35
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,38 @@
+discord.c (0.0.3-0) stable; urgency=low
+
+ * added support for attachment viewing as links
+
+ -- Anton Luka Šijanec <anton@sijanec.eu> Wed, 05 May 2021 12:50:00 +0200
+
+discord.c (0.0.2-2) stable; urgency=low
+
+ * fixed debian source distribution
+
+ -- Anton Luka Šijanec <anton@sijanec.eu> Sun, 04 Apr 2021 14:00:00 +0200
+
+discord.c (0.0.2-1) stable; urgency=low
+
+ * added direct messaging support as a virtual guild 0
+
+ -- Anton Luka Šijanec <anton@sijanec.eu> Thu, 25 Mar 2021 22:10:00 +0100
+
+discord.c (0.0.1-1) stable; urgency=low
+
+ * multichannel support (use /join and /leave, [TAB] key to switch channels you
+ send to)
+ * now ui says to turn on networking thread with /n 1 when it's off and no
+ channels are joined (start of the program)
+ fixed bugs:
+ * when name of channel/user in text chat log contains an unicode character,
+ %08.8s obviously misses. this is now fixed by moving cursor directly (:
+
+ (small bug detected after release: no focused channel when leaving focused
+ channel, use [TAB] to fix (; )
+
+ -- Anton Luka Šijanec <anton@sijanec.eu> Mon, 22 Mar 2021 19:45:00 +0100
+
+discord.c (0.0.0-1) stable; urgency=low
+
+ * Initial proof of concept release.
+
+ -- Anton Luka Šijanec <anton@sijanec.eu> Thu, 18 Mar 2021 18:23:04 +0100
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..b4de394
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+11
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..a660ede
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,16 @@
+Source: discord.c
+Section: utils
+Priority: optional
+Maintainer: Anton Luka Šijanec <anton@sijanec.eu>
+Build-Depends: debhelper (>=11~),
+ libcjson-dev,
+ libcurl4-openssl-dev,
+ libncursesw6
+Standards-Version: 4.1.4
+Homepage: https://git.sijanec.eu/sijanec/discord.c
+
+Package: discord.c
+Architecture: any
+Multi-Arch: foreign
+Depends: ${misc:Depends}, ${shlibs:Depends}
+Description: a lightweight chat client that connects to the discord.com chatting platform
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..bd9b7a2
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,10 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: discord.c
+Source: <https://git.sijanec.eu/sijanec/discord.c>
+#
+# Please double check copyright with the licensecheck(1) command.
+
+#----------------------------------------------------------------------------
+# Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following
+# license/copyright files.
+Anton Luka Šijanec 2021
diff --git a/debian/discord.c.substvars b/debian/discord.c.substvars
new file mode 100644
index 0000000..939d5bd
--- /dev/null
+++ b/debian/discord.c.substvars
@@ -0,0 +1,3 @@
+shlibs:Depends=libc6 (>= 2.14), libcjson1 (>= 1.7.5), libcurl4 (>= 7.16.2), libncursesw6 (>= 6), libtinfo6 (>= 6)
+misc:Depends=
+misc:Pre-Depends=
diff --git a/debian/files b/debian/files
new file mode 100644
index 0000000..428f52a
--- /dev/null
+++ b/debian/files
@@ -0,0 +1,3 @@
+discord.c-dbgsym_0.0.2-2_amd64.deb debug optional automatic=yes
+discord.c_0.0.2-2_amd64.buildinfo utils optional
+discord.c_0.0.2-2_amd64.deb utils optional
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..4a97dfa
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+# You must remove unused comment lines for the released package.
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..4f2c774
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,4 @@
+#!/usr/bin/make -f
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (quilt)
diff --git a/debian/source/local-options b/debian/source/local-options
new file mode 100644
index 0000000..00131ee
--- /dev/null
+++ b/debian/source/local-options
@@ -0,0 +1,2 @@
+#abort-on-upstream-changes
+#unapply-patches
diff --git a/debian/watch b/debian/watch
new file mode 100644
index 0000000..76575dc
--- /dev/null
+++ b/debian/watch
@@ -0,0 +1,2 @@
+# You must remove unused comment lines for the released package.
+version=3
diff --git a/src/api.c b/src/api.c
index cf24448..168fcf2 100644
--- a/src/api.c
+++ b/src/api.c
@@ -52,10 +52,7 @@
- use posixes pthread_rwlock_init(3POSIX) mutexes to allow reading to arrays and other types
- do not have the illusion that you can append to an array of pointers without non-shared locking, because you realloc that array of pointers, appending must also be non-shared locked
- _free functions shall never fail - do not use timed locks
- TODO: make it work.
- i changed arrays from type arrays to type pointer arrays, so code that allocates must be reimplemented, also struct free functions and -> instead of . in array elements
- - make mutex locks in api and ui thread
- - make the ui thread
*/
struct dc_error {
size_t line;
@@ -77,6 +74,7 @@ struct dc_message {
char * username; /* yesfree */
int discriminator;
char * content; /* yesfree */
+ char * attachment; /* yesfree - url to the attachment should it exist */
time_t time;
_Atomic(struct dc_channel *) channel; /* nofree */
unsigned short int tts;
@@ -86,6 +84,7 @@ struct dc_message {
void dc_message_free (struct dc_message * m) { /* noui, noapi, nolock - only called by dc_channel_free */
free(m->username); m->username = NULL;
free(m->content); m->content = NULL;
+ free(m->attachment); m->attachment = NULL;
m->channel = NULL;
m->tts = 0;
m->discriminator = -1;
@@ -572,7 +571,7 @@ int dc_send_message (struct dc_message * m) { /* nolock - once message is append
cJSON * json = cJSON_CreateObject();
cJSON * nons = cJSON_CreateNumber(rand());
cJSON_AddItemToObject(json, "nonce", nons);
- cJSON * content = cJSON_CreateString(m->content);
+ cJSON * content = cJSON_CreateString(m->content ? m->content : "dc_send_message(): !m->content");
cJSON_AddItemToObject(json, "content", content);
cJSON * tts = m->tts ? cJSON_CreateTrue() : cJSON_CreateFalse();
cJSON_AddItemToObject(json, "tts", tts);
@@ -649,8 +648,14 @@ int dc_fetch_messages (struct dc_channel * ch) {
char * id = cJSON_GetStringValue(cJSON_GetObjectItem(message, "id"));
char * discriminator = cJSON_GetStringValue(cJSON_GetObjectItem2(message, "author", "discriminator"));
char * username = cJSON_GetStringValue(cJSON_GetObjectItem2(message, "author", "username"));
- if (!id || !timestamp || !content || !username || !discriminator) {
- DC_CLIENT_ERROR(c, "!id || !timestamp || !content || !username || discriminator < 0");
+ char * attachment = NULL;
+ cJSON * attachmentj = NULL;
+ cJSON * attachments = cJSON_GetObjectItem(message, "attachments");
+ cJSON_ArrayForEach(attachmentj, attachments)
+ if ((attachment = cJSON_GetStringValue(cJSON_GetObjectItem(attachmentj, "url"))))
+ break; /* we only extract the first attachment */
+ if (!id || !timestamp || (!content && !attachment) || !username || !discriminator) {
+ DC_CLIENT_ERROR(c, "!id || (!timestamp && !attachment) || !content || !username || discriminator < 0");
continue;
}
int kratekts = 0;
@@ -690,8 +695,10 @@ int dc_fetch_messages (struct dc_channel * ch) {
/* DC_CLIENT_ERROR(c, "recvd msg %llu", idull); */ /* remember: continue in a nested forloop is not useful in some cases (: */
DC_FMTM = calloc(1, sizeof(struct dc_message));
DC_FMTM->time = mktime(&tm);
- DC_FMTM->content = malloc(strlen(content)+1);
- strcpy(DC_FMTM->content, content);
+ if (content)
+ strcpy(DC_FMTM->content = malloc(strlen(content)+1), content);
+ if (attachment)
+ strcpy(DC_FMTM->attachment = malloc(strlen(attachment)+1), attachment);
DC_FMTM->username = malloc(strlen(username)+1);
strcpy(DC_FMTM->username, username);
DC_FMTM->id = idull;
diff --git a/src/i18n.h b/src/i18n.h
index 1468e83..acb8946 100644
--- a/src/i18n.h
+++ b/src/i18n.h
@@ -26,3 +26,4 @@
#define DC_I18N_UI_SLOWMODE "na tem kanalu po poslanem sporočilu novega ne smeš poslati %ds. počakaj še %ds in poskusi znova."
#define DC_I18N_UI_LINE_BEFORE_NETWORK "discord.c | najprej zaženi mrežno nit z ukazom /n 1"
#define DC_I18N_DMS "zasebni pogovori (virtualna skupina kanalov)"
+#define DC_I18N_ATTACHMENT "priponka"
diff --git a/src/ui.c b/src/ui.c
index e741335..725e7cc 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -28,7 +28,9 @@ int dc_ui_print_message (WINDOW * textwin, struct dc_message * msg2do) {
DC_SIMPLEPRINT(textwin, 4, "%.33s", msg2do->username);
getyx(textwin, y, x);
wmove(textwin, y, 37); /* quick mafs */
- DC_SIMPLEPRINT(textwin, 3, ": %s\n", msg2do->content);
+ DC_SIMPLEPRINT(textwin, 3, ": %s%s", msg2do->content ? msg2do->content : "", msg2do->attachment ? " " : "\n");
+ if (msg2do->attachment)
+ DC_SIMPLEPRINT(textwin, 8, "[" DC_I18N_ATTACHMENT "]: %s\n", msg2do->attachment);
msg2do->status = 1;
if (x); /* set but not used */
return 1;
@@ -194,6 +196,7 @@ int dc_ui_thread (struct dc_thread_control * t) {
init_pair(5, COLOR_CYAN, COLOR_BLACK);
init_pair(6, COLOR_BLACK, COLOR_CYAN);
init_pair(7, COLOR_MAGENTA, COLOR_BLACK);
+ init_pair(8, COLOR_BLUE, COLOR_WHITE);
keypad(stdscr, TRUE);
getmaxyx(stdscr, y, x); /* to je macro, zato y in x nista kazalca (;: */
ui.maxy = y;