From fd8213fbd9e993a0328aebe34e4aa2c6aea57a1c Mon Sep 17 00:00:00 2001 From: Artem Savkov Date: Wed, 25 Jul 2018 16:34:09 +0200 Subject: [PATCH] Add "emoji_urls" boolean option Add an option to control whether to show emoji urls next to the text alias or not. Fixes: #169 --- README | 4 ++++ doc/discord-help.txt | 4 ++++ src/discord-handlers.c | 23 ++++++++++++++++------- src/discord.c | 1 + 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README b/README index 6601332..aac9b47 100644 --- a/README +++ b/README @@ -170,6 +170,10 @@ This section describes options available through "account set" bitlbee command This feature is not properly documented in official docs, but it presumably can force push notifications to other clients when bitlbee is connected. + - emoji_urls (type: boolean; default: on) + Controls whether bitlbee-discord would display an url to emoji image next + to it's text alias. + Debugging --------- You can enable extra debug output for bitlbee-discord, by setting BITLBEE_DEBUG diff --git a/doc/discord-help.txt b/doc/discord-help.txt index a804c12..9f3c646 100644 --- a/doc/discord-help.txt +++ b/doc/discord-help.txt @@ -97,3 +97,7 @@ For instance, "Foo.*,Bar.A" will exclude all channels from server "Foo" and chan always_afk (type: boolean; default: off) When enabled bitlbee-discord would always report client's status as afk. This feature is not properly documented in official docs, but it presumably can force push notifications to other clients when bitlbee is connected. % +?emoji_urls +emoji_urls (type: boolean; default: on) +Controls whether bitlbee-discord would display an url to emoji image next to it's text alias. +% diff --git a/src/discord-handlers.c b/src/discord-handlers.c index a466c4d..6ef48af 100644 --- a/src/discord-handlers.c +++ b/src/discord-handlers.c @@ -603,7 +603,7 @@ static gboolean discord_prepare_message(struct im_connection *ic, "author"), "username")); const char *nonce = json_o_str(minfo, "nonce"); gboolean is_self = discord_is_self(ic, author); - + time_t tstamp = use_tstamp ? parse_iso_8601(json_o_str(minfo, "timestamp")) : 0; // Don't echo self messages that we sent in this session @@ -673,15 +673,24 @@ static gboolean discord_prepare_message(struct im_connection *ic, } // Replace animated emoji with code and a URL - GRegex *emoji_regex_a = g_regex_new("", 0, 0, NULL); - gchar *emoji_msg_a = g_regex_replace(emoji_regex_a, msg, -1, 0, "\\1 ", 0, NULL); + GRegex *emoji_regex = g_regex_new("", 0, 0, NULL); + gchar *emoji_msg; + if (set_getbool(&ic->acc->set, "emoji_urls")) { + emoji_msg = g_regex_replace(emoji_regex, msg, -1, 0, "\\1 ", 0, NULL); + } else { + emoji_msg = g_regex_replace(emoji_regex, msg, -1, 0, "\\1", 0, NULL); + } g_free(msg); - msg = emoji_msg_a; - g_regex_unref(emoji_regex_a); + msg = emoji_msg; + g_regex_unref(emoji_regex); // Replace custom emoji with code and a URL - GRegex *emoji_regex = g_regex_new("<(:[^:]+:)(\\d+)>", 0, 0, NULL); - gchar *emoji_msg = g_regex_replace(emoji_regex, msg, -1, 0, "\\1 ", 0, NULL); + emoji_regex = g_regex_new("<(:[^:]+:)(\\d+)>", 0, 0, NULL); + if (set_getbool(&ic->acc->set, "emoji_urls")) { + emoji_msg = g_regex_replace(emoji_regex, msg, -1, 0, "\\1 ", 0, NULL); + } else { + emoji_msg = g_regex_replace(emoji_regex, msg, -1, 0, "\\1", 0, NULL); + } g_free(msg); msg = emoji_msg; g_regex_unref(emoji_regex); diff --git a/src/discord.c b/src/discord.c index 9954b66..cb41f33 100644 --- a/src/discord.c +++ b/src/discord.c @@ -90,6 +90,7 @@ static void discord_init(account_t *acc) s = set_add(&acc->set, "incoming_me_translation", "on", set_eval_bool, acc); s = set_add(&acc->set, "fetch_pinned", "off", set_eval_bool, acc); s = set_add(&acc->set, "always_afk", "off", set_eval_bool, acc); + s = set_add(&acc->set, "emoji_urls", "on", set_eval_bool, acc); s = set_add(&acc->set, "auto_join", "off", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY;