Commit 168b4357 authored by Samson Ootoovak's avatar Samson Ootoovak

Load environment variables with Rocket.

Rocket provides a nice way to specify environment variables with a toml
file so this takes advantage of that loading system.
parent 2c123406
[global]
slack_api_key=""
......@@ -5,7 +5,7 @@ extern crate rocket;
extern crate slack;
use std::thread;
use std::env;
use rocket::config;
struct Botket;
......@@ -45,18 +45,21 @@ fn root(message: &str) -> String {
}
fn main() {
let rocket = rocket::ignite();
let config = config::active().unwrap();
let api_key = config.get_str("slack_api_key").unwrap();
let mut cli = slack::RtmClient::new(api_key);
let mut botket = Botket;
let rocket_handle = thread::spawn(|| {
println!("===== Starting Rocket Thread =====");
rocket::ignite().mount("/", routes![root]).launch();
rocket.mount("/", routes![root]).launch();
"===== Done Rocket Thread ====="
});
let slack_handle = thread::spawn(|| {
let slack_handle = thread::spawn(move || {
println!("===== Starting Slack Client Thread =====");
let api_key = env::var("SLACK_API_KEY").unwrap();
let mut handler = Botket;
let mut cli = slack::RtmClient::new(&api_key);
let _ = cli.login_and_run::<Botket>(&mut handler);
let _ = cli.login_and_run::<Botket>(&mut botket);
"===== Done Slack Client Thread ====="
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment