Skip to content

Commit

Permalink
Add support for away state/status messages.
Browse files Browse the repository at this point in the history
Add support for setting away state along with away message and status messages
(help set status).
  • Loading branch information
sm00th committed Apr 10, 2016
1 parent 710d3f9 commit f9b0ec3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/discord-websockets.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Artem Savkov <artem.savkov@gmail.com>
* Copyright 2015-2016 Artem Savkov <artem.savkov@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -223,3 +223,17 @@ void discord_ws_cleanup(discord_data *dd)
lws_context_destroy(dd->lwsctx);
}
}

void discord_ws_set_status(discord_data *dd, gboolean idle, gchar *message)
{
GString *buf = g_string_new("");
if (idle == TRUE) {
g_string_printf(buf, "{\"op\":3,\"d\":{\"idle_since\":%tu,\"game\":{\"name\":\"%s\"}}}", time(NULL), message);
} else if (message != NULL) {
g_string_printf(buf, "{\"op\":3,\"d\":{\"idle_since\":null,\"game\":{\"name\":\"%s\"}}}", message);
} else {
g_string_printf(buf, "{\"op\":3,\"d\":{\"idle_since\":null,\"game\":{\"name\":null}}}");
}
discord_ws_send_payload(dd->lws, buf->str, buf->len);
g_string_free(buf, TRUE);
}
1 change: 1 addition & 0 deletions src/discord-websockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ 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, gboolean idle, gchar *message);
24 changes: 23 additions & 1 deletion src/discord.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ static void discord_init(account_t *acc)

s = set_add(&acc->set, "max_backlog", "50", set_eval_int, acc);
s->flags |= ACC_SET_OFFLINE_ONLY;

acc->flags |= ACC_FLAG_AWAY_MESSAGE;
acc->flags |= ACC_FLAG_STATUS_MESSAGE;
}

static void discord_login(account_t *acc)
Expand Down Expand Up @@ -91,6 +94,23 @@ static gboolean discord_is_self(struct im_connection *ic, const char *who)
return !g_strcmp0(dd->uname, who);
}

static GList *discord_away_states(struct im_connection *ic)
{
static GList *m = NULL;

m = g_list_append(m, "Idle");

return m;
}

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 != NULL, message);
}

G_MODULE_EXPORT void init_plugin(void)
{
struct prpl *dpp;
Expand All @@ -103,7 +123,9 @@ G_MODULE_EXPORT void init_plugin(void)
.chat_msg = discord_chat_msg,
.buddy_msg = discord_buddy_msg,
.handle_cmp = g_strcmp0,
.handle_is_self = discord_is_self
.handle_is_self = discord_is_self,
.away_states = discord_away_states,
.set_away = discord_set_away
};
dpp = g_memdup(&pp, sizeof pp);
register_protocol(dpp);
Expand Down

0 comments on commit f9b0ec3

Please sign in to comment.