From ecb95b511448ec409f3bf4b2677129a5bee7a82c Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Wed, 19 Oct 2016 17:39:57 -0700 Subject: Add ability to fully set a presence The full presence setting allows for manually specifying the online status and afk field. --- src/client/connection.rs | 16 +++++++++++++++- src/client/context.rs | 13 ++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/client/connection.rs b/src/client/connection.rs index f321cfc..7a12a7e 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -166,10 +166,23 @@ impl Connection { } pub fn set_game(&self, game: Option) { + self.set_presence(game, OnlineStatus::Online, false) + } + + pub fn set_presence(&self, + game: Option, + status: OnlineStatus, + afk: bool) { + let status = match status { + OnlineStatus::Offline => OnlineStatus::Invisible, + other => other, + }; let msg = ObjectBuilder::new() .insert("op", 3) .insert_object("d", move |mut object| { - object = object.insert("idle_since", Value::Null); + object = object.insert("since", 0) + .insert("afk", afk) + .insert("status", status.name()); match game { Some(game) => { @@ -180,6 +193,7 @@ impl Connection { } }) .build(); + let _ = self.keepalive_channel.send(Status::SendMessage(msg)); } diff --git a/src/client/context.rs b/src/client/context.rs index 6f28a75..6402e9b 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -780,7 +780,18 @@ impl Context { } pub fn set_game(&self, game: Option) { - self.connection.lock().unwrap().set_game(game) + self.connection.lock() + .unwrap() + .set_presence(game, OnlineStatus::Online, false); + } + + pub fn set_presence(&self, + game: Option, + status: OnlineStatus, + afk: bool) { + self.connection.lock() + .unwrap() + .set_presence(game, status, afk) } pub fn start_guild_prune(&self, guild_id: G, days: u16) -- cgit v1.2.3