aboutsummaryrefslogtreecommitdiff
path: root/examples/07_sample_bot_structure/src/main.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-10-29 09:53:10 -0700
committerZeyla Hellyer <[email protected]>2017-10-29 09:53:10 -0700
commitd50b12931404946e219d3ff0878f0632445ef35f (patch)
treee411e56cdd94522dae108a86b12494069bd7f5a9 /examples/07_sample_bot_structure/src/main.rs
parentFix #206 (#207) (diff)
downloadserenity-d50b12931404946e219d3ff0878f0632445ef35f.tar.xz
serenity-d50b12931404946e219d3ff0878f0632445ef35f.zip
Add logging and dotenv to example 07
Diffstat (limited to 'examples/07_sample_bot_structure/src/main.rs')
-rw-r--r--examples/07_sample_bot_structure/src/main.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/examples/07_sample_bot_structure/src/main.rs b/examples/07_sample_bot_structure/src/main.rs
index 8962d55..01f7a61 100644
--- a/examples/07_sample_bot_structure/src/main.rs
+++ b/examples/07_sample_bot_structure/src/main.rs
@@ -9,18 +9,43 @@
//! features = ["framework", "standard_framework"]
//! ```
-#[macro_use]
-extern crate serenity;
+#[macro_use] extern crate log;
+#[macro_use] extern crate serenity;
+
+extern crate env_logger;
+extern crate kankyo;
mod commands;
-use serenity::prelude::*;
use serenity::framework::StandardFramework;
+use serenity::model::event::ResumedEvent;
+use serenity::model::Ready;
+use serenity::prelude::*;
use std::env;
-struct Handler; impl EventHandler for Handler {}
+struct Handler;
+
+impl EventHandler for Handler {
+ fn on_ready(&self, _: Context, ready: Ready) {
+ info!("Connected as {}", ready.user.name);
+ }
+
+ fn on_resume(&self, _: Context, _: ResumedEvent) {
+ info!("Resumed");
+ }
+}
fn main() {
+ // This will load the environment variables located at `./.env`, relative to
+ // the CWD. See `./.env.example` for an example on how to structure this.
+ kankyo::load().expect("Failed to load .env file");
+
+ // Initialize the logger to use environment variables.
+ //
+ // In this case, a good default is setting the environment variable
+ // `RUST_LOG` to debug`.
+ env_logger::init().expect("Failed to initialize env_logger");
+
let mut client = Client::new(&env::var("DISCORD_TOKEN").unwrap(), Handler);
client.with_framework(StandardFramework::new()
@@ -30,6 +55,6 @@ fn main() {
.command("multiply", |c| c.exec(commands::math::multiply)));
if let Err(why) = client.start() {
- println!("Client error: {:?}", why);
+ error!("Client error: {:?}", why);
}
}