aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs5
-rw-r--r--src/model/guild/guild_id.rs8
-rw-r--r--src/model/guild/member.rs8
3 files changed, 19 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs
index a9484d5..390d295 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -61,6 +61,10 @@ pub enum Error {
Model(ModelError),
/// An error occurred while parsing an integer.
Num(ParseIntError),
+ /// Input exceeded a limit.
+ ///
+ /// *This only exists for the `GuildId::ban` and `Member::ban` functions. For their cases, it's the "reason".*
+ ExceededLimit,
/// 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.
@@ -186,6 +190,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::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 c2cfc3d..c707413 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -53,7 +53,13 @@ impl GuildId {
return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd)));
}
- http::ban_user(self.0, user.into().0, dmd, &*ban_options.reason())
+ let reason = ban_options.reason();
+
+ if reason.len() > 512 {
+ return Err(Error::ExceededLimit);
+ }
+
+ http::ban_user(self.0, user.into().0, dmd, &*reason)
}
/// Gets a list of the guild's bans.
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index b128887..053360d 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -146,7 +146,13 @@ impl Member {
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
#[cfg(feature="cache")]
pub fn ban<BO: BanOptions>(&self, ban_options: BO) -> Result<()> {
- http::ban_user(self.guild_id.0, self.user.read().unwrap().id.0, ban_options.dmd(), &*ban_options.reason())
+ let reason = ban_options.reason();
+
+ if reason.len() > 512 {
+ return Err(Error::ExceededLimit);
+ }
+
+ http::ban_user(self.guild_id.0, self.user.read().unwrap().id.0, ban_options.dmd(), &*reason)
}
/// Determines the member's colour.