aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTaavi <[email protected]>2017-01-02 03:38:36 +0300
committerzeyla <[email protected]>2017-01-01 16:38:36 -0800
commit18cc152769a35cd1705f045b9815cc90446034ef (patch)
treeb33d18158b62ad5d89cd35f4f547aadb509369e2 /examples
parentFix command macro signatures (diff)
downloadserenity-18cc152769a35cd1705f045b9815cc90446034ef.tar.xz
serenity-18cc152769a35cd1705f045b9815cc90446034ef.zip
Implement context message queueing
Also the dreaded `ctx <<= "something"` which is actually a mistake.
Diffstat (limited to 'examples')
-rw-r--r--examples/06_command_framework/src/main.rs6
-rw-r--r--examples/08_search/src/main.rs15
2 files changed, 11 insertions, 10 deletions
diff --git a/examples/06_command_framework/src/main.rs b/examples/06_command_framework/src/main.rs
index 4aeafe1..35a6994 100644
--- a/examples/06_command_framework/src/main.rs
+++ b/examples/06_command_framework/src/main.rs
@@ -81,9 +81,9 @@ fn main() {
let entry = counter.entry(command_name.clone()).or_insert(0);
*entry += 1;
- true
+ true // if `before` returns false, command processing doesn't happen.
})
- // Very similar to `before`, except this will be called directly _after_
+ // Similar to `before`, except will be called directly _after_
// command execution.
.after(|_, _, command_name, error| {
match error {
@@ -153,7 +153,7 @@ command!(commands(context, _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(_: &Context, message: &Message) -> bool {
+fn owner_check(_: &mut Context, message: &Message) -> bool {
// Replace 7 with your ID
message.author.id == 7
}
diff --git a/examples/08_search/src/main.rs b/examples/08_search/src/main.rs
index 53d194f..4fe0a0e 100644
--- a/examples/08_search/src/main.rs
+++ b/examples/08_search/src/main.rs
@@ -13,6 +13,7 @@
//! This particular example will automatically ensure that only the current user
//! may search; this acts as a "selfbot".
+#[macro_use]
extern crate serenity;
use serenity::client::{CACHE, Client, Context};
@@ -37,17 +38,17 @@ fn main() {
}
}
-fn self_check(_context: &Context, message: &Message) -> bool {
+fn self_check(_context: &mut Context, message: &Message) -> bool {
message.author.id == CACHE.read().unwrap().user.id
}
-fn search(context: &Context, message: &Message, args: Vec<String>) {
+command!(search(context, message, args) {
let query = args.join(" ");
if query.is_empty() {
let _ = context.say("You must provide a query");
- return;
+ return Ok(());
}
let guild_id = match message.guild_id() {
@@ -55,7 +56,7 @@ fn search(context: &Context, message: &Message, args: Vec<String>) {
None => {
let _ = context.say("Only supports guilds");
- return;
+ return Ok(());
},
};
@@ -67,7 +68,7 @@ fn search(context: &Context, message: &Message, args: Vec<String>) {
None => {
let _ = context.say("Guild data not found");
- return;
+ return Ok(());
},
};
@@ -94,7 +95,7 @@ fn search(context: &Context, message: &Message, args: Vec<String>) {
let _ = context.say("Error occurred while searching");
- return;
+ return Ok(());
},
};
@@ -112,4 +113,4 @@ fn search(context: &Context, message: &Message, args: Vec<String>) {
e
}));
-}
+});