aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-19 21:55:02 -0800
committerAustin Hellyer <[email protected]>2016-11-19 21:55:02 -0800
commit9581588164f044dceb11e9efae18bac385e7199e (patch)
tree8af3bd51693705335db55af02f5a4fe9af5edb68 /src
parentRename state methods from find_ to get_ (diff)
downloadserenity-9581588164f044dceb11e9efae18bac385e7199e.tar.xz
serenity-9581588164f044dceb11e9efae18bac385e7199e.zip
Rework contextual presence methods
Rework the methods to accept strings and games directly, rather than Optional values. Instead, use the new `reset_presence` to set a clean status, or `set_presence` for more fine-grained control. In addition, `Game::playing` and `Game::streaming` now accept `&str`s rather than Strings.
Diffstat (limited to 'src')
-rw-r--r--src/client/context.rs81
-rw-r--r--src/model/gateway.rs10
2 files changed, 77 insertions, 14 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 53bc9e2..3d9b249 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -1218,34 +1218,97 @@ impl Context {
http::send_message(channel_id.into().0, Value::Object(map))
}
- pub fn set_game(&self, game: Option<Game>) {
+ /// "Resets" the current user's presence, by setting the game to `None`,
+ /// the online status to [`Online`], and `afk` to `false`.
+ ///
+ /// Use [`set_presence`] for fine-grained control over individual details.
+ ///
+ /// [`Online`]: ../model/enum.OnlineStatus.html#variant.Online
+ /// [`set_presence`]: #method.set_presence
+ pub fn reset_presence(&self) {
self.connection.lock()
.unwrap()
- .set_presence(game, OnlineStatus::Online, false);
+ .set_presence(None, OnlineStatus::Online, false)
}
- /// Set the current game, passing in only its name. This will automatically
+ /// Sets the current game, defaulting to an online status of [`Online`], and
+ /// setting `afk` to `false`.
+ ///
+ /// # Examples
+ ///
+ /// Set the current user as playing "Heroes of the Storm":
+ ///
+ /// ```rust,ignore
+ /// use serenity::model::Game;
+ ///
+ /// // assuming you are in a context
+ ///
+ /// context.set_game(Game::playing("Heroes of the Storm"));
+ /// ```
+ ///
+ /// [`Online`]: ../model/enum.OnlineStatus.html#variant.Online
+ pub fn set_game(&self, game: Game) {
+ self.connection.lock()
+ .unwrap()
+ .set_presence(Some(game), OnlineStatus::Online, false);
+ }
+
+ /// Sets the current game, passing in only its name. This will automatically
/// set the current user's [`OnlineStatus`] to [`Online`], and its
/// [`GameType`] as [`Playing`].
///
- /// Pass `None` to remove the current user's current game.
+ /// Use [`reset_presence`] to clear the current game, or [`set_presence`]
+ /// for more fine-grained control.
///
/// [`GameType`]: ../model/enum.GameType.html
/// [`Online`]: ../model/enum.OnlineStatus.html#variant.Online
/// [`OnlineStatus`]: ../model/enum.OnlineStatus.html
/// [`Playing`]: ../model/enum.GameType.html#variant.Playing
- pub fn set_game_name(&self, game: Option<&str>) {
- let game = game.map(|x| Game {
+ /// [`reset_presence`]: #method.reset_presence
+ /// [`set_presence`]: #method.set_presence
+ pub fn set_game_name(&self, game_name: &str) {
+ let game = Game {
kind: GameType::Playing,
- name: x.to_owned(),
+ name: game_name.to_owned(),
url: None,
- });
+ };
self.connection.lock()
.unwrap()
- .set_presence(game, OnlineStatus::Online, false);
+ .set_presence(Some(game), OnlineStatus::Online, false);
}
+ /// Sets the current user's presence, providing all fields to be passed.
+ ///
+ /// # Examples
+ ///
+ /// Setting the current user as having no game, being [`Idle`],
+ /// and setting `afk` to `true`:
+ ///
+ /// ```rust,no_run
+ /// use serenity::model::OnlineStatus;
+ ///
+ /// // assuming you are in a context
+ ///
+ /// context.set_game(None, OnlineStatus::Idle, true);
+ /// ```
+ ///
+ /// Setting the current user as playing "Heroes of the Storm", being
+ /// [`DoNotDisturb`], and setting `afk` to `false`:
+ ///
+ /// ```rust,no_run
+ /// use serenity::model::OnlineStatus;
+ ///
+ /// // assuming you are in a context
+ ///
+ /// let game = Game::playing("Heroes of the Storm");
+ /// let status = OnlineStatus::DoNotDisturb;
+ ///
+ /// context.set_game(Some(game), status, false);
+ /// ```
+ ///
+ /// [`DoNotDisturb`]: ../model/enum.OnlineStatus.html#variant.DoNotDisturb
+ /// [`Idle`]: ../model/enum.OnlineStatus.html#variant.Idle
pub fn set_presence(&self,
game: Option<Game>,
status: OnlineStatus,
diff --git a/src/model/gateway.rs b/src/model/gateway.rs
index 29dd7ce..5fdfdfe 100644
--- a/src/model/gateway.rs
+++ b/src/model/gateway.rs
@@ -762,20 +762,20 @@ impl Event {
impl Game {
#[cfg(feature="methods")]
- pub fn playing(name: String) -> Game {
+ pub fn playing(name: &str) -> Game {
Game {
kind: GameType::Playing,
- name: name,
+ name: name.to_owned(),
url: None,
}
}
#[cfg(feature="methods")]
- pub fn streaming(name: String, url: String) -> Game {
+ pub fn streaming(name: &str, url: &str) -> Game {
Game {
kind: GameType::Streaming,
- name: name,
- url: Some(url),
+ name: name.to_owned(),
+ url: Some(url.to_owned()),
}
}