aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/01_basic_ping_bot/Cargo.toml7
-rw-r--r--examples/01_basic_ping_bot/src/main.rs (renamed from examples/01_basic_ping_bot.rs)0
-rw-r--r--examples/02_transparent_guild_sharding/Cargo.toml7
-rw-r--r--examples/02_transparent_guild_sharding/src/main.rs (renamed from examples/02_transparent_guild_sharding.rs)0
-rw-r--r--examples/03_struct_utilities/Cargo.toml7
-rw-r--r--examples/03_struct_utilities/src/main.rs (renamed from examples/03_struct_utilities.rs)18
-rw-r--r--examples/04_message_builder/Cargo.toml7
-rw-r--r--examples/04_message_builder/src/main.rs (renamed from examples/04_message_builder.rs)0
-rw-r--r--examples/05_user_login/Cargo.toml7
-rw-r--r--examples/05_user_login/src/main.rs (renamed from examples/05_user_login.rs)0
-rw-r--r--examples/06_command_framework/Cargo.toml7
-rw-r--r--examples/06_command_framework/src/main.rs (renamed from examples/06_command_framework.rs)18
-rw-r--r--examples/07_voice/Cargo.toml7
-rw-r--r--examples/07_voice/src/main.rs (renamed from examples/07_voice.rs)29
14 files changed, 77 insertions, 37 deletions
diff --git a/examples/01_basic_ping_bot/Cargo.toml b/examples/01_basic_ping_bot/Cargo.toml
new file mode 100644
index 0000000..603ee6b
--- /dev/null
+++ b/examples/01_basic_ping_bot/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "01_basic_ping_bot"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+serenity = { git = "https://github.com/zeyla/serenity.rs.git" }
diff --git a/examples/01_basic_ping_bot.rs b/examples/01_basic_ping_bot/src/main.rs
index 8db4614..8db4614 100644
--- a/examples/01_basic_ping_bot.rs
+++ b/examples/01_basic_ping_bot/src/main.rs
diff --git a/examples/02_transparent_guild_sharding/Cargo.toml b/examples/02_transparent_guild_sharding/Cargo.toml
new file mode 100644
index 0000000..3899f6d
--- /dev/null
+++ b/examples/02_transparent_guild_sharding/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "02_transparent_guild_sharding"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+serenity = { git = "https://github.com/zeyla/serenity.rs.git" }
diff --git a/examples/02_transparent_guild_sharding.rs b/examples/02_transparent_guild_sharding/src/main.rs
index 19b61d0..19b61d0 100644
--- a/examples/02_transparent_guild_sharding.rs
+++ b/examples/02_transparent_guild_sharding/src/main.rs
diff --git a/examples/03_struct_utilities/Cargo.toml b/examples/03_struct_utilities/Cargo.toml
new file mode 100644
index 0000000..8dc013c
--- /dev/null
+++ b/examples/03_struct_utilities/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "03_struct_utilities"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+serenity = { git = "https://github.com/zeyla/serenity.rs.git" }
diff --git a/examples/03_struct_utilities.rs b/examples/03_struct_utilities/src/main.rs
index ea91500..6bf436d 100644
--- a/examples/03_struct_utilities.rs
+++ b/examples/03_struct_utilities/src/main.rs
@@ -1,13 +1,18 @@
-//! Requires the 'methods' feature flag be enabled.
+//! Requires the 'methods' feature flag be enabled in your project's Cargo.toml.
+//!
+//! This can be activated by specifying the feature in the dependency section:
+//!
+//! ```toml
+//! [dependencies.serenity]
+//! git = "https://github.com/zeyla/serenity.rs.git"
+//! features = ["methods"]
+//! ```
extern crate serenity;
-#[cfg(feature = "methods")]
use serenity::Client;
-#[cfg(feature = "methods")]
use std::env;
-#[cfg(feature = "methods")]
fn main() {
// Configure the client with your Discord bot token in the environment.
let token = env::var("DISCORD_TOKEN")
@@ -26,8 +31,3 @@ fn main() {
let _ = client.start();
}
-
-#[cfg(not(feature = "methods"))]
-fn main() {
- println!("The 'methods' feature flag is required for this example.");
-}
diff --git a/examples/04_message_builder/Cargo.toml b/examples/04_message_builder/Cargo.toml
new file mode 100644
index 0000000..cf0108f
--- /dev/null
+++ b/examples/04_message_builder/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "04_message_builder"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+serenity = { git = "https://github.com/zeyla/serenity.rs.git" }
diff --git a/examples/04_message_builder.rs b/examples/04_message_builder/src/main.rs
index 41f390b..41f390b 100644
--- a/examples/04_message_builder.rs
+++ b/examples/04_message_builder/src/main.rs
diff --git a/examples/05_user_login/Cargo.toml b/examples/05_user_login/Cargo.toml
new file mode 100644
index 0000000..0f0a19e
--- /dev/null
+++ b/examples/05_user_login/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "05_user_login"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+serenity = { git = "https://github.com/zeyla/serenity.rs.git" }
diff --git a/examples/05_user_login.rs b/examples/05_user_login/src/main.rs
index bbc9303..bbc9303 100644
--- a/examples/05_user_login.rs
+++ b/examples/05_user_login/src/main.rs
diff --git a/examples/06_command_framework/Cargo.toml b/examples/06_command_framework/Cargo.toml
new file mode 100644
index 0000000..fa93475
--- /dev/null
+++ b/examples/06_command_framework/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "06_command_framework"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+serenity = { git = "https://github.com/zeyla/serenity.rs.git" }
diff --git a/examples/06_command_framework.rs b/examples/06_command_framework/src/main.rs
index 78e4e9e..95d832c 100644
--- a/examples/06_command_framework.rs
+++ b/examples/06_command_framework/src/main.rs
@@ -1,3 +1,13 @@
+//! Requires the 'methods' feature flag be enabled in your project's Cargo.toml.
+//!
+//! This can be activated by specifying the feature in the dependency section:
+//!
+//! ```toml
+//! [dependencies.serenity]
+//! git = "https://github.com/zeyla/serenity.rs.git"
+//! features = ["framework", methods"]
+//! ```
+
#[macro_use]
extern crate serenity;
@@ -56,18 +66,10 @@ fn dog_command(context: &Context, _msg: &Message, _args: Vec<String>) {
}
// `Message::reply` is only compiled if the `methods` feature flag is enabled.
-#[cfg(feature = "methods")]
fn ping_command(_context: &Context, message: &Message, _args: Vec<String>) {
let _ = message.reply("Pong!");
}
-#[cfg(not(feature = "methods"))]
-fn ping_command(context: &Context, message: &Message, _args: Vec<String>) {
- if let Err(why) = context.say(&format!("{}: Pong!", message.author)) {
- println!("Error sending message: {:?}", why);
- }
-}
-
fn owner_check(_context: &Context, message: &Message) -> bool {
// Replace 7 with your ID
message.author.id == 7
diff --git a/examples/07_voice/Cargo.toml b/examples/07_voice/Cargo.toml
new file mode 100644
index 0000000..d17a835
--- /dev/null
+++ b/examples/07_voice/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "07_voice"
+version = "0.1.0"
+authors = ["my name <[email protected]>"]
+
+[dependencies]
+serenity = { git = "https://github.com/zeyla/serenity.rs.git" }
diff --git a/examples/07_voice.rs b/examples/07_voice/src/main.rs
index e685f37..fe02245 100644
--- a/examples/07_voice.rs
+++ b/examples/07_voice/src/main.rs
@@ -1,24 +1,20 @@
-// Requires the feature "voice" be enabled.
+//! Requires the "cache", "methods", and "voice" features be enabled in your
+//! Cargo.toml, like so:
+//!
+//! ```toml
+//! [dependencies.serenity]
+//! version = "*"
+//! features = ["cache", "methods", "voice"]
+//! ```
extern crate serenity;
-#[cfg(feature = "voice")]
use serenity::client::{CACHE, Client, Context};
-#[cfg(feature = "voice")]
use serenity::ext::voice;
-#[cfg(feature = "voice")]
use serenity::model::{ChannelId, Message};
-#[cfg(feature = "voice")]
use serenity::Result as SerenityResult;
-#[cfg(feature = "voice")]
use std::env;
-#[cfg(not(feature = "voice"))]
-fn main() {
- panic!("'extras' and 'voice' must be enabled");
-}
-
-#[cfg(feature = "voice")]
fn main() {
// Configure the client with your Discord bot token in the environment.
let token = env::var("DISCORD_TOKEN")
@@ -45,7 +41,6 @@ fn main() {
let _ = client.start().map_err(|why| println!("Client ended: {:?}", why));
}
-#[cfg(feature = "voice")]
fn deafen(context: &Context, message: &Message, _args: Vec<String>) {
let guild_id = match CACHE.read().unwrap().get_guild_channel(message.channel_id) {
Some(channel) => channel.guild_id,
@@ -76,7 +71,6 @@ fn deafen(context: &Context, message: &Message, _args: Vec<String>) {
}
}
-#[cfg(feature = "voice")]
fn join(context: &Context, message: &Message, args: Vec<String>) {
let connect_to = match args.get(0) {
Some(arg) => match arg.parse::<u64>() {
@@ -109,7 +103,6 @@ fn join(context: &Context, message: &Message, args: Vec<String>) {
check_msg(context.say(&format!("Joined {}", connect_to.mention())));
}
-#[cfg(feature = "voice")]
fn leave(context: &Context, message: &Message, _args: Vec<String>) {
let guild_id = match CACHE.read().unwrap().get_guild_channel(message.channel_id) {
Some(channel) => channel.guild_id,
@@ -132,7 +125,6 @@ fn leave(context: &Context, message: &Message, _args: Vec<String>) {
}
}
-#[cfg(feature = "voice")]
fn mute(context: &Context, message: &Message, _args: Vec<String>) {
let guild_id = match CACHE.read().unwrap().get_guild_channel(message.channel_id) {
Some(channel) => channel.guild_id,
@@ -163,12 +155,10 @@ fn mute(context: &Context, message: &Message, _args: Vec<String>) {
}
}
-#[cfg(feature = "voice")]
fn ping(context: &Context, _message: &Message, _args: Vec<String>) {
check_msg(context.say("Pong!"));
}
-#[cfg(feature = "voice")]
fn play(context: &Context, message: &Message, args: Vec<String>) {
let url = match args.get(0) {
Some(url) => url,
@@ -214,7 +204,6 @@ fn play(context: &Context, message: &Message, args: Vec<String>) {
}
}
-#[cfg(feature = "voice")]
fn undeafen(context: &Context, message: &Message, _args: Vec<String>) {
let guild_id = match CACHE.read().unwrap().get_guild_channel(message.channel_id) {
Some(channel) => channel.guild_id,
@@ -234,7 +223,6 @@ fn undeafen(context: &Context, message: &Message, _args: Vec<String>) {
}
}
-#[cfg(feature = "voice")]
fn unmute(context: &Context, message: &Message, _args: Vec<String>) {
let guild_id = match CACHE.read().unwrap().get_guild_channel(message.channel_id) {
Some(channel) => channel.guild_id,
@@ -255,6 +243,7 @@ fn unmute(context: &Context, message: &Message, _args: Vec<String>) {
}
/// Checks that a message successfully sent; if not, then logs why to stdout.
+#[cfg(feature = "voice")]
fn check_msg(result: SerenityResult<Message>) {
if let Err(why) = result {
println!("Error sending message: {:?}", why);