From 82637a67c8d3dc11b7f6297f85fa69816c373a2c Mon Sep 17 00:00:00 2001 From: Romain Gautier Date: Mon, 27 Mar 2017 14:24:40 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 ++ Cargo.toml | 7 +++++++ src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..324c57f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +**/*.rs.bk diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..15dee32 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "rom-discord-bot" +version = "0.1.0" +authors = ["Romain Gautier "] + +[dependencies] +discord = "^0.8.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d625cee --- /dev/null +++ b/src/main.rs @@ -0,0 +1,42 @@ +//client id: 295890698417340417 +//client secret: eeX4u7GhSXAvt4CquizWb_--5sY41oQP + +//https://discordapp.com/oauth2/authorize?&client_id=295890698417340417&scope=bot&permissions=0 + +extern crate discord; + +use discord::Discord; +use discord::model::Event; + +fn main() { + + let token_bot = "Mjk1ODkwNjk4NDE3MzQwNDE3.C7qTWA.uNinGhRhSMj3sun83Ke_uIF4kjw"; + + let discord = Discord::from_bot_token(&token_bot).expect("Unable to make bot from token."); + + + let (mut connection, _) = discord.connect().expect("Unable to connect."); + + println!("Ready."); + + + loop { + + match connection.recv_event() { + Ok(Event::MessageCreate(message)) => { + println!("{} says: {}", message.author.name, message.content); + + if message.content == "!quit" { + println!("Quitting"); + break + } + } + Ok(_) => { } + Err(discord::Error::Closed(code, body)) => { + println!("Gateway closed on us with code {:?}: {}", code, body); + break + } + Err(err) => println!("Received error: {:?}", err) + } + } +}