Skip to content

Commit

Permalink
Add owner + quit functionality to example 07
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyla Hellyer committed Oct 29, 2017
1 parent 3616585 commit 41f26b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/07_sample_bot_structure/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod math;
pub mod meta;
pub mod owner;
10 changes: 10 additions & 0 deletions examples/07_sample_bot_structure/src/commands/owner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
command!(quit(ctx, msg, _args) {
match ctx.quit() {
Ok(()) => {
let _ = msg.reply("Shutting down!");
},
Err(why) => {
let _ = msg.reply(&format!("Failed to shutdown: {:?}", why));
},
}
});
21 changes: 19 additions & 2 deletions examples/07_sample_bot_structure/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use serenity::framework::StandardFramework;
use serenity::model::event::ResumedEvent;
use serenity::model::Ready;
use serenity::prelude::*;
use serenity::http;
use std::collections::HashSet;
use std::env;

struct Handler;
Expand Down Expand Up @@ -48,11 +50,26 @@ fn main() {

let mut client = Client::new(&env::var("DISCORD_TOKEN").unwrap(), Handler);

let owners = match http::get_current_application_info() {
Ok(info) => {
let mut set = HashSet::new();
set.insert(info.owner.id);

set
},
Err(why) => panic!("Couldn't get application info: {:?}", why),
};

client.with_framework(StandardFramework::new()
.configure(|c| c.prefix("~"))
.configure(|c| c
.owners(owners)
.prefix("~"))
.command("ping", |c| c.exec(commands::meta::ping))
.command("latency", |c| c.exec(commands::meta::latency))
.command("multiply", |c| c.exec(commands::math::multiply)));
.command("multiply", |c| c.exec(commands::math::multiply))
.command("quit", |c| c
.exec(commands::owner::quit)
.owners_only(true)));

if let Err(why) = client.start() {
error!("Client error: {:?}", why);
Expand Down

0 comments on commit 41f26b3

Please sign in to comment.