diff options
| author | acdenisSK <[email protected]> | 2017-07-08 00:43:09 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-08 00:43:09 +0200 |
| commit | 420f9bdaa5a5022ff1d769f1d44a689a6fea12a4 (patch) | |
| tree | 03a2e6002dfd626a8827cc43d24fa49263c107a5 /src/model/guild/guild_id.rs | |
| parent | Actually, use `unreachable!` instead of `panic!` (diff) | |
| download | serenity-420f9bdaa5a5022ff1d769f1d44a689a6fea12a4.tar.xz serenity-420f9bdaa5a5022ff1d769f1d44a689a6fea12a4.zip | |
Implement attaching reasons to bans
Diffstat (limited to 'src/model/guild/guild_id.rs')
| -rw-r--r-- | src/model/guild/guild_id.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 08538b1..68212c7 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -1,5 +1,6 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; use ::model::*; +use ::model::guild::BanOptions; #[cfg(feature="cache")] use ::CACHE; @@ -45,13 +46,30 @@ impl GuildId { /// [`Guild::ban`]: struct.Guild.html#method.ban /// [`User`]: struct.User.html /// [Ban Members]: permissions/constant.BAN_MEMBERS.html - pub fn ban<U: Into<UserId>>(&self, user: U, delete_message_days: u8) + pub fn ban<U: Into<UserId>, BO: Into<BanOptions>>(&self, user: U, ban_options: BO) -> Result<()> { - if delete_message_days > 7 { - return Err(Error::Model(ModelError::DeleteMessageDaysAmount(delete_message_days))); + + use self::BanOptions::*; + + match ban_options.into() { + DeleteMessageDays(dmd) => { + if dmd > 7 { + return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd))); + } + + http::ban_user(self.0, user.into().0, dmd, "") + }, + DMDReason(dmd, reason) => { + if dmd > 7 { + return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd))); + } + + http::ban_user(self.0, user.into().0, dmd, &*reason) + }, + Reason(reason) => { + http::ban_user(self.0, user.into().0, 0, &*reason) + }, } - - http::ban_user(self.0, user.into().0, delete_message_days) } /// Gets a list of the guild's bans. |