finally a working implementation of Discord sender

This commit is contained in:
Adrian Malacoda 2017-02-16 00:27:53 -06:00
parent 7581521b61
commit bdee07143b
2 changed files with 6 additions and 3 deletions

View File

@ -31,18 +31,19 @@ impl DiscordPlugin {
}
pub struct DiscordMessageSender {
discord: Arc<Discord>,
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<event::Event>) {
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
})
};

View File

@ -9,7 +9,7 @@ type = "hello"
name = "Fred"
[discord]
channel = "#testchannelpleaseignore"
token = "MjgwNTYxNjUyOTM4ODMzOTIw.C4QQmw.0VO9PBBolmMyr4rreAL6VSkUut8"
[stdin]