Add optional code argument to shutdown command
Signed-off-by: trivernis <trivernis@protonmail.com>pull/3/head
parent
a7045ebe5a
commit
e11ff3f72f
@ -1,19 +1,25 @@
|
|||||||
use crate::commands::common::handle_autodelete;
|
use crate::commands::common::handle_autodelete;
|
||||||
use serenity::framework::standard::macros::command;
|
use serenity::framework::standard::macros::command;
|
||||||
use serenity::framework::standard::CommandResult;
|
use serenity::framework::standard::{Args, CommandResult};
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
#[description("Shutdown")]
|
#[description("Shuts down the bot with the specified exit code")]
|
||||||
#[usage("")]
|
#[min_args(0)]
|
||||||
|
#[max_args(1)]
|
||||||
|
#[usage("(<code>)")]
|
||||||
#[owners_only]
|
#[owners_only]
|
||||||
async fn shutdown(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn shutdown(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
log::info!("Shutting down...");
|
let code = args.single::<i32>().unwrap_or(0);
|
||||||
|
log::info!("Shutting down with code {}...", code);
|
||||||
msg.channel_id
|
msg.channel_id
|
||||||
.say(ctx, ":night_with_stars: Good night ....")
|
.say(
|
||||||
|
ctx,
|
||||||
|
format!(":night_with_stars: Good night (code: {})...", code),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
handle_autodelete(ctx, msg).await?;
|
handle_autodelete(ctx, msg).await?;
|
||||||
process::exit(0);
|
process::exit(code);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue