diff options
| author | acdenisSK <[email protected]> | 2017-07-10 22:11:07 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-10 22:11:07 +0200 |
| commit | 60c33db56bb3754bb0d2196d5f48fee63adf7730 (patch) | |
| tree | d0a8dda83c9b74891866c95cc57dc65f5416d8ab /src/model/guild | |
| parent | Use a trait way of overloading the `ban` function instead of an enum (diff) | |
| download | serenity-60c33db56bb3754bb0d2196d5f48fee63adf7730.tar.xz serenity-60c33db56bb3754bb0d2196d5f48fee63adf7730.zip | |
Return an error if the reason the user provided exceeded the limit
Diffstat (limited to 'src/model/guild')
| -rw-r--r-- | src/model/guild/guild_id.rs | 8 | ||||
| -rw-r--r-- | src/model/guild/member.rs | 8 |
2 files changed, 14 insertions, 2 deletions
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. |