aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-10-19 17:39:57 -0700
committerAustin Hellyer <[email protected]>2016-10-20 06:38:34 -0700
commitecb95b511448ec409f3bf4b2677129a5bee7a82c (patch)
tree5167d07d9034f9d0a77818c4821d8e184f20bec1
parentInitial commit (diff)
downloadserenity-ecb95b511448ec409f3bf4b2677129a5bee7a82c.tar.xz
serenity-ecb95b511448ec409f3bf4b2677129a5bee7a82c.zip
Add ability to fully set a presence
The full presence setting allows for manually specifying the online status and afk field.
-rw-r--r--src/client/connection.rs16
-rw-r--r--src/client/context.rs13
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)