aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-11-04 23:12:17 +0100
committeracdenisSK <[email protected]>2017-11-04 23:12:17 +0100
commit2032a402c387b1310f2ae62621f3e07c86b76aef (patch)
treee34c35de1eb517d9b2469f02cd179ab9e6b34544 /src/model
parentMerge v0.4.3 (diff)
downloadserenity-2032a402c387b1310f2ae62621f3e07c86b76aef.tar.xz
serenity-2032a402c387b1310f2ae62621f3e07c86b76aef.zip
Whoops. Add a `FromStr` impl for `ReactionType`
Diffstat (limited to 'src/model')
-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
4 files changed, 34 insertions, 8 deletions
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);