use std::collections::HashSet;
use std::default::Default;
use super::command::PrefixCheck;
use ::client::Context;
use ::http;
use ::model::{GuildId, Message, UserId};
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 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>,
}
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 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_owned()];
self
}
pub fn prefixes(mut self, prefixes: Vec<&str>) -> Self {
self.prefixes = prefixes.iter().map(|x| x.to_string()).collect();
self
}
}
impl Default for Configuration {
fn default() -> Configuration {
Configuration {
depth: 5,
on_mention: None,
dynamic_prefix: None,
allow_whitespace: false,
prefixes: vec![],
ignore_bots: true,
owners: HashSet::default(),
blocked_users: HashSet::default(),
blocked_guilds: HashSet::default(),
disabled_commands: HashSet::default(),
allow_dm: true,
ignore_webhooks: true,
}
}
}