aboutsummaryrefslogtreecommitdiff
path: root/src/client/bridge
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-04-27 08:05:56 -0700
committerKen Swenson <[email protected]>2018-11-06 20:35:51 -0500
commit3e54f4c524ad609b31c061286eab971f0084a4c5 (patch)
tree907334e8b8a2823696f2b96456aca062f3d00a40 /src/client/bridge
parentMake builders mutably borrowed (diff)
downloadserenity-3e54f4c524ad609b31c061286eab971f0084a4c5.tar.xz
serenity-3e54f4c524ad609b31c061286eab971f0084a4c5.zip
Add Rich Presence parsing support
Adds support for parsing Rich Presences. This can not be used for setting activities with bots. Upgrade path: Basically change your import and usage from `serenity::model::gateway::Game` to `serenity::model::gateway::Activity`.
Diffstat (limited to 'src/client/bridge')
-rw-r--r--src/client/bridge/gateway/shard_messenger.rs50
-rw-r--r--src/client/bridge/gateway/shard_runner.rs16
-rw-r--r--src/client/bridge/gateway/shard_runner_message.rs12
3 files changed, 28 insertions, 50 deletions
diff --git a/src/client/bridge/gateway/shard_messenger.rs b/src/client/bridge/gateway/shard_messenger.rs
index 11e75ce..21e586a 100644
--- a/src/client/bridge/gateway/shard_messenger.rs
+++ b/src/client/bridge/gateway/shard_messenger.rs
@@ -7,11 +7,11 @@ use websocket::message::OwnedMessage;
/// A lightweight wrapper around an mpsc sender.
///
/// This is used to cleanly communicate with a shard's respective
-/// [`ShardRunner`]. This can be used for actions such as setting the game via
-/// [`set_game`] or shutting down via [`shutdown`].
+/// [`ShardRunner`]. This can be used for actions such as setting the activity
+/// via [`set_activity`] or shutting down via [`shutdown`].
///
/// [`ShardRunner`]: struct.ShardRunner.html
-/// [`set_game`]: #method.set_game
+/// [`set_activity`]: #method.set_activity
/// [`shutdown`]: #method.shutdown
#[derive(Clone, Debug)]
pub struct ShardMessenger {
@@ -124,13 +124,13 @@ impl ShardMessenger {
});
}
- /// Sets the user's current game, if any.
+ /// Sets the user's current activity, if any.
///
/// Other presence settings are maintained.
///
/// # Examples
///
- /// Setting the current game to playing `"Heroes of the Storm"`:
+ /// Setting the current activity to playing `"Heroes of the Storm"`:
///
/// ```rust,no_run
/// # extern crate parking_lot;
@@ -146,19 +146,9 @@ impl ShardMessenger {
/// #
/// # let mut shard = Shard::new(mutex.clone(), mutex, [0, 1]).unwrap();
/// #
- /// # #[cfg(feature = "model")]
- /// use serenity::model::gateway::Game;
- /// # #[cfg(not(feature = "model"))]
- /// use serenity::model::gateway::{Game, GameType};
- ///
- /// # #[cfg(feature = "model")]
- /// shard.set_game(Some(Game::playing("Heroes of the Storm")));
- /// # #[cfg(not(feature = "model"))]
- /// shard.set_game(Some(Game {
- /// kind: GameType::Playing,
- /// name: "Heroes of the Storm".to_owned(),
- /// url: None,
- /// }));
+ /// use serenity::model::gateway::Activity;
+ ///
+ /// shard.set_activity(Some(Activity::playing("Heroes of the Storm")));
/// # Ok(())
/// # }
/// #
@@ -166,12 +156,8 @@ impl ShardMessenger {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn set_game<T: Into<Game>>(&self, game: Option<T>) {
- self._set_game(game.map(Into::into))
- }
-
- fn _set_game(&self, game: Option<Game>) {
- let _ = self.send(ShardRunnerMessage::SetGame(game));
+ pub fn set_activity(&self, activity: Option<Activity>) {
+ let _ = self.send(ShardRunnerMessage::SetActivity(activity));
}
/// Sets the user's full presence information.
@@ -198,9 +184,9 @@ impl ShardMessenger {
/// #
/// # let mut shard = Shard::new(mutex.clone(), mutex, [0, 1]).unwrap();
/// #
- /// use serenity::model::{Game, OnlineStatus};
+ /// use serenity::model::{Activity, OnlineStatus};
///
- /// shard.set_presence(Some(Game::playing("Heroes of the Storm")), OnlineStatus::Online);
+ /// shard.set_presence(Some(Activity::playing("Heroes of the Storm")), OnlineStatus::Online);
/// # Ok(())
/// # }
/// #
@@ -208,20 +194,12 @@ impl ShardMessenger {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn set_presence<T: Into<Game>>(
- &self,
- game: Option<T>,
- status: OnlineStatus,
- ) {
- self._set_presence(game.map(Into::into), status)
- }
-
- fn _set_presence(&self, game: Option<Game>, mut status: OnlineStatus) {
+ pub fn set_presence(&self, activity: Option<Activity>, mut status: OnlineStatus) {
if status == OnlineStatus::Offline {
status = OnlineStatus::Invisible;
}
- let _ = self.send(ShardRunnerMessage::SetPresence(status, game));
+ let _ = self.send(ShardRunnerMessage::SetPresence(status, activity));
}
/// Sets the user's current online status.
diff --git a/src/client/bridge/gateway/shard_runner.rs b/src/client/bridge/gateway/shard_runner.rs
index ea1fad6..0f244bd 100644
--- a/src/client/bridge/gateway/shard_runner.rs
+++ b/src/client/bridge/gateway/shard_runner.rs
@@ -258,26 +258,26 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> {
ShardRunnerMessage::Message(msg) => {
self.shard.client.send_message(&msg).is_ok()
},
- ShardRunnerMessage::SetGame(game) => {
- // To avoid a clone of `game`, we do a little bit of
+ ShardRunnerMessage::SetActivity(activity) => {
+ // To avoid a clone of `activity`, we do a little bit of
// trickery here:
//
// First, we obtain a reference to the current presence of
// the shard, and create a new presence tuple of the new
- // game we received over the channel as well as the online
- // status that the shard already had.
+ // activity we received over the channel as well as the
+ // online status that the shard already had.
//
// We then (attempt to) send the websocket message with the
// status update, expressively returning:
//
// - whether the message successfully sent
- // - the original game we received over the channel
- self.shard.set_game(game);
+ // - the original activity we received over the channel
+ self.shard.set_activity(activity);
self.shard.update_presence().is_ok()
},
- ShardRunnerMessage::SetPresence(status, game) => {
- self.shard.set_presence(status, game);
+ ShardRunnerMessage::SetPresence(status, activity) => {
+ self.shard.set_presence(status, activity);
self.shard.update_presence().is_ok()
},
diff --git a/src/client/bridge/gateway/shard_runner_message.rs b/src/client/bridge/gateway/shard_runner_message.rs
index edb9b8a..0fac329 100644
--- a/src/client/bridge/gateway/shard_runner_message.rs
+++ b/src/client/bridge/gateway/shard_runner_message.rs
@@ -1,7 +1,7 @@
use model::{
- gateway::Game,
+ gateway::Activity,
+ id::GuildId,
user::OnlineStatus,
- id::GuildId
};
use websocket::message::OwnedMessage;
@@ -38,11 +38,11 @@ pub enum ShardRunnerMessage {
Close(u16, Option<String>),
/// Indicates that the client is to send a custom WebSocket message.
Message(OwnedMessage),
- /// Indicates that the client is to update the shard's presence's game.
- SetGame(Option<Game>),
+ /// Indicates that the client is to update the shard's presence's activity.
+ SetActivity(Option<Activity>),
/// Indicates that the client is to update the shard's presence in its
- /// entirety.
- SetPresence(OnlineStatus, Option<Game>),
+ /// entirity.
+ SetPresence(OnlineStatus, Option<Activity>),
/// Indicates that the client is to update the shard's presence's status.
SetStatus(OnlineStatus),
}