aboutsummaryrefslogtreecommitdiffstats
path: root/src/commands
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-04 01:09:10 +0100
committersalmonik <salmonik@tuta.io>2026-11-04 01:09:10 +0100
commitceb96326ccf3daff0472cafdaba3e223d3a20724 (patch)
tree8bd84f484ce714bd10f1c9f25f612ab16fbd8eae /src/commands
parentcron: scope jobs to the guild that created them (diff)
downloadsenator-sperma-ceb96326ccf3daff0472cafdaba3e223d3a20724.tar.gz
senator-sperma-ceb96326ccf3daff0472cafdaba3e223d3a20724.zip
triggers: scope groups to the guild that created them
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/autocomplete.rs5
-rw-r--r--src/commands/trigger.rs17
2 files changed, 15 insertions, 7 deletions
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<serenity::Autocomp
208} 208}
209 209
210pub async fn trigger_name(ctx: Context<'_>, partial: &str) -> Vec<String> { 210pub async fn trigger_name(ctx: Context<'_>, partial: &str) -> Vec<String> {
211 let Some(guild_id) = ctx.guild_id() else {
212 return Vec::new();
213 };
211 let db_pool = &ctx.data().db_pool; 214 let db_pool = &ctx.data().db_pool;
212 match crate::database::list_triggers(db_pool).await { 215 match crate::database::list_triggers(db_pool, guild_id.get() as i64).await {
213 Ok(triggers) => { 216 Ok(triggers) => {
214 let names: Vec<_> = triggers 217 let names: Vec<_> = triggers
215 .into_iter() 218 .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(
27 #[autocomplete = "trigger_name"] 27 #[autocomplete = "trigger_name"]
28 name: String, 28 name: String,
29) -> Result<()> { 29) -> Result<()> {
30 match database::create_trigger(&ctx.data().db_pool, &name).await { 30 let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?;
31 match database::create_trigger(&ctx.data().db_pool, guild_id.get() as i64, &name).await {
31 Ok(_) => { 32 Ok(_) => {
32 ctx.data().reload_triggers().await; 33 ctx.data().reload_triggers().await;
33 ctx.say(lang::fmt_trigger_created(&name)).await?; 34 ctx.say(lang::fmt_trigger_created(&name)).await?;
@@ -49,7 +50,8 @@ pub async fn add(
49 #[description = "Keywords separated by \\"] trigger_keywords: Option<String>, 50 #[description = "Keywords separated by \\"] trigger_keywords: Option<String>,
50 #[description = "Responses separated by \\"] response: Option<String>, 51 #[description = "Responses separated by \\"] response: Option<String>,
51) -> Result<()> { 52) -> Result<()> {
52 let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) 53 let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?;
54 let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name)
53 .await? 55 .await?
54 .ok_or_else(lang::err_trigger_not_found)?; 56 .ok_or_else(lang::err_trigger_not_found)?;
55 57
@@ -90,7 +92,8 @@ pub async fn remove(
90 #[description = "Keyword to remove"] trigger_keyword: Option<String>, 92 #[description = "Keyword to remove"] trigger_keyword: Option<String>,
91 #[description = "Response to remove"] response: Option<String>, 93 #[description = "Response to remove"] response: Option<String>,
92) -> Result<()> { 94) -> Result<()> {
93 let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) 95 let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?;
96 let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name)
94 .await? 97 .await?
95 .ok_or_else(lang::err_trigger_not_found)?; 98 .ok_or_else(lang::err_trigger_not_found)?;
96 99
@@ -119,11 +122,12 @@ pub async fn delete(
119 #[autocomplete = "trigger_name"] 122 #[autocomplete = "trigger_name"]
120 name: String, 123 name: String,
121) -> Result<()> { 124) -> Result<()> {
122 let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) 125 let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?;
126 let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name)
123 .await? 127 .await?
124 .ok_or_else(lang::err_trigger_not_found)?; 128 .ok_or_else(lang::err_trigger_not_found)?;
125 129
126 database::delete_trigger(&ctx.data().db_pool, t.id).await?; 130 database::delete_trigger(&ctx.data().db_pool, t.id, guild_id.get() as i64).await?;
127 ctx.data().reload_triggers().await; 131 ctx.data().reload_triggers().await;
128 ctx.say(lang::fmt_trigger_deleted(&name)).await?; 132 ctx.say(lang::fmt_trigger_deleted(&name)).await?;
129 Ok(()) 133 Ok(())
@@ -137,7 +141,8 @@ pub async fn list(
137 #[autocomplete = "trigger_name"] 141 #[autocomplete = "trigger_name"]
138 name: String, 142 name: String,
139) -> Result<()> { 143) -> Result<()> {
140 let t = database::get_trigger_by_name(&ctx.data().db_pool, &name) 144 let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?;
145 let t = database::get_trigger_by_name(&ctx.data().db_pool, guild_id.get() as i64, &name)
141 .await? 146 .await?
142 .ok_or_else(lang::err_trigger_not_found)?; 147 .ok_or_else(lang::err_trigger_not_found)?;
143 148