Skip to content

Commit

Permalink
Merge pull request #201 from marcelropos/shutdown_method
Browse files Browse the repository at this point in the history
added shutdown command
  • Loading branch information
maxwai authored Feb 18, 2024
2 parents 7f6ac29 + 2d41688 commit a0e2646
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 24 additions & 6 deletions src/bot/commands.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::time::SystemTime;

use poise::CreateReply;
use tracing::info;

use super::checks;
use crate::{
bot::{Context, Error},
logging, mysql_lib,
};
use std::time::SystemTime;
use poise::CreateReply;

use super::checks;

/// ping command
#[poise::command(slash_command, prefix_command)]
Expand All @@ -15,13 +17,14 @@ pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
let now = SystemTime::now();
let reply_message = ctx.say(response).await?;
reply_message
.edit(ctx, CreateReply::default()
.content(match now.elapsed() {
.edit(
ctx,
CreateReply::default().content(match now.elapsed() {
Ok(elapsed) => {
format!("Pong: {} ms", elapsed.as_millis())
}
Err(_) => "Pong: could not calculate time difference".to_owned(),
})
}),
)
.await?;
Ok(())
Expand Down Expand Up @@ -80,3 +83,18 @@ pub async fn logger_pipe(ctx: Context<'_>) -> Result<(), Error> {

Ok(())
}

/// bot shutdown command
#[poise::command(prefix_command, guild_only)]
pub async fn shutdown(ctx: Context<'_>) -> Result<(), Error> {
if !checks::is_bot_admin(ctx).await {
ctx.say("Missing permissions, requires bot admin permissions")
.await?;
return Ok(());
}

info!("Shutting down due to command");
ctx.framework().shard_manager.shutdown_all().await;

Ok(())
}
2 changes: 1 addition & 1 deletion src/bot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn entrypoint(database_pool: Pool<MySql>, redis_client: Client) {
let db_clone = database_pool.clone();
let framework = Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![commands::ping(), commands::logger_pipe()],
commands: vec![commands::ping(), commands::logger_pipe(), commands::shutdown()],
allowed_mentions: Some({
serenity::CreateAllowedMentions::default()
.replied_user(true)
Expand Down

0 comments on commit a0e2646

Please sign in to comment.