From e11ff3f72f49d9a19c8fc01cbf27ba092b47d54c Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 10 Apr 2021 11:50:16 +0200 Subject: [PATCH] Add optional code argument to shutdown command Signed-off-by: trivernis --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/misc/shutdown.rs | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a27dc07..1e9ee8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2050,7 +2050,7 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tobi-rs" -version = "0.1.1" +version = "0.1.2" dependencies = [ "aspotify", "chrono", diff --git a/Cargo.toml b/Cargo.toml index f3b4ecb..cb07cd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tobi-rs" -version = "0.1.1" +version = "0.1.2" authors = ["trivernis "] edition = "2018" diff --git a/src/commands/misc/shutdown.rs b/src/commands/misc/shutdown.rs index 1c2c6ec..297f248 100644 --- a/src/commands/misc/shutdown.rs +++ b/src/commands/misc/shutdown.rs @@ -1,19 +1,25 @@ use crate::commands::common::handle_autodelete; use serenity::framework::standard::macros::command; -use serenity::framework::standard::CommandResult; +use serenity::framework::standard::{Args, CommandResult}; use serenity::model::channel::Message; use serenity::prelude::*; use std::process; #[command] -#[description("Shutdown")] -#[usage("")] +#[description("Shuts down the bot with the specified exit code")] +#[min_args(0)] +#[max_args(1)] +#[usage("()")] #[owners_only] -async fn shutdown(ctx: &Context, msg: &Message) -> CommandResult { - log::info!("Shutting down..."); +async fn shutdown(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { + let code = args.single::().unwrap_or(0); + log::info!("Shutting down with code {}...", code); msg.channel_id - .say(ctx, ":night_with_stars: Good night ....") + .say( + ctx, + format!(":night_with_stars: Good night (code: {})...", code), + ) .await?; handle_autodelete(ctx, msg).await?; - process::exit(0); + process::exit(code); }