diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/connection.rs | 16 | ||||
| -rw-r--r-- | src/client/context.rs | 13 |
2 files changed, 27 insertions, 2 deletions
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<Game>) { + self.set_presence(game, OnlineStatus::Online, false) + } + + pub fn set_presence(&self, + game: Option<Game>, + 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<Game>) { - self.connection.lock().unwrap().set_game(game) + self.connection.lock() + .unwrap() + .set_presence(game, OnlineStatus::Online, false); + } + + pub fn set_presence(&self, + game: Option<Game>, + status: OnlineStatus, + afk: bool) { + self.connection.lock() + .unwrap() + .set_presence(game, status, afk) } pub fn start_guild_prune<G>(&self, guild_id: G, days: u16) |