diff options
| author | Maiddog <[email protected]> | 2017-08-27 17:54:16 -0500 |
|---|---|---|
| committer | alex <[email protected]> | 2017-08-28 00:54:16 +0200 |
| commit | 4e360cf86a74051e2d4f98758c65ae29b97b7b8b (patch) | |
| tree | 6f2a02381b507432b089dbdeeabeb89ff496efe8 /examples | |
| parent | Prevent malformed opus data from crashing the bot process (#149) (diff) | |
| download | serenity-4e360cf86a74051e2d4f98758c65ae29b97b7b8b.tar.xz serenity-4e360cf86a74051e2d4f98758c65ae29b97b7b8b.zip | |
Fix examples (#151)
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/02_transparent_guild_sharding/src/main.rs | 8 | ||||
| -rw-r--r-- | examples/03_struct_utilities/src/main.rs | 2 | ||||
| -rw-r--r-- | examples/05_command_framework/src/main.rs | 9 | ||||
| -rw-r--r-- | examples/06_voice/src/main.rs | 6 | ||||
| -rw-r--r-- | examples/07_sample_bot_structure/src/commands/math.rs | 5 |
5 files changed, 17 insertions, 13 deletions
diff --git a/examples/02_transparent_guild_sharding/src/main.rs b/examples/02_transparent_guild_sharding/src/main.rs index 8546b0f..55b20c1 100644 --- a/examples/02_transparent_guild_sharding/src/main.rs +++ b/examples/02_transparent_guild_sharding/src/main.rs @@ -25,17 +25,15 @@ use std::env; struct Handler; impl EventHandler for Handler { - fn on_message(&self, _: Context, msg: Message) { + fn on_message(&self, ctx: Context, msg: Message) { if msg.content == "!ping" { // The current shard needs to be unlocked so it can be read from, as // multiple threads may otherwise attempt to read from or mutate it // concurrently. { let shard = ctx.shard.lock(); - - if let Some(shard_info) = shard.shard_info() { - println!("Shard {}", shard_info[0]); - } + let shard_info = shard.shard_info(); + println!("Shard {}", shard_info[0]); } if let Err(why) = msg.channel_id.say("Pong!") { diff --git a/examples/03_struct_utilities/src/main.rs b/examples/03_struct_utilities/src/main.rs index 5f777bd..e08cf00 100644 --- a/examples/03_struct_utilities/src/main.rs +++ b/examples/03_struct_utilities/src/main.rs @@ -17,7 +17,7 @@ impl EventHandler for Handler { // In this case, you can direct message a User directly by simply // calling a method on its instance, with the content of the // message. - if let Err(why) = msg.author.dm("Hello!") { + if let Err(why) = msg.author.dm(|m| m.content("Hello!")) { println!("Error when direct messaging user: {:?}", why); } } diff --git a/examples/05_command_framework/src/main.rs b/examples/05_command_framework/src/main.rs index 6cf5692..d987628 100644 --- a/examples/05_command_framework/src/main.rs +++ b/examples/05_command_framework/src/main.rs @@ -15,7 +15,7 @@ extern crate typemap; use serenity::prelude::*; use serenity::model::*; -use serenity::framework::standard::{Command, DispatchError, StandardFramework, help_commands}; +use serenity::framework::standard::{Args, Command, DispatchError, StandardFramework, help_commands}; use std::collections::HashMap; use std::env; use std::fmt::Write; @@ -166,7 +166,7 @@ command!(commands(ctx, msg, _args) { // In this case, this command checks to ensure you are the owner of the message // in order for the command to be executed. If the check fails, the command is // not called. -fn owner_check(_: &mut Context, msg: &Message, _: &[String], _: &Arc<Command>) -> bool { +fn owner_check(_: &mut Context, msg: &Message, _: &mut Args, _: &Arc<Command>) -> bool { // Replace 7 with your ID msg.author.id == 7 } @@ -197,7 +197,10 @@ command!(some_long_command(_ctx, msg, args) { // will be ignored. // // Argument type overloading is currently not supported. -command!(multiply(_ctx, msg, args, first: f64, second: f64) { +command!(multiply(_ctx, msg, args) { + let first = args.single::<f64>().unwrap(); + let second = args.single::<f64>().unwrap(); + let res = first * second; if let Err(why) = msg.channel_id.say(&res.to_string()) { diff --git a/examples/06_voice/src/main.rs b/examples/06_voice/src/main.rs index d074eb8..40d8817 100644 --- a/examples/06_voice/src/main.rs +++ b/examples/06_voice/src/main.rs @@ -191,7 +191,7 @@ command!(play(ctx, msg, args) { }, }; - if let Some(handler) = ctx.shard.lock().unwrap().manager.get(guild_id) { + if let Some(handler) = ctx.shard.lock().manager.get(guild_id) { let source = match voice::ytdl(url) { Ok(source) => source, Err(why) => { @@ -221,7 +221,7 @@ command!(undeafen(ctx, msg) { }, }; - if let Some(handler) = ctx.shard.lock().unwrap().manager.get(guild_id) { + if let Some(handler) = ctx.shard.lock().manager.get(guild_id) { handler.deafen(false); check_msg(msg.channel_id.say("Undeafened")); @@ -240,7 +240,7 @@ command!(unmute(ctx, msg) { }, }; - if let Some(handler) = ctx.shard.lock().unwrap().manager.get(guild_id) { + if let Some(handler) = ctx.shard.lock().manager.get(guild_id) { handler.mute(false); check_msg(msg.channel_id.say("Unmuted")); diff --git a/examples/07_sample_bot_structure/src/commands/math.rs b/examples/07_sample_bot_structure/src/commands/math.rs index 2b1c1d2..3aaccc4 100644 --- a/examples/07_sample_bot_structure/src/commands/math.rs +++ b/examples/07_sample_bot_structure/src/commands/math.rs @@ -1,4 +1,7 @@ -command!(multiply(_ctx, msg, _args, one: f64, two: f64) { +command!(multiply(_ctx, msg, args) { + let one = args.single::<f64>().unwrap(); + let two = args.single::<f64>().unwrap(); + let product = one * two; let _ = msg.channel_id.say(product); |