Skip to content

Instantly share code, notes, and snippets.

@habnabit
Created June 24, 2016 23:51
Show Gist options
  • Save habnabit/56da136cbfb7d6da40b0819d1d27e68e to your computer and use it in GitHub Desktop.
Save habnabit/56da136cbfb7d6da40b0819d1d27e68e to your computer and use it in GitHub Desktop.
match event {
// Sample structure.
// Ok(Message(Standard { ts: "1465616511.000007", channel: Some("G0RFEFRF1"),
// user: Some("U04R67MSW"), text: Some("#sloakme"), is_starred: None,
// pinned_to: None, reactions: None, edited: None, attachments: None }))
Ok(&slack::Event::Message(slack::Message::Standard {
channel: Some(ref channel),
user: Some(ref user),
text: Some(ref text),
..
})) if text.contains("#pokeme") => {
let pokemon = thread_rng().choose(&self.pokedex).unwrap();
let attachment_json = json::encode(&vec![attachment_for_pokemon(pokemon)]).unwrap();
let _ = cli.post_message(
channel,
&format!("You are a {}!", &pokemon.species),
Some(&attachment_json));
},
Ok(_) => (),
Err(err) => println!("Error on event: {}", err),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment