aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLake Lezz <[email protected]>2018-11-16 02:27:06 +0100
committeracdenisSK <[email protected]>2018-11-16 20:57:13 +0100
commit653e596527020954738104558a8596ae0c378279 (patch)
treedaedfe7ec9e41f98772b8ea5d8c9d5a4ae77c86a /examples
parentMerge branch 'current' into v0.6.x (diff)
downloadserenity-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.rs26
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);
+ }
+});