From bdee07143b7f5d0a731b3ef4290ab9c38510d1dc Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Thu, 16 Feb 2017 00:27:53 -0600 Subject: [PATCH] finally a working implementation of Discord sender --- src/plugins/discord.rs | 7 +++++-- tenquestionmarks.toml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/discord.rs b/src/plugins/discord.rs index 69445e3..d859de9 100644 --- a/src/plugins/discord.rs +++ b/src/plugins/discord.rs @@ -31,18 +31,19 @@ impl DiscordPlugin { } pub struct DiscordMessageSender { + discord: Arc, channel_id: discord::model::ChannelId } impl MessageSender for DiscordMessageSender { fn send_message (&self, message: &str) { - println!("send to {:?}: {:?}", self.channel_id, message); + self.discord.send_message(&self.channel_id, message, "", false); } } impl Plugin for DiscordPlugin { fn produce_events<'a>(&'a self, sender: Sender) { - let discord = Discord::from_bot_token(&self.token[..]).expect("Login failed"); + let discord = Arc::new(Discord::from_bot_token(&self.token[..]).expect("Login failed")); let (mut connection, _) = discord.connect().expect("Connection failed"); loop { match connection.recv_event() { @@ -50,6 +51,7 @@ impl Plugin for DiscordPlugin { let author = User { name: message.author.name.clone(), sender: Arc::new(DiscordMessageSender { + discord: discord.clone(), channel_id: message.channel_id }) }; @@ -59,6 +61,7 @@ impl Plugin for DiscordPlugin { description: String::from(""), topic: String::from(""), sender: Arc::new(DiscordMessageSender { + discord: discord.clone(), channel_id: message.channel_id }) }; diff --git a/tenquestionmarks.toml b/tenquestionmarks.toml index 42d0621..db8b592 100644 --- a/tenquestionmarks.toml +++ b/tenquestionmarks.toml @@ -9,7 +9,7 @@ type = "hello" name = "Fred" [discord] -channel = "#testchannelpleaseignore" +token = "MjgwNTYxNjUyOTM4ODMzOTIw.C4QQmw.0VO9PBBolmMyr4rreAL6VSkUut8" [stdin]