From f471d4caefff51d49b69551412f4859d99f674a2 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 6 Nov 2026 21:34:53 +0100 Subject: revert required permissions Signed-off-by: salmonik --- src/commands/cron.rs | 21 +++++++++------- src/commands/record.rs | 2 +- src/commands/trigger.rs | 12 ++++----- src/commands/utilities.rs | 62 +++++++++++++++++++++++++++++------------------ 4 files changed, 58 insertions(+), 39 deletions(-) (limited to 'src/commands') diff --git a/src/commands/cron.rs b/src/commands/cron.rs index ec5b702..809d1a4 100644 --- a/src/commands/cron.rs +++ b/src/commands/cron.rs @@ -12,7 +12,6 @@ type Context<'a> = poise::Context<'a, Data, Error>; #[poise::command( slash_command, guild_only, - required_permissions = "MANAGE_GUILD", subcommands("dodaj_audio", "dodaj_wiadomość", "pokaż", "usuń", "pauza", "wznów",) )] pub async fn cron(_ctx: Context<'_>) -> Result<()> { @@ -20,7 +19,7 @@ pub async fn cron(_ctx: Context<'_>) -> Result<()> { } /// Schedule audio playback -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn dodaj_audio( ctx: Context<'_>, #[description = "Cron expression (e.g. \"37 21 * * *\" = every day at 21:37)"] cron_expression: String, @@ -75,7 +74,7 @@ pub async fn dodaj_audio( } /// Schedule a periodic message -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn dodaj_wiadomość( ctx: Context<'_>, #[description = "Cron expression (e.g. \"37 21 * * *\" = every day at 21:37)"] cron_expression: String, @@ -109,7 +108,7 @@ pub async fn dodaj_wiadomość( } /// List all cron jobs -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn pokaż(ctx: Context<'_>) -> Result<()> { let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; let jobs = database::list_cron_jobs(&ctx.data().db_pool, guild_id.get() as i64).await?; @@ -144,7 +143,7 @@ pub async fn pokaż(ctx: Context<'_>) -> Result<()> { } /// Remove a cron job -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn usuń( ctx: Context<'_>, #[description = "ID pracy do usunięcia"] job_id: i64, @@ -159,13 +158,15 @@ pub async fn usuń( } /// Pause a cron job -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn pauza( ctx: Context<'_>, #[description = "ID pracy do zapauzowania"] job_id: i64, ) -> Result<()> { let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; - if database::set_cron_job_active(&ctx.data().db_pool, job_id, guild_id.get() as i64, false).await? { + if database::set_cron_job_active(&ctx.data().db_pool, job_id, guild_id.get() as i64, false) + .await? + { ctx.say(lang::fmt_cron_paused(job_id)).await?; } else { ctx.say(lang::fmt_cron_not_found(job_id)).await?; @@ -174,13 +175,15 @@ pub async fn pauza( } /// Resume a paused cron job -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn wznów( ctx: Context<'_>, #[description = "ID pracy cron do wznowienia"] job_id: i64, ) -> Result<()> { let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; - if database::set_cron_job_active(&ctx.data().db_pool, job_id, guild_id.get() as i64, true).await? { + if database::set_cron_job_active(&ctx.data().db_pool, job_id, guild_id.get() as i64, true) + .await? + { ctx.say(lang::fmt_cron_resumed(job_id)).await?; } else { ctx.say(lang::fmt_cron_not_found(job_id)).await?; diff --git a/src/commands/record.rs b/src/commands/record.rs index dfe736d..c5cecd3 100644 --- a/src/commands/record.rs +++ b/src/commands/record.rs @@ -13,7 +13,7 @@ type Context<'a> = poise::Context<'a, crate::Data, crate::error::Error>; /// connected to a voice channel, if `RECORDING_ENABLED=true`. This command is a /// read-only snapshot — the buffer keeps recording afterwards. Only callable by /// someone in the same voice channel as the bot. -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn record(ctx: Context<'_>) -> Result<()> { ctx.defer().await?; let data = ctx.data(); diff --git a/src/commands/trigger.rs b/src/commands/trigger.rs index 5d481e4..01fda18 100644 --- a/src/commands/trigger.rs +++ b/src/commands/trigger.rs @@ -20,7 +20,7 @@ pub async fn trigger(_ctx: Context<'_>) -> Result<()> { } /// Create a new trigger group -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn create( ctx: Context<'_>, #[description = "Logical group name"] @@ -41,7 +41,7 @@ pub async fn create( } /// Add keywords and/or responses to a trigger group -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn add( ctx: Context<'_>, #[description = "Existing group name"] @@ -83,7 +83,7 @@ pub async fn add( } /// Remove keyword or response from a group -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn remove( ctx: Context<'_>, #[description = "Group name"] @@ -115,7 +115,7 @@ pub async fn remove( } /// Delete an entire trigger group -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn delete( ctx: Context<'_>, #[description = "Group name"] @@ -134,7 +134,7 @@ pub async fn delete( } /// List keywords and responses for a group -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn list( ctx: Context<'_>, #[description = "Group name"] @@ -185,7 +185,7 @@ pub async fn list( } /// Display trigger command usage info -#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] +#[poise::command(slash_command, guild_only)] pub async fn help(ctx: Context<'_>) -> Result<()> { let help = [ "**Trigger Commands**", diff --git a/src/commands/utilities.rs b/src/commands/utilities.rs index f43b30e..f585d83 100644 --- a/src/commands/utilities.rs +++ b/src/commands/utilities.rs @@ -4,11 +4,11 @@ use poise::serenity_prelude as serenity; use tracing::warn; use super::autocomplete::any_file; -use crate::music::sanitize_yt_url; use crate::Data; use crate::copyparty::{html_decode, percent_decode, redact_url}; use crate::error::{Error, Result}; use crate::lang; +use crate::music::sanitize_yt_url; type Context<'a> = poise::Context<'a, Data, Error>; @@ -90,19 +90,12 @@ fn safe_basename(name: &str) -> String { /// Create a unique per-operation directory and return /// `(directory, input_path, output_path)`. Concurrent commands can never /// overwrite or delete each other's files. -async fn temp_op( - original: &str, - output_name: &str, -) -> std::io::Result<(String, String, String)> { +async fn temp_op(original: &str, output_name: &str) -> std::io::Result<(String, String, String)> { let safe = safe_basename(original); let ext = ext_of(&safe) .map(|ext| format!(".{ext}")) .unwrap_or_default(); - let dir = format!( - "{}/op_{}", - crate::config::temp_path(), - uuid::Uuid::new_v4() - ); + let dir = format!("{}/op_{}", crate::config::temp_path(), uuid::Uuid::new_v4()); tokio::fs::create_dir_all(&dir).await?; let input_path = format!("{dir}/input{ext}"); let output_path = format!("{dir}/{}", safe_basename(output_name)); @@ -303,7 +296,10 @@ async fn compress_attachment_bytes( /// Compress audio bytes for playback using Vorbis (symphonia-decodable). /// Uses Vorbis instead of Opus because symphonia 0.6 lacks an Opus decoder. /// Returns the compressed .ogg bytes on success. -pub(crate) async fn compress_audio_bytes(input_bytes: &[u8], original_name: &str) -> Option> { +pub(crate) async fn compress_audio_bytes( + input_bytes: &[u8], + original_name: &str, +) -> Option> { let safe_name = safe_basename(original_name); let stem = stem_of(&safe_name).to_string(); let out_filename = format!("compressed_{stem}.ogg"); @@ -378,9 +374,28 @@ pub(crate) fn extract_urls(content: &str) -> Vec { b.is_ascii_alphanumeric() || matches!( b, - b'-' | b'.' | b'_' | b'~' | b':' | b'/' | b'?' | b'#' | b'[' | b']' | b'@' - | b'!' | b'$' | b'&' | b'\'' | b'(' | b')' | b'*' | b'+' | b',' | b';' - | b'%' | b'=' + b'-' | b'.' + | b'_' + | b'~' + | b':' + | b'/' + | b'?' + | b'#' + | b'[' + | b']' + | b'@' + | b'!' + | b'$' + | b'&' + | b'\'' + | b'(' + | b')' + | b'*' + | b'+' + | b',' + | b';' + | b'%' + | b'=' ) } let bytes = content.as_bytes(); @@ -445,9 +460,10 @@ async fn find_downloaded_file(dir: &str) -> Option<(String, String)> { Err(_) => continue, }; if let Some((t, _)) = &newest - && *t >= mtime { - continue; - } + && *t >= mtime + { + continue; + } newest = Some((mtime, entry.path().to_string_lossy().into_owned())); } newest.map(|(_, p)| { @@ -540,8 +556,10 @@ async fn run_download( Ok(result) => result.map_err(|e| Error::Custom(lang::fmt_ytdlp_err(&e)))?, Err(_) => { let _ = tokio::fs::remove_dir_all(&dl_dir).await; - ctx.say(lang::fmt_download_failed("download timed out after 10 minutes")) - .await?; + ctx.say(lang::fmt_download_failed( + "download timed out after 10 minutes", + )) + .await?; return Ok(()); } }; @@ -1043,7 +1061,7 @@ pub async fn message_download(ctx: Context<'_>, message: serenity::Message) -> R } /// Echo text to channel -#[poise::command(slash_command, required_permissions = "MANAGE_MESSAGES")] +#[poise::command(slash_command)] pub async fn say(ctx: Context<'_>, #[description = "Message to send"] text: String) -> Result<()> { // Acknowledge the interaction with an invisible ephemeral reply, delete it, // then post the actual text as a normal channel message (not a reply to the @@ -1059,9 +1077,7 @@ pub async fn say(ctx: Context<'_>, #[description = "Message to send"] text: Stri warn!("say: failed to delete ephemeral acknowledgement: {e}"); } - ctx.channel_id() - .say(ctx.serenity_context(), &text) - .await?; + ctx.channel_id().say(ctx.serenity_context(), &text).await?; Ok(()) } -- cgit v1.2.3