aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-08-01 08:35:04 -0700
committerZeyla Hellyer <[email protected]>2018-08-01 08:35:04 -0700
commite1332a54af46eff6051097ff4989c8d0fde4ca37 (patch)
tree9f2a8753e994e1b533ca20da67ce5325a79fdfd1 /src/client
parentMove unit tests into source (diff)
downloadserenity-e1332a54af46eff6051097ff4989c8d0fde4ca37.tar.xz
serenity-e1332a54af46eff6051097ff4989c8d0fde4ca37.zip
Add From impls for Game, generify Game params
Add more `impl From<T> for Game` implementations, and make `Into<Game>` trait bounds for all function parameters accepting a Game.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/bridge/gateway/shard_messenger.rs16
-rw-r--r--src/client/context.rs20
2 files changed, 24 insertions, 12 deletions
diff --git a/src/client/bridge/gateway/shard_messenger.rs b/src/client/bridge/gateway/shard_messenger.rs
index 2331d4a..6d625b6 100644
--- a/src/client/bridge/gateway/shard_messenger.rs
+++ b/src/client/bridge/gateway/shard_messenger.rs
@@ -157,7 +157,11 @@ impl ShardMessenger {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn set_game(&self, game: Option<Game>) {
+ 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));
}
@@ -195,7 +199,15 @@ impl ShardMessenger {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn set_presence(&self, game: Option<Game>, mut status: OnlineStatus) {
+ 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) {
if status == OnlineStatus::Offline {
status = OnlineStatus::Invisible;
}
diff --git a/src/client/context.rs b/src/client/context.rs
index c72818c..61a1925 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -274,7 +274,7 @@ impl Context {
/// [`set_presence`]: #method.set_presence
#[inline]
pub fn reset_presence(&self) {
- self.shard.set_presence(None, OnlineStatus::Online);
+ self.shard.set_presence(None::<Game>, OnlineStatus::Online);
}
/// Sets the current game, defaulting to an online status of [`Online`].
@@ -317,7 +317,11 @@ impl Context {
///
/// [`Online`]: ../model/user/enum.OnlineStatus.html#variant.Online
#[inline]
- pub fn set_game(&self, game: Game) {
+ pub fn set_game<T: Into<Game>>(&self, game: T) {
+ self._set_game(game.into())
+ }
+
+ fn _set_game(&self, game: Game) {
self.shard.set_presence(Some(game), OnlineStatus::Online);
}
@@ -357,14 +361,10 @@ impl Context {
/// [`Playing`]: ../model/gateway/enum.GameType.html#variant.Playing
/// [`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: game_name.to_string(),
- url: None,
- };
-
- self.shard.set_presence(Some(game), OnlineStatus::Online);
+ #[deprecated(since = "0.5.5", note = "Use Context::set_game")]
+ #[inline]
+ pub fn set_game_name<T: Into<String>>(&self, game_name: T) {
+ self.set_game(game_name.into())
}
/// Sets the current user's presence, providing all fields to be passed.