Add ability to specify the "playing" status string (with tenquestionmarks default)
This commit is contained in:
parent
5fc231eec6
commit
1a69349557
@ -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<Module> {
|
||||
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<event::Event>) {
|
||||
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)) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user