diff options
| author | Lake Lezz <[email protected]> | 2018-11-16 02:27:06 +0100 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2018-11-16 20:57:13 +0100 |
| commit | 653e596527020954738104558a8596ae0c378279 (patch) | |
| tree | daedfe7ec9e41f98772b8ea5d8c9d5a4ae77c86a /examples | |
| parent | Merge branch 'current' into v0.6.x (diff) | |
| download | serenity-653e596527020954738104558a8596ae0c378279.tar.xz serenity-653e596527020954738104558a8596ae0c378279.zip | |
Add Slow Mode Rate (#439)
Fixes #402
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/05_command_framework/src/main.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/examples/05_command_framework/src/main.rs b/examples/05_command_framework/src/main.rs index 3fec94b..11dbc81 100644 --- a/examples/05_command_framework/src/main.rs +++ b/examples/05_command_framework/src/main.rs @@ -20,7 +20,7 @@ use serenity::{ framework::standard::{ help_commands, Args, CommandOptions, DispatchError, HelpBehaviour, StandardFramework, }, - model::{channel::Message, gateway::Ready, Permissions}, + model::{channel::{Channel, Message}, gateway::Ready, Permissions}, prelude::*, utils::{content_safe, ContentSafeOptions}, }; @@ -230,6 +230,9 @@ fn main() { .command("am i admin", |c| c .cmd(am_i_admin) .guild_only(true)) + .command("slow mode", |c| c + .cmd(slow_mode) + .guild_only(true)) ), ); @@ -441,3 +444,24 @@ command!(bird(_ctx, msg, args) { println!("Error sending message: {:?}", why); } }); + +command!(slow_mode(_ctx, msg, args) { + let say_content = if let Ok(slow_mode_rate_seconds) = args.single::<u64>() { + + if let Err(why) = msg.channel_id.edit(|c| c.slow_mode_rate(slow_mode_rate_seconds)) { + println!("Error setting channel's slow mode rate: {:?}", why); + + format!("Failed to set slow mode to `{}` seconds.", slow_mode_rate_seconds) + } else { + format!("Successfully set slow mode rate to `{}` seconds.", slow_mode_rate_seconds) + } + } else if let Some(Channel::Guild(channel)) = msg.channel_id.to_channel_cached() { + format!("Current slow mode rate is `{}` seconds.", channel.read().slow_mode_rate) + } else { + "Failed to find channel in cache.".to_string() + }; + + if let Err(why) = msg.channel_id.say(say_content) { + println!("Error sending message: {:?}", why); + } +}); |