aboutsummaryrefslogtreecommitdiff
path: root/src/framework/standard/configuration.rs
diff options
context:
space:
mode:
authorVictor Polevoy <[email protected]>2018-05-24 11:33:26 +0300
committerAlex M. M <[email protected]>2018-05-24 10:33:26 +0200
commit457a17e059395aab3d1a23bd1cfe6e01ea0b5a61 (patch)
treeccb419eaadba872284b16cfd1abe595596f3321b /src/framework/standard/configuration.rs
parentimpl From<{,&'a }CurrentUser> for User (diff)
downloadserenity-457a17e059395aab3d1a23bd1cfe6e01ea0b5a61.tar.xz
serenity-457a17e059395aab3d1a23bd1cfe6e01ea0b5a61.zip
Add an option for a bot to work only in certain channels (#318)
Diffstat (limited to 'src/framework/standard/configuration.rs')
-rw-r--r--src/framework/standard/configuration.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/framework/standard/configuration.rs b/src/framework/standard/configuration.rs
index 2b7584d..01d3b01 100644
--- a/src/framework/standard/configuration.rs
+++ b/src/framework/standard/configuration.rs
@@ -2,7 +2,7 @@ use client::Context;
use http;
use model::{
channel::Message,
- id::{GuildId, UserId}
+ id::{ChannelId, GuildId, UserId}
};
use std::{
collections::HashSet,
@@ -44,6 +44,7 @@ pub struct Configuration {
#[doc(hidden)] pub allow_whitespace: bool,
#[doc(hidden)] pub blocked_guilds: HashSet<GuildId>,
#[doc(hidden)] pub blocked_users: HashSet<UserId>,
+ #[doc(hidden)] pub allowed_channels: HashSet<ChannelId>,
#[doc(hidden)] pub depth: usize,
#[doc(hidden)] pub disabled_commands: HashSet<String>,
#[doc(hidden)] pub dynamic_prefix: Option<Box<PrefixCheck>>,
@@ -118,6 +119,30 @@ impl Configuration {
self
}
+ /// HashSet of channels Ids where commands will be working.
+ ///
+ /// # Examples
+ ///
+ /// Create a HashSet in-place:
+ ///
+ /// ```rust,no_run
+ /// # use serenity::prelude::*;
+ /// # struct Handler;
+ /// #
+ /// # impl EventHandler for Handler {}
+ /// # let mut client = Client::new("token", Handler).unwrap();
+ /// use serenity::model::id::ChannelId;
+ /// use serenity::framework::StandardFramework;
+ ///
+ /// client.with_framework(StandardFramework::new().configure(|c| c
+ /// .allowed_channels(vec![ChannelId(7), ChannelId(77)].into_iter().collect())));
+ /// ```
+ pub fn allowed_channels(mut self, channels: HashSet<ChannelId>) -> Self {
+ self.allowed_channels = channels;
+
+ self
+ }
+
/// HashSet of user Ids whose commands will be ignored.
/// Guilds owned by user Ids will also be ignored.
///
@@ -454,6 +479,7 @@ impl Default for Configuration {
owners: HashSet::default(),
blocked_users: HashSet::default(),
blocked_guilds: HashSet::default(),
+ allowed_channels: HashSet::default(),
disabled_commands: HashSet::default(),
allow_dm: true,
ignore_webhooks: true,