add ability to specify a list of guilds for discord module. Intent is to be able to filter events to specific guilds.
This commit is contained in:
parent
0d4718c3f3
commit
a698450c1e
@ -3,7 +3,10 @@ use discord::Discord;
|
||||
use discord::model::{Event, PossibleServer};
|
||||
|
||||
use modules::EventLoop;
|
||||
|
||||
use toml;
|
||||
use toml::value::Table;
|
||||
use helpers::config::Config;
|
||||
|
||||
use event;
|
||||
|
||||
@ -20,24 +23,30 @@ use {MessageSender, Message, User, Channel};
|
||||
|
||||
pub struct DiscordModule {
|
||||
token: String,
|
||||
playing: String
|
||||
playing: String,
|
||||
guilds: Vec<String>
|
||||
}
|
||||
|
||||
const DEFAULT_PLAYING: &'static str = "tenquestionmarks 0.0.3";
|
||||
|
||||
impl DiscordModule {
|
||||
pub fn new (_: &Table, configuration: &Table) -> Box<EventLoop> {
|
||||
let token = configuration.get("token")
|
||||
.and_then(|value| value.as_str())
|
||||
.unwrap_or("");
|
||||
let token = configuration.get_string("token").unwrap_or("");
|
||||
let playing = configuration.get_string("playing").unwrap_or(DEFAULT_PLAYING);
|
||||
|
||||
let playing = configuration.get("playing")
|
||||
.and_then(|value| value.as_str())
|
||||
.unwrap_or(DEFAULT_PLAYING);
|
||||
let guilds = configuration.get_vec("guilds")
|
||||
.unwrap_or(vec![])
|
||||
.iter()
|
||||
.map(toml::Value::as_str)
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.map(String::from)
|
||||
.collect();
|
||||
|
||||
Box::new(DiscordModule {
|
||||
token: String::from(token),
|
||||
playing: String::from(playing)
|
||||
playing: String::from(playing),
|
||||
guilds: guilds
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user