use client::Context;
use http;
use model::{
channel::Message,
id::{ChannelId, GuildId, UserId}
};
use std::{
collections::HashSet,
default::Default
};
use super::command::PrefixCheck;
pub struct Configuration {
#[doc(hidden)] pub allow_dm: bool,
#[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>>,
#[doc(hidden)] pub ignore_bots: bool,
#[doc(hidden)] pub ignore_webhooks: bool,
#[doc(hidden)] pub on_mention: Option<Vec<String>>,
#[doc(hidden)] pub owners: HashSet<UserId>,
#[doc(hidden)] pub prefixes: Vec<String>,
#[doc(hidden)] pub no_dm_prefix: bool,
#[doc(hidden)] pub delimiters: Vec<String>,
#[doc(hidden)] pub case_insensitive: bool,
}
impl Configuration {
pub fn allow_dm(mut self, allow_dm: bool) -> Self {
self.allow_dm = allow_dm;
self
}
pub fn allow_whitespace(mut self, allow_whitespace: bool) -> Self {
self.allow_whitespace = allow_whitespace;
self
}
pub fn allowed_channels(mut self, channels: HashSet<ChannelId>) -> Self {
self.allowed_channels = channels;
self
}
pub fn blocked_guilds(mut self, guilds: HashSet<GuildId>) -> Self {
self.blocked_guilds = guilds;
self
}
pub fn blocked_users(mut self, users: HashSet<UserId>) -> Self {
self.blocked_users = users;
self
}
pub fn depth(mut self, depth: u8) -> Self {
self.depth = depth as usize;
self
}
pub fn disabled_commands(mut self, commands: HashSet<String>) -> Self {
self.disabled_commands = commands;
self
}
pub fn dynamic_prefix<F>(mut self, dynamic_prefix: F) -> Self
where F: Fn(&mut Context, &Message) -> Option<String> + Send + Sync + 'static {
self.dynamic_prefix = Some(Box::new(dynamic_prefix));
self
}
pub fn ignore_bots(mut self, ignore_bots: bool) -> Self {
self.ignore_bots = ignore_bots;
self
}
pub fn ignore_webhooks(mut self, ignore_webhooks: bool) -> Self {
self.ignore_webhooks = ignore_webhooks;
self
}
pub fn on_mention(mut self, on_mention: bool) -> Self {
if !on_mention {
return self;
}
if let Ok(current_user) = http::get_current_user() {
self.on_mention = Some(vec![
format!("<@{}>", current_user.id), format!("<@!{}>", current_user.id), ]);
}
self
}
pub fn owners(mut self, user_ids: HashSet<UserId>) -> Self {
self.owners = user_ids;
self
}
pub fn prefix(mut self, prefix: &str) -> Self {
self.prefixes = vec![prefix.to_string()];
self
}
pub fn prefixes<T: ToString, It: IntoIterator<Item=T>>(mut self, prefixes: It) -> Self {
self.prefixes = prefixes.into_iter().map(|x| x.to_string()).collect();
self
}
pub fn no_dm_prefix(mut self, b: bool) -> Self {
self.no_dm_prefix = b;
self
}
pub fn delimiter(mut self, delimiter: &str) -> Self {
self.delimiters.push(delimiter.to_string());
self
}
pub fn delimiters<T: ToString, It: IntoIterator<Item=T>>(mut self, delimiters: It) -> Self {
self.delimiters.clear();
self.delimiters
.extend(delimiters.into_iter().map(|s| s.to_string()));
self
}
pub fn case_insensitivity(mut self, cs: bool) -> Self {
self.case_insensitive = cs;
self
}
}
impl Default for Configuration {
fn default() -> Configuration {
Configuration {
allow_dm: true,
allow_whitespace: false,
allowed_channels: HashSet::default(),
blocked_guilds: HashSet::default(),
blocked_users: HashSet::default(),
case_insensitive: false,
delimiters: vec![" ".to_string()],
depth: 5,
disabled_commands: HashSet::default(),
dynamic_prefix: None,
ignore_bots: true,
ignore_webhooks: true,
no_dm_prefix: false,
on_mention: None,
owners: HashSet::default(),
prefixes: vec![],
}
}
}