Commit 093bfd09 authored by ootoovak's avatar ootoovak

The first commit for Botket.

The first commit is glued together example code. It regesters messages
but it currently does not do anything with them.
parents
This diff is collapsed.
[package]
name = "botket"
version = "0.1.0"
authors = ["ootoovak <ootoovak@gmail.com>"]
[dependencies]
rocket = "0.2.3"
rocket_codegen = "0.2.3"
slack = "0.16.0"
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
extern crate slack;
use std::env;
struct Botket;
#[allow(unused_variables)]
impl slack::EventHandler for Botket {
fn on_event(&mut self,
cli: &mut slack::RtmClient,
event: Result<slack::Event, slack::Error>,
raw_json: &str) {
println!("on_event(event: {:?}, raw_json: {:?})", event, raw_json);
}
fn on_ping(&mut self, cli: &mut slack::RtmClient) {
println!("on_ping");
}
fn on_close(&mut self, cli: &mut slack::RtmClient) {
println!("on_close");
}
fn on_connect(&mut self, cli: &mut slack::RtmClient) {
println!("on_connect");
let _ = cli.send_message("#general", "Hello world! (rtm)");
let _ = cli.post_message("#general", "hello world! (postMessage)", None);
}
}
#[get("/<message>")]
fn root(message: &str) -> String {
format!("You asked Botket to say: {}", message)
}
fn main() {
let api_key = env::var("SLACK_API_KEY").unwrap();
let mut handler = Botket;
let mut cli = slack::RtmClient::new(&api_key);
let result = cli.login_and_run::<Botket>(&mut handler);
match result {
Ok(_) => {}
Err(err) => panic!("Error: {}", err),
}
println!("{}", cli.get_name().unwrap());
println!("{}", cli.get_team().unwrap().name);
rocket::ignite().mount("/", routes![root]).launch();
}
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