commit 402778e6c7421fc7f68bc91f2e10b995849f7485
parent f7fa6f6daa40c1bfa7fc44fcd077f7e306474368
Author: Marcel <mtrnord1@gmail.com>
Date: Mon, 6 Feb 2017 14:25:59 +0100
add some basic code
Diffstat:
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -34,10 +34,11 @@ license = "GPL-3.0"
# specified using the following parameters:
[badges]
# Travis CI: `repository` is required. `branch` is optional; default is `master`
-#travis-ci = { repository = "...", branch = "master" }
+travis-ci = { repository = "https://github.com/Nordgdanken/TG_sync-rs", branch = "master" }
[dependencies]
telebot = "0.1.1"
+slack = "0.16.0"
futures = "0.1.7"
tokio-core = "0.1.2"
diff --git a/src/main.rs b/src/main.rs
@@ -1,4 +1,5 @@
extern crate telebot;
+extern crate slack;
extern crate tokio_core;
extern crate futures;
@@ -9,7 +10,59 @@ use futures::stream::Stream;
// import all available functions
use telebot::functions::*;
+struct MyHandler;
+
+#[allow(unused_variables)]
+impl slack::EventHandler for MyHandler {
+ 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");
+ // Do a few things using the api:
+ // send a message over the real time api websocket
+ let _ = cli.send_message("#testing_syncotronic", "Hello world! (rtm)");
+ // post a message as a user to the web api
+ let _ = cli.post_message("#testing_syncotronic", "hello world! (postMessage)", None);
+ // set a channel topic via the web api
+ // let _ = cli.set_topic("#general", "bots rule!");
+ }
+}
+
fn main() {
+ slack();
+ tg();
+}
+
+fn slack() {
+ let args: Vec<String> = std::env::args().collect();
+ let api_key = match args.len() {
+ 0 | 1 => panic!("No api-key in args! Usage: cargo run --example slack_example -- <api-key>"),
+ x => {
+ args[x - 1].clone()
+ }
+ };
+ let mut handler = MyHandler;
+ let mut cli = slack::RtmClient::new(&api_key);
+ let r = cli.login_and_run::<MyHandler>(&mut handler);
+ match r {
+ Ok(_) => {}
+ Err(err) => panic!("Error: {}", err),
+ }
+ println!("{}", cli.get_name().unwrap());
+ println!("{}", cli.get_team().unwrap().name);
+}
+
+fn tg() {
let mut lp = Core::new().unwrap();
let bot = bot::RcBot::new(lp.handle(), "315066220:AAFGOUmSvq0T725a6Ke4C-zmfx80m_PcsxM")
.update_interval(200);