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 discord::model::{Event, PossibleServer};
|
||||||
|
|
||||||
use modules::EventLoop;
|
use modules::EventLoop;
|
||||||
|
|
||||||
|
use toml;
|
||||||
use toml::value::Table;
|
use toml::value::Table;
|
||||||
|
use helpers::config::Config;
|
||||||
|
|
||||||
use event;
|
use event;
|
||||||
|
|
||||||
@ -20,24 +23,30 @@ use {MessageSender, Message, User, Channel};
|
|||||||
|
|
||||||
pub struct DiscordModule {
|
pub struct DiscordModule {
|
||||||
token: String,
|
token: String,
|
||||||
playing: String
|
playing: String,
|
||||||
|
guilds: Vec<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_PLAYING: &'static str = "tenquestionmarks 0.0.3";
|
const DEFAULT_PLAYING: &'static str = "tenquestionmarks 0.0.3";
|
||||||
|
|
||||||
impl DiscordModule {
|
impl DiscordModule {
|
||||||
pub fn new (_: &Table, configuration: &Table) -> Box<EventLoop> {
|
pub fn new (_: &Table, configuration: &Table) -> Box<EventLoop> {
|
||||||
let token = configuration.get("token")
|
let token = configuration.get_string("token").unwrap_or("");
|
||||||
.and_then(|value| value.as_str())
|
let playing = configuration.get_string("playing").unwrap_or(DEFAULT_PLAYING);
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
let playing = configuration.get("playing")
|
let guilds = configuration.get_vec("guilds")
|
||||||
.and_then(|value| value.as_str())
|
.unwrap_or(vec![])
|
||||||
.unwrap_or(DEFAULT_PLAYING);
|
.iter()
|
||||||
|
.map(toml::Value::as_str)
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
|
.map(String::from)
|
||||||
|
.collect();
|
||||||
|
|
||||||
Box::new(DiscordModule {
|
Box::new(DiscordModule {
|
||||||
token: String::from(token),
|
token: String::from(token),
|
||||||
playing: String::from(playing)
|
playing: String::from(playing),
|
||||||
|
guilds: guilds
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user