add a way to run mc commands from discord

This commit is contained in:
Mark 2023-11-23 21:01:29 +01:00
parent 2fe29d15cc
commit b5c31fd589

View File

@ -127,6 +127,27 @@ async fn stop(ctx: Context<'_>) -> Result<(), Error> {
} }
Ok(()) Ok(())
} }
#[poise::command(slash_command)]
async fn run_command(
ctx: Context<'_>,
#[description = "command (without '/')"] cmd: String,
) -> Result<(), Error> {
let current_lock = ctx.data().current.lock().await;
if let Some((_, thread)) = current_lock.as_ref() {
ctx.say(format!("Running '{cmd}'")).await?;
_ = thread
.lock()
.await
.as_ref()
.unwrap()
.clone_task_sender()
.send_task(MinecraftServerTask::RunCommand(cmd));
} else {
ctx.say(format!("Use /start to start a server first"))
.await?;
}
Ok(())
}
async fn event_handler( async fn event_handler(
ctx: &serenity::Context, ctx: &serenity::Context,