From ceb96326ccf3daff0472cafdaba3e223d3a20724 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 01:09:10 +0100 Subject: triggers: scope groups to the guild that created them --- src/commands/autocomplete.rs | 5 ++++- src/commands/trigger.rs | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src/commands') diff --git a/src/commands/autocomplete.rs b/src/commands/autocomplete.rs index a909738..d05a48b 100644 --- a/src/commands/autocomplete.rs +++ b/src/commands/autocomplete.rs @@ -208,8 +208,11 @@ pub async fn any_file(ctx: Context<'_>, partial: &str) -> Vec, partial: &str) -> Vec { + let Some(guild_id) = ctx.guild_id() else { + return Vec::new(); + }; let db_pool = &ctx.data().db_pool; - match crate::database::list_triggers(db_pool).await { + match crate::database::list_triggers(db_pool, guild_id.get() as i64).await { Ok(triggers) => { let names: Vec<_> = triggers .into_iter() diff --git a/src/commands/trigger.rs b/src/commands/trigger.rs index 3a91edd..5d481e4 100644 --- a/src/commands/trigger.rs +++ b/src/commands/trigger.rs @@ -27,7 +27,8 @@ pub async fn create( #[autocomplete = "trigger_name"] name: String, ) -> Result<()> { - match database::create_trigger(&ctx.data().db_pool, &name).await { + let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; + match database::create_trigger(&ctx.data().db_pool, guild_id.get() as i64, &name).await { Ok(_) => { ctx.data().reload_triggers().await; ctx.say(lang::fmt_trigger_created(&name)).await?; @@ -49,7 +50,8 @@ pub async fn add( #[description = "Keywords separated by \\"] trigger_keywords: Option, #[description = "Responses separated by \\"] response: Option, ) -> Result<()> { - let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) + let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; + let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name) .await? .ok_or_else(lang::err_trigger_not_found)?; @@ -90,7 +92,8 @@ pub async fn remove( #[description = "Keyword to remove"] trigger_keyword: Option, #[description = "Response to remove"] response: Option, ) -> Result<()> { - let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) + let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; + let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name) .await? .ok_or_else(lang::err_trigger_not_found)?; @@ -119,11 +122,12 @@ pub async fn delete( #[autocomplete = "trigger_name"] name: String, ) -> Result<()> { - let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) + let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; + let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name) .await? .ok_or_else(lang::err_trigger_not_found)?; - database::delete_trigger(&ctx.data().db_pool, t.id).await?; + database::delete_trigger(&ctx.data().db_pool, t.id, guild_id.get() as i64).await?; ctx.data().reload_triggers().await; ctx.say(lang::fmt_trigger_deleted(&name)).await?; Ok(()) @@ -137,7 +141,8 @@ pub async fn list( #[autocomplete = "trigger_name"] name: String, ) -> Result<()> { - let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) + let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; + let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name) .await? .ok_or_else(lang::err_trigger_not_found)?; -- cgit v1.2.3