Add ability to specify the "playing" status string (with tenquestionmarks default)

This commit is contained in:
Adrian Malacoda 2017-02-17 02:44:00 -06:00
parent 5fc231eec6
commit 1a69349557

View File

@ -15,17 +15,25 @@ use User;
use Channel; use Channel;
pub struct DiscordModule { pub struct DiscordModule {
token: String token: String,
playing: String
} }
const DEFAULT_PLAYING: &'static str = "tenquestionmarks 0.0.1";
impl DiscordModule { impl DiscordModule {
pub fn new (configuration: &Table) -> Box<Module> { pub fn new (configuration: &Table) -> Box<Module> {
let token = configuration.get("token") let token = configuration.get("token")
.and_then(|value| value.as_str()) .and_then(|value| value.as_str())
.unwrap_or(""); .unwrap_or("");
let playing = configuration.get("playing")
.and_then(|value| value.as_str())
.unwrap_or(DEFAULT_PLAYING);
Box::new(DiscordModule { Box::new(DiscordModule {
token: String::from(token) token: String::from(token),
playing: String::from(playing)
}) })
} }
} }
@ -49,6 +57,10 @@ impl Module for DiscordModule {
fn produce_events<'a>(&'a self, sender: Sender<event::Event>) { fn produce_events<'a>(&'a self, sender: Sender<event::Event>) {
let discord = Arc::new(Discord::from_bot_token(&self.token[..]).expect("Discord module: Login failed")); let discord = Arc::new(Discord::from_bot_token(&self.token[..]).expect("Discord module: Login failed"));
let (mut connection, _) = discord.connect().expect("Discord module: Connection failed"); let (mut connection, _) = discord.connect().expect("Discord module: Connection failed");
info!("Playing {}", self.playing);
connection.set_game_name(self.playing.clone());
loop { loop {
match connection.recv_event() { match connection.recv_event() {
Ok(Event::MessageCreate(message)) => { Ok(Event::MessageCreate(message)) => {