aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-08-01 06:53:46 +0200
committeracdenisSK <[email protected]>2017-08-01 06:53:46 +0200
commit25d49316133e2a8b7c4b26d3b6a44efdf5ad8834 (patch)
tree1a313f96374118bed3da5aeea5744106b9509c88 /src
parentRemove the `ext` module and remove a match (diff)
downloadserenity-25d49316133e2a8b7c4b26d3b6a44efdf5ad8834.tar.xz
serenity-25d49316133e2a8b7c4b26d3b6a44efdf5ad8834.zip
Provide the input and limit back to the user, and do some consistencies
Diffstat (limited to 'src')
-rw-r--r--src/error.rs5
-rw-r--r--src/model/guild/guild_id.rs2
-rw-r--r--src/model/guild/member.rs9
3 files changed, 11 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs
index 185f907..508578b 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -62,10 +62,11 @@ pub enum Error {
/// An error occurred while parsing an integer.
Num(ParseIntError),
/// Input exceeded a limit.
+ /// Providing the input and the limit that's not supposed to be exceeded.
///
/// *This only exists for the `GuildId::ban` and `Member::ban` functions. For their cases,
/// it's the "reason".*
- ExceededLimit,
+ ExceededLimit(String, u32),
/// Some other error. This is only used for "Expected value <TYPE>" errors,
/// when a more detailed error can not be easily provided via the
/// [`Error::Decode`] variant.
@@ -171,7 +172,7 @@ impl StdError for Error {
fn description(&self) -> &str {
match *self {
Error::Decode(msg, _) | Error::Other(msg) => msg,
- Error::ExceededLimit => "Input exceeded a limit",
+ Error::ExceededLimit(..) => "Input exceeded a limit",
Error::Format(ref inner) => inner.description(),
Error::Io(ref inner) => inner.description(),
Error::Json(ref inner) => inner.description(),
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs
index 08fd1a1..a199331 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -54,7 +54,7 @@ impl GuildId {
let reason = ban_options.reason();
if reason.len() > 512 {
- return Err(Error::ExceededLimit);
+ return Err(Error::ExceededLimit(reason.to_string(), 512));
}
http::ban_user(self.0, user.into().0, dmd, &*reason)
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index 70590b0..756477b 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -132,16 +132,21 @@ impl Member {
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
#[cfg(feature = "cache")]
pub fn ban<BO: BanOptions>(&self, ban_options: BO) -> Result<()> {
+ let dmd = ban_options.dmd();
+ if dmd > 7 {
+ return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd)));
+ }
+
let reason = ban_options.reason();
if reason.len() > 512 {
- return Err(Error::ExceededLimit);
+ return Err(Error::ExceededLimit(reason.to_string(), 512));
}
http::ban_user(
self.guild_id.0,
self.user.read().unwrap().id.0,
- ban_options.dmd(),
+ dmd,
&*reason,
)
}