From 869350843547fab3ea7898bc8f8e8764f3d47194 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 15 Dec 2023 12:05:55 +0100 Subject: [PATCH] allow start/stop/run_command to only be used in the info channel (-> info channel permissions control who has MC admin) --- mcdcbot/src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mcdcbot/src/main.rs b/mcdcbot/src/main.rs index a7f6886..1dab92d 100755 --- a/mcdcbot/src/main.rs +++ b/mcdcbot/src/main.rs @@ -41,6 +41,13 @@ async fn start( ctx: Context<'_>, #[description = "Server's name (see /list)"] srv: String, ) -> Result<(), Error> { + { + let cid = ctx.data().settings.lock().await.channel_id_info; + if ctx.channel_id() != cid { + ctx.say(format!("This command can only be used in <#{cid}>.",)) + .await?; + } + } // find server by name let servers_lock = ctx.data().servers.lock().await; let mut matching_server = None; @@ -111,6 +118,13 @@ async fn start( } #[poise::command(slash_command)] async fn stop(ctx: Context<'_>) -> Result<(), Error> { + { + let cid = ctx.data().settings.lock().await.channel_id_info; + if ctx.channel_id() != cid { + ctx.say(format!("This command can only be used in <#{cid}>.",)) + .await?; + } + } let current_lock = ctx.data().current.lock().await; if let Some((_, thread)) = current_lock.as_ref() { _ = thread @@ -132,6 +146,13 @@ async fn run_command( ctx: Context<'_>, #[description = "command (without '/')"] cmd: String, ) -> Result<(), Error> { + { + let cid = ctx.data().settings.lock().await.channel_id_info; + if ctx.channel_id() != cid { + ctx.say(format!("This command can only be used in <#{cid}>.",)) + .await?; + } + } let current_lock = ctx.data().current.lock().await; if let Some((_, thread)) = current_lock.as_ref() { ctx.say(format!("Running '{cmd}'")).await?;