aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-08-06 13:51:45 +0200
committeracdenisSK <[email protected]>2017-08-06 13:53:43 +0200
commit9b09481216105cf75375346a6e41edd7d5869e7c (patch)
treeafb80b707a08f119ce81e21e64ba29bb0b061dc4
parentmake Travis test on OS X (#123) (diff)
downloadserenity-9b09481216105cf75375346a6e41edd7d5869e7c.tar.xz
serenity-9b09481216105cf75375346a6e41edd7d5869e7c.zip
Update examples
-rw-r--r--examples/04_message_builder/src/main.rs2
-rw-r--r--examples/05_command_framework/src/main.rs24
-rw-r--r--examples/06_voice/src/main.rs8
-rw-r--r--examples/07_sample_bot_structure/src/commands/math.rs2
-rw-r--r--examples/07_sample_bot_structure/src/commands/meta.rs2
-rw-r--r--examples/07_sample_bot_structure/src/main.rs9
6 files changed, 25 insertions, 22 deletions
diff --git a/examples/04_message_builder/src/main.rs b/examples/04_message_builder/src/main.rs
index 4fecb93..713224b 100644
--- a/examples/04_message_builder/src/main.rs
+++ b/examples/04_message_builder/src/main.rs
@@ -25,7 +25,7 @@ impl EventHandler for Handler {
// emojis, and more.
let response = MessageBuilder::new()
.push("User ")
- .push_bold_safe(&msg.author.name)
+ .push_bold_safe(msg.author.name)
.push(" used the 'ping' command in the ")
.mention(channel)
.push(" channel")
diff --git a/examples/05_command_framework/src/main.rs b/examples/05_command_framework/src/main.rs
index 2f7d57c..467c4ab 100644
--- a/examples/05_command_framework/src/main.rs
+++ b/examples/05_command_framework/src/main.rs
@@ -13,10 +13,9 @@
extern crate serenity;
extern crate typemap;
-use serenity::client::Context;
-use serenity::Client;
-use serenity::model::{Message, permissions};
-use serenity::ext::framework::{DispatchError, help_commands};
+use serenity::prelude::*;
+use serenity::model::*;
+use serenity::framework::{BuiltinFramework, DispatchError, help_commands};
use std::collections::HashMap;
use std::env;
use std::fmt::Write;
@@ -28,21 +27,25 @@ impl Key for CommandCounter {
type Value = HashMap<String, u64>;
}
+struct Handler;
+
+impl EventHandler for Handler {
+ fn on_ready(&self, _: Context, ready: Ready) {
+ println!("{} is connected!", ready.user.name);
+ }
+}
+
fn main() {
// Configure the client with your Discord bot token in the environment.
let token = env::var("DISCORD_TOKEN")
.expect("Expected a token in the environment");
- let mut client = Client::new(&token);
+ let mut client = Client::new(&token, Handler);
{
let mut data = client.data.lock().unwrap();
data.insert::<CommandCounter>(HashMap::default());
}
- client.on_ready(|_ctx, ready| {
- println!("{} is connected!", ready.user.name);
- });
-
// Commands are equivalent to:
// "~about"
// "~emoji cat"
@@ -50,13 +53,14 @@ fn main() {
// "~multiply"
// "~ping"
// "~some long command"
- client.with_framework(|f| f
+ client.with_framework(
// Configures the client, allowing for options to mutate how the
// framework functions.
//
// Refer to the documentation for
// `serenity::ext::framework::Configuration` for all available
// configurations.
+ BuiltinFramework::new()
.configure(|c| c
.allow_whitespace(true)
.on_mention(true)
diff --git a/examples/06_voice/src/main.rs b/examples/06_voice/src/main.rs
index d1a0c11..2faa207 100644
--- a/examples/06_voice/src/main.rs
+++ b/examples/06_voice/src/main.rs
@@ -29,7 +29,7 @@ fn main() {
// Configure the client with your Discord bot token in the environment.
let token = env::var("DISCORD_TOKEN")
.expect("Expected a token in the environment");
- let mut client = Client::new(&token);
+ let mut client = Client::new(&token, Handler);
client.with_framework(|f| f
.configure(|c| c
@@ -43,11 +43,7 @@ fn main() {
.on("ping", ping)
.on("undeafen", undeafen)
.on("unmute", unmute));
-
- client.on_ready(|_context, ready| {
- println!("{} is connected!", ready.user.name);
- });
-
+
let _ = client.start().map_err(|why| println!("Client ended: {:?}", why));
}
diff --git a/examples/07_sample_bot_structure/src/commands/math.rs b/examples/07_sample_bot_structure/src/commands/math.rs
index 79bfc52..2b1c1d2 100644
--- a/examples/07_sample_bot_structure/src/commands/math.rs
+++ b/examples/07_sample_bot_structure/src/commands/math.rs
@@ -1,5 +1,5 @@
command!(multiply(_ctx, msg, _args, one: f64, two: f64) {
let product = one * two;
- let _ = msg.channel_id.say(&product.to_string());
+ let _ = msg.channel_id.say(product);
});
diff --git a/examples/07_sample_bot_structure/src/commands/meta.rs b/examples/07_sample_bot_structure/src/commands/meta.rs
index a4036fc..fc7c492 100644
--- a/examples/07_sample_bot_structure/src/commands/meta.rs
+++ b/examples/07_sample_bot_structure/src/commands/meta.rs
@@ -6,7 +6,7 @@ command!(latency(ctx, msg) {
format!("{}.{}s", s.as_secs(), s.subsec_nanos())
});
- let _ = msg.channel_id.say(&latency);
+ let _ = msg.channel_id.say(latency);
});
command!(ping(_ctx, msg) {
diff --git a/examples/07_sample_bot_structure/src/main.rs b/examples/07_sample_bot_structure/src/main.rs
index 42ccd64..37227cc 100644
--- a/examples/07_sample_bot_structure/src/main.rs
+++ b/examples/07_sample_bot_structure/src/main.rs
@@ -14,13 +14,16 @@ extern crate serenity;
mod commands;
-use serenity::Client;
+use serenity::prelude::*;
+use serenity::framework::BuiltinFramework;
use std::env;
+struct Handler; impl EventHandler for Handler {}
+
fn main() {
- let mut client = Client::new(&env::var("DISCORD_TOKEN").unwrap());
+ let mut client = Client::new(&env::var("DISCORD_TOKEN").unwrap(), Handler);
- client.with_framework(|f| f
+ client.with_framework(BuiltinFramework::new()
.configure(|c| c.prefix("~"))
.command("ping", |c| c.exec(commands::meta::ping))
.command("latency", |c| c.exec(commands::meta::latency))