From 1a69349557200cd8723f3bd635a5f67e58e40d60 Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Fri, 17 Feb 2017 02:44:00 -0600 Subject: [PATCH] Add ability to specify the "playing" status string (with tenquestionmarks default) --- src/modules/discord.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/discord.rs b/src/modules/discord.rs index 235bd39..f9a01ab 100644 --- a/src/modules/discord.rs +++ b/src/modules/discord.rs @@ -15,17 +15,25 @@ use User; use Channel; pub struct DiscordModule { - token: String + token: String, + playing: String } +const DEFAULT_PLAYING: &'static str = "tenquestionmarks 0.0.1"; + impl DiscordModule { pub fn new (configuration: &Table) -> Box { let token = configuration.get("token") .and_then(|value| value.as_str()) .unwrap_or(""); + let playing = configuration.get("playing") + .and_then(|value| value.as_str()) + .unwrap_or(DEFAULT_PLAYING); + 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) { 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"); + + info!("Playing {}", self.playing); + connection.set_game_name(self.playing.clone()); + loop { match connection.recv_event() { Ok(Event::MessageCreate(message)) => {