diff options
| -rw-r--r-- | src/error.rs | 5 | ||||
| -rw-r--r-- | src/model/guild/guild_id.rs | 2 | ||||
| -rw-r--r-- | src/model/guild/member.rs | 9 |
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, ) } |