diff options
| author | Austin Hellyer <[email protected]> | 2017-01-24 08:55:49 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2017-01-24 08:55:49 -0800 |
| commit | 47510594e5c939406ebccec8af7e3107a338c7bc (patch) | |
| tree | 8def4138c4d6d33ae40e290c51a39c131ae2850d /examples | |
| parent | Code style (diff) | |
| download | serenity-47510594e5c939406ebccec8af7e3107a338c7bc.tar.xz serenity-47510594e5c939406ebccec8af7e3107a338c7bc.zip | |
Update examples for OOP style update
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/01_basic_ping_bot/Cargo.toml | 4 | ||||
| -rw-r--r-- | examples/01_basic_ping_bot/src/main.rs | 6 | ||||
| -rw-r--r-- | examples/02_transparent_guild_sharding/Cargo.toml | 4 | ||||
| -rw-r--r-- | examples/02_transparent_guild_sharding/src/main.rs | 8 | ||||
| -rw-r--r-- | examples/03_struct_utilities/Cargo.toml | 5 | ||||
| -rw-r--r-- | examples/03_struct_utilities/src/main.rs | 5 | ||||
| -rw-r--r-- | examples/04_message_builder/Cargo.toml | 4 | ||||
| -rw-r--r-- | examples/04_message_builder/src/main.rs | 6 | ||||
| -rw-r--r-- | examples/05_user_login/Cargo.toml | 4 | ||||
| -rw-r--r-- | examples/05_user_login/src/main.rs | 2 | ||||
| -rw-r--r-- | examples/06_command_framework/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/06_command_framework/src/main.rs | 18 | ||||
| -rw-r--r-- | examples/07_voice/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/07_voice/src/main.rs | 2 | ||||
| -rw-r--r-- | examples/08_search/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/08_search/src/main.rs | 15 |
16 files changed, 43 insertions, 45 deletions
diff --git a/examples/01_basic_ping_bot/Cargo.toml b/examples/01_basic_ping_bot/Cargo.toml index d4cbb5f..deded6f 100644 --- a/examples/01_basic_ping_bot/Cargo.toml +++ b/examples/01_basic_ping_bot/Cargo.toml @@ -3,5 +3,5 @@ name = "01_basic_ping_bot" version = "0.1.0" authors = ["my name <[email protected]>"] -[dependencies.serenity] -path = "../../" +[dependencies] +serenity = { path = "../../" } diff --git a/examples/01_basic_ping_bot/src/main.rs b/examples/01_basic_ping_bot/src/main.rs index e00263b..991b537 100644 --- a/examples/01_basic_ping_bot/src/main.rs +++ b/examples/01_basic_ping_bot/src/main.rs @@ -18,13 +18,13 @@ fn main() { // // Event handlers are dispatched through multi-threading, and so multiple // of a single event can be dispatched simultaneously. - client.on_message(|context, message| { + client.on_message(|ctx, message| { if message.content == "!ping" { // Sending a message can fail, due to a network error, an // authentication error, or lack of permissions to post in the // channel, so log to stdout when some error happens, with a // description of it. - if let Err(why) = context.say("Pong!") { + if let Err(why) = ctx.say("Pong!") { println!("Error sending message: {:?}", why); } } @@ -36,7 +36,7 @@ fn main() { // relationships, and more. // // In this case, just print what the current user's username is. - client.on_ready(|_context, ready| { + client.on_ready(|_ctx, ready| { println!("{} is connected!", ready.user.name); }); diff --git a/examples/02_transparent_guild_sharding/Cargo.toml b/examples/02_transparent_guild_sharding/Cargo.toml index 620c7af..808b5c1 100644 --- a/examples/02_transparent_guild_sharding/Cargo.toml +++ b/examples/02_transparent_guild_sharding/Cargo.toml @@ -3,5 +3,5 @@ name = "02_transparent_guild_sharding" version = "0.1.0" authors = ["my name <[email protected]>"] -[dependencies.serenity] -path = "../../" +[dependencies] +serenity = { path = "../../" } diff --git a/examples/02_transparent_guild_sharding/src/main.rs b/examples/02_transparent_guild_sharding/src/main.rs index 1e3446f..b0a639a 100644 --- a/examples/02_transparent_guild_sharding/src/main.rs +++ b/examples/02_transparent_guild_sharding/src/main.rs @@ -27,26 +27,26 @@ fn main() { .expect("Expected a token in the environment"); let mut client = Client::login_bot(&token); - client.on_message(|context, message| { + client.on_message(|ctx, message| { if message.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 = context.shard.lock().unwrap(); + let shard = ctx.shard.lock().unwrap(); if let Some(shard_info) = shard.shard_info() { println!("Shard {}", shard_info[0]); } } - if let Err(why) = context.say("Pong!") { + if let Err(why) = ctx.say("Pong!") { println!("Error sending message: {:?}", why); } } }); - client.on_ready(|_context, ready| { + client.on_ready(|_ctx, ready| { println!("{} is connected!", ready.user.name); }); diff --git a/examples/03_struct_utilities/Cargo.toml b/examples/03_struct_utilities/Cargo.toml index dc89662..e9a563e 100644 --- a/examples/03_struct_utilities/Cargo.toml +++ b/examples/03_struct_utilities/Cargo.toml @@ -3,6 +3,5 @@ name = "03_struct_utilities" version = "0.1.0" authors = ["my name <[email protected]>"] -[dependencies.serenity] -features = ["methods"] -path = "../../" +[dependencies] +serenity = { path = "../../" } diff --git a/examples/03_struct_utilities/src/main.rs b/examples/03_struct_utilities/src/main.rs index 942d918..d31b840 100644 --- a/examples/03_struct_utilities/src/main.rs +++ b/examples/03_struct_utilities/src/main.rs @@ -5,7 +5,6 @@ //! ```toml //! [dependencies.serenity] //! git = "https://github.com/zeyla/serenity.git" -//! features = ["methods"] //! ``` extern crate serenity; @@ -19,7 +18,7 @@ fn main() { .expect("Expected a token in the environment"); let mut client = Client::login_bot(&token); - client.on_message(|_context, message| { + client.on_message(|_ctx, message| { if message.content == "!messageme" { // If the `methods` feature is enabled, then model structs will // have a lot of useful methods implemented, to avoid using an @@ -35,7 +34,7 @@ fn main() { } }); - client.on_ready(|_context, ready| { + client.on_ready(|_ctx, ready| { println!("{} is connected!", ready.user.name); }); diff --git a/examples/04_message_builder/Cargo.toml b/examples/04_message_builder/Cargo.toml index c5bd639..76ad5ed 100644 --- a/examples/04_message_builder/Cargo.toml +++ b/examples/04_message_builder/Cargo.toml @@ -3,5 +3,5 @@ name = "04_message_builder" version = "0.1.0" authors = ["my name <[email protected]>"] -[dependencies.serenity] -path = "../../" +[dependencies] +serenity = { path = "../../" } diff --git a/examples/04_message_builder/src/main.rs b/examples/04_message_builder/src/main.rs index 2712fe6..8817065 100644 --- a/examples/04_message_builder/src/main.rs +++ b/examples/04_message_builder/src/main.rs @@ -10,9 +10,9 @@ fn main() { .expect("Expected a token in the environment"); let mut client = Client::login_bot(&token); - client.on_message(|context, message| { + client.on_message(|ctx, message| { if message.content == "!ping" { - let channel = match context.get_channel(message.channel_id) { + let channel = match ctx.get_channel() { Ok(channel) => channel, Err(why) => { println!("Error getting channel: {:?}", why); @@ -32,7 +32,7 @@ fn main() { .push(" channel") .build(); - if let Err(why) = context.say(&response) { + if let Err(why) = ctx.say(&response) { println!("Error sending message: {:?}", why); } } diff --git a/examples/05_user_login/Cargo.toml b/examples/05_user_login/Cargo.toml index 4b0fdcc..1cdf703 100644 --- a/examples/05_user_login/Cargo.toml +++ b/examples/05_user_login/Cargo.toml @@ -3,5 +3,5 @@ name = "05_user_login" version = "0.1.0" authors = ["my name <[email protected]>"] -[dependencies.serenity] -path = "../../" +[dependencies] +serenity = { path = "../../" } diff --git a/examples/05_user_login/src/main.rs b/examples/05_user_login/src/main.rs index 582dfbf..5fdfbf0 100644 --- a/examples/05_user_login/src/main.rs +++ b/examples/05_user_login/src/main.rs @@ -17,7 +17,7 @@ fn main() { // disallow you from performing bot-only commands. let mut client = Client::login_user(&token); - client.on_ready(|_context, ready| { + client.on_ready(|_ctx, ready| { println!("{} is connected!", ready.user.name); }); diff --git a/examples/06_command_framework/Cargo.toml b/examples/06_command_framework/Cargo.toml index ec4fea7..bddfc55 100644 --- a/examples/06_command_framework/Cargo.toml +++ b/examples/06_command_framework/Cargo.toml @@ -7,5 +7,5 @@ authors = ["my name <[email protected]>"] typemap = "0.3" [dependencies.serenity] -features = ["framework", "methods"] +features = ["framework"] path = "../../" diff --git a/examples/06_command_framework/src/main.rs b/examples/06_command_framework/src/main.rs index a0e4b7f..0561f56 100644 --- a/examples/06_command_framework/src/main.rs +++ b/examples/06_command_framework/src/main.rs @@ -5,7 +5,7 @@ //! ```toml //! [dependencies.serenity] //! git = "https://github.com/zeyla/serenity.git" -//! features = ["framework", "methods"] +//! features = ["framework"] //! ``` #[macro_use] @@ -38,7 +38,7 @@ fn main() { data.insert::<CommandCounter>(HashMap::default()); } - client.on_ready(|_, ready| { + client.on_ready(|_ctx, ready| { println!("{} is connected!", ready.user.name); }); @@ -133,17 +133,17 @@ fn main() { // This may bring more features available for commands in the future. See the // "multiply" command below for some of the power that the `command!` macro can // bring. -command!(commands(context, _msg, _args) { +command!(commands(ctx, _msg, _args) { let mut contents = "Commands used:\n".to_owned(); - let data = context.data.lock().unwrap(); + let data = ctx.data.lock().unwrap(); let counter = data.get::<CommandCounter>().unwrap(); for (k, v) in counter { let _ = write!(contents, "- {name}: {amount}\n", name=k, amount=v); } - if let Err(why) = context.say(&contents) { + if let Err(why) = ctx.say(&contents) { println!("Error sending message: {:?}", why); } }); @@ -158,8 +158,8 @@ fn owner_check(_: &mut Context, message: &Message) -> bool { message.author.id == 7 } -command!(some_long_command(context, _msg, args) { - if let Err(why) = context.say(&format!("Arguments: {:?}", args)) { +command!(some_long_command(ctx, _msg, args) { + if let Err(why) = ctx.say(&format!("Arguments: {:?}", args)) { println!("Error sending message: {:?}", why); } }); @@ -184,10 +184,10 @@ command!(some_long_command(context, _msg, args) { // will be ignored. // // Argument type overloading is currently not supported. -command!(multiply(context, _msg, args, first: f64, second: f64) { +command!(multiply(ctx, _msg, args, first: f64, second: f64) { let res = first * second; - if let Err(why) = context.say(&res.to_string()) { + if let Err(why) = ctx.say(&res.to_string()) { println!("Err sending product of {} and {}: {:?}", first, second, why); } }); diff --git a/examples/07_voice/Cargo.toml b/examples/07_voice/Cargo.toml index b09ea79..e2e3359 100644 --- a/examples/07_voice/Cargo.toml +++ b/examples/07_voice/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["my name <[email protected]>"] [dependencies.serenity] -features = ["cache", "framework", "methods", "voice"] +features = ["cache", "framework", "voice"] path = "../../" diff --git a/examples/07_voice/src/main.rs b/examples/07_voice/src/main.rs index f8a6921..b10b0ea 100644 --- a/examples/07_voice/src/main.rs +++ b/examples/07_voice/src/main.rs @@ -4,7 +4,7 @@ //! ```toml //! [dependencies.serenity] //! version = "*" -//! features = ["cache", "framework", "methods", "voice"] +//! features = ["cache", "framework", "voice"] //! ``` #[macro_use] diff --git a/examples/08_search/Cargo.toml b/examples/08_search/Cargo.toml index 5936ea5..961f9cf 100644 --- a/examples/08_search/Cargo.toml +++ b/examples/08_search/Cargo.toml @@ -4,5 +4,4 @@ version = "0.1.0" authors = ["Austin Hellyer <[email protected]>"] [dependencies] -#serenity = "0.1" serenity = { path = "../../" } diff --git a/examples/08_search/src/main.rs b/examples/08_search/src/main.rs index 4fe0a0e..915520a 100644 --- a/examples/08_search/src/main.rs +++ b/examples/08_search/src/main.rs @@ -4,7 +4,7 @@ //! ```toml //! [dependencies.serenity] //! version = "*" -//! features = ["cache", "framework", "methods"] +//! features = ["cache", "framework"] //! ``` //! //! Note that - due to bot users not being able to search - this example may @@ -26,8 +26,9 @@ fn main() { client.with_framework(|f| f .configure(|c| c.prefix("~").on_mention(true)) - .on("search", search) - .set_check("search", self_check)); + .command("search", |c| c + .exec(search) + .check(self_check))); client.on_ready(|_context, ready| { println!("{} is connected!", ready.user.name); @@ -76,10 +77,10 @@ command!(search(context, message, args) { .values() .filter(|c| c.name.starts_with("search-")) .map(|c| c.id) - .collect() + .collect::<Vec<_>>() }; - let search = context.search_guild(guild_id, channel_ids, |s| s + let search = guild_id.search_channels(&channel_ids, |s| s .content(&query) .context_size(0) .has_attachment(true) @@ -99,11 +100,11 @@ command!(search(context, message, args) { }, }; - let _ = context.send_message(message.channel_id, move |m| m + let _ = context.send_message(|m| m .content(&format!("Found {} total results", messages.total)) .embed(move |mut e| { for (i, mut messages) in messages.results.into_iter().enumerate() { - let ref mut message = messages[0]; + let mut message = &mut messages[0]; message.content.truncate(1000); e = e.field(|f| f |