Add "emoji_urls" boolean option

Add an option to control whether to show emoji urls next to the text
alias or not.

Fixes: #169
This commit is contained in:
Artem Savkov 2018-07-25 16:34:09 +02:00
parent ea210b62c4
commit fd8213fbd9
4 changed files with 25 additions and 7 deletions

4
README
View File

@ -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

View File

@ -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.
%

View File

@ -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("<a(:[^:]+:)(\\d+)>", 0, 0, NULL);
gchar *emoji_msg_a = g_regex_replace(emoji_regex_a, msg, -1, 0, "\\1 <https://cdn.discordapp.com/emojis/\\2.gif>", 0, NULL);
GRegex *emoji_regex = g_regex_new("<a(:[^:]+:)(\\d+)>", 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 <https://cdn.discordapp.com/emojis/\\2.gif>", 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 <https://cdn.discordapp.com/emojis/\\2.png>", 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 <https://cdn.discordapp.com/emojis/\\2.png>", 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);

View File

@ -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;