aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/06_command_framework.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/examples/06_command_framework.rs b/examples/06_command_framework.rs
index af8781c..38f756d 100644
--- a/examples/06_command_framework.rs
+++ b/examples/06_command_framework.rs
@@ -12,10 +12,6 @@ fn main() {
.expect("Expected a token in the environment");
let mut client = Client::login_bot(&token);
- client.on_message(|_context, message| {
- println!("Received message: {:?}", message);
- });
-
client.on_ready(|_context, ready| {
println!("{} is connected!", ready.user.name);
});
@@ -28,9 +24,17 @@ fn main() {
// "~some complex command"
client.with_framework(|f| f
.configure(|c| c
- .on_mention(true)
.allow_whitespace(true)
+ .on_mention(true)
.prefix("~"))
+ .before(|_context, message, command_name| {
+ println!("Got command '{}' by user '{}'",
+ command_name,
+ message.author.name);
+ })
+ .after(|_context, _message, command_name| {
+ println!("Processed command '{}'", command_name)
+ })
.on("ping", ping_command)
.set_check("ping", owner_check) // Ensure only the owner can run this
.on("emoji cat", cat_command)
@@ -47,11 +51,11 @@ command!(cat_command(context, _msg, _arg) {
let _ = context.say(":cat:");
});
-fn dog_command(context: Context, _msg: Message, _args: Vec<String>) {
+fn dog_command(context: &Context, _msg: &Message, _args: Vec<String>) {
let _ = context.say(":dog:");
}
-fn ping_command(_context: Context, message: Message, _args: Vec<String>) {
+fn ping_command(_context: &Context, message: &Message, _args: Vec<String>) {
let _ = message.reply("Pong!");
}
@@ -60,7 +64,7 @@ fn owner_check(_context: &Context, message: &Message) -> bool {
message.author.id == 7
}
-fn some_complex_command(context: Context, _msg: Message, args: Vec<String>) {
+fn some_complex_command(context: &Context, _msg: &Message, args: Vec<String>) {
let _ = context.say(&format!("Arguments: {:?}", args));
}