aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/builder/create_embed.rs6
-rw-r--r--src/client/bridge/gateway/shard_runner.rs7
-rw-r--r--src/gateway/shard.rs61
-rw-r--r--src/model/channel/reaction.rs27
-rw-r--r--src/model/guild/member.rs6
-rw-r--r--src/model/guild/mod.rs8
-rw-r--r--src/model/utils.rs1
7 files changed, 37 insertions, 79 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs
index 7c4d3d6..7a19ba7 100644
--- a/src/builder/create_embed.rs
+++ b/src/builder/create_embed.rs
@@ -235,15 +235,9 @@ impl CreateEmbed {
/// struct Handler;
///
/// impl EventHandler for Handler {
-<<<<<<< HEAD
- /// fn guild_member_addition(&self, _: Context, guild_id: GuildId, member: Member) {
- /// use serenity::client::CACHE;
- /// let cache = CACHE.read();
-=======
/// fn on_guild_member_addition(&self, _: Context, guild_id: GuildId, member: Member) {
/// use serenity::CACHE;
/// let cache = CACHE.read().unwrap();
->>>>>>> v0.4.3
///
/// if let Some(guild) = cache.guild(guild_id) {
/// let guild = guild.read();
diff --git a/src/client/bridge/gateway/shard_runner.rs b/src/client/bridge/gateway/shard_runner.rs
index 0ba83ba..a5fde3d 100644
--- a/src/client/bridge/gateway/shard_runner.rs
+++ b/src/client/bridge/gateway/shard_runner.rs
@@ -422,11 +422,4 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> {
Ok(())
}
-
- fn request_shutdown(&self) -> Result<()> {
- debug!("[ShardRunner {:?}] Requesting shutdown", self.shard_info);
- let _ = self.manager_tx.send(ShardManagerMessage::ShutdownAll);
-
- Ok(())
- }
}
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs
index 340e2e8..08a26a6 100644
--- a/src/gateway/shard.rs
+++ b/src/gateway/shard.rs
@@ -156,12 +156,9 @@ impl Shard {
let user = http::get_current_user()?;
Shard {
-<<<<<<< HEAD
manager: VoiceManager::new(tx, user.id),
manager_rx: rx,
-=======
shutdown: false,
->>>>>>> v0.4.3
client,
current_presence,
heartbeat_instants,
@@ -193,13 +190,11 @@ impl Shard {
})
}
-<<<<<<< HEAD
/// Retrieves the current presence of the shard.
#[inline]
pub fn current_presence(&self) -> &CurrentPresence {
&self.current_presence
}
-=======
/// Whether the shard has permanently shutdown.
///
/// This should normally happen due to manual calling of [`shutdown`] or
@@ -212,31 +207,6 @@ impl Shard {
self.shutdown
}
- /// Retrieves a copy of the current shard information.
- ///
- /// The first element is the _current_ shard - 0-indexed - while the second
- /// element is the _total number_ of shards -- 1-indexed.
- ///
- /// For example, if using 3 shards in total, and if this is shard 1, then it
- /// can be read as "the second of three shards".
- ///
- /// # Examples
- ///
- /// Retrieving the shard info for the second shard, out of two shards total:
- ///
- /// ```rust,no_run
- /// # use serenity::client::gateway::Shard;
- /// # use std::sync::{Arc, Mutex};
- /// #
- /// # let mutex = Arc::new(Mutex::new("".to_string()));
- /// #
- /// # let shard = Shard::new(mutex.clone(), mutex, [1, 2]).unwrap();
- /// #
- /// assert_eq!(shard.shard_info(), [1, 2]);
- /// ```
- pub fn shard_info(&self) -> [u64; 2] { self.shard_info }
->>>>>>> v0.4.3
-
/// Retrieves the heartbeat instants of the shard.
///
/// This is the time of when a heartbeat was sent and when an
@@ -265,7 +235,6 @@ impl Shard {
///
/// # Errors
///
-<<<<<<< HEAD
/// Returns [`GatewayError::HeartbeatFailed`] if there was an error sending
/// a heartbeat.
///
@@ -317,8 +286,6 @@ impl Shard {
self.session_id.as_ref()
}
- #[inline]
-=======
/// ```rust,no_run
/// # #[cfg(feature = "model")]
/// # fn main() {
@@ -337,7 +304,7 @@ impl Shard {
/// # #[cfg(not(feature = "model"))]
/// # fn main() { }
/// ```
->>>>>>> v0.4.3
+ #[inline]
pub fn set_game(&mut self, game: Option<Game>) {
self.current_presence.0 = game;
}
@@ -370,15 +337,12 @@ impl Shard {
/// Retrieving the shard info for the second shard, out of two shards total:
///
/// ```rust,no_run
-<<<<<<< HEAD
/// # extern crate parking_lot;
/// # extern crate serenity;
/// #
/// # use parking_lot::Mutex;
-=======
/// # #[cfg(feature = "model")]
/// # fn main() {
->>>>>>> v0.4.3
/// # use serenity::client::gateway::Shard;
/// # use std::error::Error;
/// # use std::sync::Arc;
@@ -388,7 +352,6 @@ impl Shard {
/// #
/// # let shard = Shard::new(mutex.clone(), mutex, [1, 2]).unwrap();
/// #
-<<<<<<< HEAD
/// assert_eq!(shard.shard_info(), [1, 2]);
/// # Ok(())
/// # }
@@ -396,15 +359,6 @@ impl Shard {
/// # fn main() {
/// # try_main().unwrap();
/// # }
-=======
- /// use serenity::model::{Game, OnlineStatus};
- ///
- /// shard.set_presence(Some(Game::playing("Heroes of the Storm")), OnlineStatus::Online, false);
- /// # }
- /// #
- /// # #[cfg(not(feature = "model"))]
- /// # fn main() { }
->>>>>>> v0.4.3
/// ```
pub fn shard_info(&self) -> [u64; 2] { self.shard_info }
@@ -695,8 +649,6 @@ impl Shard {
}
/// Calculates the heartbeat latency between the shard and the gateway.
-<<<<<<< HEAD
-=======
///
/// # Examples
///
@@ -732,7 +684,6 @@ impl Shard {
///
/// [`Client`]: ../struct.Client.html
/// [`EventHandler::on_message`]: ../event_handler/trait.EventHandler.html#method.on_message
->>>>>>> v0.4.3
// Shamelessly stolen from brayzure's commit in eris:
// <https://github.com/abalabahaha/eris/commit/0ce296ae9a542bcec0edf1c999ee2d9986bed5a6>
pub fn latency(&self) -> Option<StdDuration> {
@@ -766,14 +717,11 @@ impl Shard {
pub(crate) fn cycle_voice_recv(&mut self) -> Vec<Value> {
let mut messages = vec![];
-<<<<<<< HEAD
while let Ok(v) = self.manager_rx.try_recv() {
messages.push(v);
}
-=======
self.shutdown = true;
debug!("[Shard {:?}] Cleanly shutdown shard", self.shard_info);
->>>>>>> v0.4.3
messages
}
@@ -801,21 +749,18 @@ impl Shard {
self.shard_info,
);
- self.resume()
+ self.resume()?;
} else {
debug!(
"[Shard {:?}] Autoreconnector choosing to reconnect",
self.shard_info,
);
-<<<<<<< HEAD
- self.reconnect()
+ self.reconnect()?;
}
-=======
self.shutdown = true;
Ok(())
->>>>>>> v0.4.3
}
/// Requests that one or multiple [`Guild`]s be chunked.
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs
index 1a40ecb..2003c28 100644
--- a/src/model/channel/reaction.rs
+++ b/src/model/channel/reaction.rs
@@ -1,5 +1,7 @@
use serde::de::{Deserialize, Error as DeError, MapAccess, Visitor};
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
+use std::str::FromStr;
+use std::error::Error as StdError;
use internal::prelude::*;
use model::*;
@@ -277,6 +279,31 @@ impl<'a> From<&'a str> for ReactionType {
fn from(unicode: &str) -> ReactionType { ReactionType::Unicode(unicode.to_string()) }
}
+// TODO: Change this to `!` once it becomes stable.
+
+#[derive(Debug)]
+pub struct NeverFails;
+
+impl Display for NeverFails {
+ fn fmt(&self, f: &mut Formatter) -> FmtResult {
+ write!(f, "never fails")
+ }
+}
+
+impl StdError for NeverFails {
+ fn description(&self) -> &str {
+ "never fails"
+ }
+}
+
+impl FromStr for ReactionType {
+ type Err = NeverFails;
+
+ fn from_str(s: &str) -> ::std::result::Result<Self, Self::Err> {
+ Ok(ReactionType::from(s))
+ }
+}
+
impl Display for ReactionType {
/// Formats the reaction type, displaying the associated emoji in a
/// way that clients can understand.
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index e5feee7..2c31bc3 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -188,7 +188,7 @@ impl Member {
let reader = guild.read();
for (cid, channel) in &reader.channels {
- if reader.permissions_for(*cid, self.user.read().id).read_messages() {
+ if reader.permissions_in(*cid, self.user.read().id).read_messages() {
return Some(channel.clone());
}
}
@@ -311,9 +311,9 @@ impl Member {
None => return Err(From::from(ModelError::GuildNotFound)),
};
- let reader = guild.read().unwrap();
+ let reader = guild.read();
- Ok(reader.member_permissions(self.user.read().unwrap().id))
+ Ok(reader.member_permissions(self.user.read().id))
}
/// Removes a [`Role`] from the member, editing its roles in-place if the
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index ab74109..1e0ef7c 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -136,7 +136,7 @@ impl Guild {
pub fn default_channel(&self, uid: UserId) -> Option<Arc<RwLock<GuildChannel>>> {
for (cid, channel) in &self.channels {
if self.permissions_in(*cid, uid).read_messages() {
- return Some(channel.read().unwrap().clone());
+ return Some(Arc::clone(&channel));
}
}
@@ -152,7 +152,7 @@ impl Guild {
for (cid, channel) in &self.channels {
for memid in self.members.keys() {
if self.permissions_in(*cid, *memid).read_messages() {
- return Some(channel.read().unwrap().clone());
+ return Some(Arc::clone(&channel));
}
}
}
@@ -162,7 +162,7 @@ impl Guild {
#[cfg(feature = "cache")]
fn has_perms(&self, mut permissions: Permissions) -> bool {
- let user_id = CACHE.read().unwrap().user.id;
+ let user_id = CACHE.read().user.id;
let perms = self.member_permissions(user_id);
permissions.remove(perms);
@@ -1040,7 +1040,7 @@ impl Guild {
} else {
warn!(
"(╯°□°)╯︵ ┻━┻ {} on {} has non-existent role {:?}",
- member.user.read().unwrap().id,
+ member.user.read().id,
self.id,
role,
);
diff --git a/src/model/utils.rs b/src/model/utils.rs
index d366e5f..fd103c0 100644
--- a/src/model/utils.rs
+++ b/src/model/utils.rs
@@ -180,7 +180,6 @@ pub fn user_has_perms(channel_id: ChannelId, mut permissions: Permissions) -> Re
let perms = guild
.read()
- .unwrap()
.permissions_in(channel_id, current_user.id);
permissions.remove(perms);