Add always_afk option

Add an option to always report client's status as afk, this will
hopefuly force push notifications to be delivered to other clients when
bitlbee is connected. See #131 for more info.
This commit is contained in:
Artem Savkov 2018-06-03 22:47:33 +02:00
parent 98f3893512
commit 870ead9c90
5 changed files with 30 additions and 12 deletions

5
README
View File

@ -165,6 +165,11 @@ This section describes options available through "account set" bitlbee command
friendship relationship with a user in addition to their actual away
status, and other users are added to channels.
- 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.
Debugging
---------
You can enable extra debug output for bitlbee-discord, by setting BITLBEE_DEBUG

View File

@ -93,3 +93,7 @@ Comma-separated list of channel patterns to exclude when auto-joining channels.
* matches any text, ? matches a single character.
For instance, "Foo.*,Bar.A" will exclude all channels from server "Foo" and channel "A" from server "Bar".
%
?always_afk
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.
%

View File

@ -26,7 +26,7 @@
#define DISCORD_STATUS_TIMEOUT 500
typedef struct {
discord_data *dd;
struct im_connection *ic;
gchar *status;
gchar *msg;
} status_data;
@ -374,22 +374,25 @@ void discord_ws_cleanup(discord_data *dd)
static gboolean discord_ws_status_postponed(status_data *sd, gint fd,
b_input_condition cond)
{
if (sd->dd->state != WS_READY) {
discord_data *dd = sd->ic->proto_data;
if (dd->state != WS_READY) {
return TRUE;
}
discord_ws_set_status(sd->dd, sd->status, sd->msg);
discord_ws_set_status(sd->ic, sd->status, sd->msg);
g_free(sd->msg);
g_free(sd->status);
g_free(sd);
sd->dd->status_timeout_id = 0;
dd->status_timeout_id = 0;
return FALSE;
}
void discord_ws_set_status(discord_data *dd, gchar *status, gchar *message)
void discord_ws_set_status(struct im_connection *ic, gchar *status,
gchar *message)
{
discord_data *dd = ic->proto_data;
GString *buf = g_string_new("");
gchar *msg = NULL;
gchar *stat = NULL;
@ -397,7 +400,7 @@ void discord_ws_set_status(discord_data *dd, gchar *status, gchar *message)
if (dd->state != WS_READY) {
if (dd->status_timeout_id == 0) {
status_data *sdata = g_new0(status_data, 1);
sdata->dd = dd;
sdata->ic = ic;
sdata->status = g_strdup(status);
sdata->msg = g_strdup(message);
dd->status_timeout_id = b_timeout_add(DISCORD_STATUS_TIMEOUT,
@ -420,10 +423,16 @@ void discord_ws_set_status(discord_data *dd, gchar *status, gchar *message)
g_string_printf(buf, "{\"op\":%d,\"d\":{\"since\":%llu,\"game\":null,\"afk\":true,\"status\":\"%s\"}}", OPCODE_STATUS_UPDATE, ((unsigned long long)time(NULL))*1000, stat);
}
} else {
char *afk;
if (set_getbool(&ic->acc->set, "always_afk")) {
afk = "true";
} else {
afk = "false";
}
if (message != NULL) { // game
g_string_printf(buf, "{\"op\":%d,\"d\":{\"since\":null,\"game\":{\"name\":\"%s\",\"type\":0},\"afk\":false,\"status\":\"online\"}}", OPCODE_STATUS_UPDATE, msg);
g_string_printf(buf, "{\"op\":%d,\"d\":{\"since\":null,\"game\":{\"name\":\"%s\",\"type\":0},\"afk\":%s,\"status\":\"online\"}}", OPCODE_STATUS_UPDATE, msg, afk);
} else { // default
g_string_printf(buf, "{\"op\":%d,\"d\":{\"since\":null,\"game\":null,\"afk\":false,\"status\":\"online\"}}", OPCODE_STATUS_UPDATE);
g_string_printf(buf, "{\"op\":%d,\"d\":{\"since\":null,\"game\":null,\"afk\":%s,\"status\":\"online\"}}", OPCODE_STATUS_UPDATE, afk);
}
}

View File

@ -37,5 +37,6 @@ gboolean discord_ws_keepalive_loop(gpointer data, gint fd,
int discord_ws_init(struct im_connection *ic, discord_data *dd);
void discord_ws_cleanup(discord_data *dd);
void discord_ws_set_status(discord_data *dd, gchar *status, gchar *message);
void discord_ws_set_status(struct im_connection *ic, gchar *status,
gchar *message);
void discord_ws_sync_server(discord_data *dd, const char *id);

View File

@ -89,6 +89,7 @@ static void discord_init(account_t *acc)
s = set_add(&acc->set, "mention_ignorecase", "off", set_eval_bool, 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, "auto_join", "off", set_eval_bool, acc);
s->flags |= ACC_SET_OFFLINE_ONLY;
@ -297,9 +298,7 @@ static GList *discord_away_states(struct im_connection *ic)
static void discord_set_away(struct im_connection *ic, char *state,
char *message)
{
discord_data *dd = ic->proto_data;
discord_ws_set_status(dd, state, message);
discord_ws_set_status(ic, state, message);
}
G_MODULE_EXPORT void init_plugin(void)