aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-04 01:08:08 +0100
committersalmonik <salmonik@tuta.io>2026-11-04 01:08:08 +0100
commit8e6fced543735aa4c68e70221518a37c36780d59 (patch)
tree7b7e6be03c3091caf2ae7bed12b40b6d6f1e71e5
parentutilities: sanitize filenames and isolate temp operations (diff)
downloadsenator-sperma-8e6fced543735aa4c68e70221518a37c36780d59.tar.gz
senator-sperma-8e6fced543735aa4c68e70221518a37c36780d59.zip
commands: gate admin, trigger, cron and recording behind permissions
-rw-r--r--src/commands/cron.rs14
-rw-r--r--src/commands/record.rs2
-rw-r--r--src/commands/trigger.rs14
-rw-r--r--src/commands/utilities.rs2
4 files changed, 18 insertions, 14 deletions
diff --git a/src/commands/cron.rs b/src/commands/cron.rs
index a645581..47c3d62 100644
--- a/src/commands/cron.rs
+++ b/src/commands/cron.rs
@@ -11,6 +11,8 @@ type Context<'a> = poise::Context<'a, Data, Error>;
11/// Cron job management 11/// Cron job management
12#[poise::command( 12#[poise::command(
13 slash_command, 13 slash_command,
14 guild_only,
15 required_permissions = "MANAGE_GUILD",
14 subcommands("dodaj_audio", "dodaj_wiadomość", "pokaż", "usuń", "pauza", "wznów",) 16 subcommands("dodaj_audio", "dodaj_wiadomość", "pokaż", "usuń", "pauza", "wznów",)
15)] 17)]
16pub async fn cron(_ctx: Context<'_>) -> Result<()> { 18pub async fn cron(_ctx: Context<'_>) -> Result<()> {
@@ -18,7 +20,7 @@ pub async fn cron(_ctx: Context<'_>) -> Result<()> {
18} 20}
19 21
20/// Schedule audio playback 22/// Schedule audio playback
21#[poise::command(slash_command)] 23#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
22pub async fn dodaj_audio( 24pub async fn dodaj_audio(
23 ctx: Context<'_>, 25 ctx: Context<'_>,
24 #[description = "Cron expression (e.g. \"37 21 * * *\" = every day at 21:37)"] cron_expression: String, 26 #[description = "Cron expression (e.g. \"37 21 * * *\" = every day at 21:37)"] cron_expression: String,
@@ -58,7 +60,7 @@ pub async fn dodaj_audio(
58} 60}
59 61
60/// Schedule a periodic message 62/// Schedule a periodic message
61#[poise::command(slash_command)] 63#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
62pub async fn dodaj_wiadomość( 64pub async fn dodaj_wiadomość(
63 ctx: Context<'_>, 65 ctx: Context<'_>,
64 #[description = "Cron expression (e.g. \"37 21 * * *\" = every day at 21:37)"] cron_expression: String, 66 #[description = "Cron expression (e.g. \"37 21 * * *\" = every day at 21:37)"] cron_expression: String,
@@ -85,7 +87,7 @@ pub async fn dodaj_wiadomość(
85} 87}
86 88
87/// List all cron jobs 89/// List all cron jobs
88#[poise::command(slash_command)] 90#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
89pub async fn pokaż(ctx: Context<'_>) -> Result<()> { 91pub async fn pokaż(ctx: Context<'_>) -> Result<()> {
90 let jobs = database::list_cron_jobs(&ctx.data().db_pool).await?; 92 let jobs = database::list_cron_jobs(&ctx.data().db_pool).await?;
91 if jobs.is_empty() { 93 if jobs.is_empty() {
@@ -119,7 +121,7 @@ pub async fn pokaż(ctx: Context<'_>) -> Result<()> {
119} 121}
120 122
121/// Remove a cron job 123/// Remove a cron job
122#[poise::command(slash_command)] 124#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
123pub async fn usuń( 125pub async fn usuń(
124 ctx: Context<'_>, 126 ctx: Context<'_>,
125 #[description = "ID pracy do usunięcia"] job_id: i64, 127 #[description = "ID pracy do usunięcia"] job_id: i64,
@@ -133,7 +135,7 @@ pub async fn usuń(
133} 135}
134 136
135/// Pause a cron job 137/// Pause a cron job
136#[poise::command(slash_command)] 138#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
137pub async fn pauza( 139pub async fn pauza(
138 ctx: Context<'_>, 140 ctx: Context<'_>,
139 #[description = "ID pracy do zapauzowania"] job_id: i64, 141 #[description = "ID pracy do zapauzowania"] job_id: i64,
@@ -147,7 +149,7 @@ pub async fn pauza(
147} 149}
148 150
149/// Resume a paused cron job 151/// Resume a paused cron job
150#[poise::command(slash_command)] 152#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
151pub async fn wznów( 153pub async fn wznów(
152 ctx: Context<'_>, 154 ctx: Context<'_>,
153 #[description = "ID pracy cron do wznowienia"] job_id: i64, 155 #[description = "ID pracy cron do wznowienia"] job_id: i64,
diff --git a/src/commands/record.rs b/src/commands/record.rs
index 6f2cfcd..48cbc59 100644
--- a/src/commands/record.rs
+++ b/src/commands/record.rs
@@ -12,7 +12,7 @@ type Context<'a> = poise::Context<'a, crate::Data, crate::error::Error>;
12/// connected to a voice channel, if `RECORDING_ENABLED=true`. This command is a 12/// connected to a voice channel, if `RECORDING_ENABLED=true`. This command is a
13/// read-only snapshot — the buffer keeps recording afterwards. Only callable by 13/// read-only snapshot — the buffer keeps recording afterwards. Only callable by
14/// someone in the same voice channel as the bot. 14/// someone in the same voice channel as the bot.
15#[poise::command(slash_command)] 15#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
16pub async fn record(ctx: Context<'_>) -> Result<()> { 16pub async fn record(ctx: Context<'_>) -> Result<()> {
17 ctx.defer().await?; 17 ctx.defer().await?;
18 let data = ctx.data(); 18 let data = ctx.data();
diff --git a/src/commands/trigger.rs b/src/commands/trigger.rs
index 2a33528..3a91edd 100644
--- a/src/commands/trigger.rs
+++ b/src/commands/trigger.rs
@@ -11,6 +11,8 @@ type Context<'a> = poise::Context<'a, Data, Error>;
11/// Trigger keyword management 11/// Trigger keyword management
12#[poise::command( 12#[poise::command(
13 slash_command, 13 slash_command,
14 guild_only,
15 required_permissions = "MANAGE_GUILD",
14 subcommands("create", "add", "remove", "delete", "list", "help",) 16 subcommands("create", "add", "remove", "delete", "list", "help",)
15)] 17)]
16pub async fn trigger(_ctx: Context<'_>) -> Result<()> { 18pub async fn trigger(_ctx: Context<'_>) -> Result<()> {
@@ -18,7 +20,7 @@ pub async fn trigger(_ctx: Context<'_>) -> Result<()> {
18} 20}
19 21
20/// Create a new trigger group 22/// Create a new trigger group
21#[poise::command(slash_command)] 23#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
22pub async fn create( 24pub async fn create(
23 ctx: Context<'_>, 25 ctx: Context<'_>,
24 #[description = "Logical group name"] 26 #[description = "Logical group name"]
@@ -38,7 +40,7 @@ pub async fn create(
38} 40}
39 41
40/// Add keywords and/or responses to a trigger group 42/// Add keywords and/or responses to a trigger group
41#[poise::command(slash_command)] 43#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
42pub async fn add( 44pub async fn add(
43 ctx: Context<'_>, 45 ctx: Context<'_>,
44 #[description = "Existing group name"] 46 #[description = "Existing group name"]
@@ -79,7 +81,7 @@ pub async fn add(
79} 81}
80 82
81/// Remove keyword or response from a group 83/// Remove keyword or response from a group
82#[poise::command(slash_command)] 84#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
83pub async fn remove( 85pub async fn remove(
84 ctx: Context<'_>, 86 ctx: Context<'_>,
85 #[description = "Group name"] 87 #[description = "Group name"]
@@ -110,7 +112,7 @@ pub async fn remove(
110} 112}
111 113
112/// Delete an entire trigger group 114/// Delete an entire trigger group
113#[poise::command(slash_command)] 115#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
114pub async fn delete( 116pub async fn delete(
115 ctx: Context<'_>, 117 ctx: Context<'_>,
116 #[description = "Group name"] 118 #[description = "Group name"]
@@ -128,7 +130,7 @@ pub async fn delete(
128} 130}
129 131
130/// List keywords and responses for a group 132/// List keywords and responses for a group
131#[poise::command(slash_command)] 133#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
132pub async fn list( 134pub async fn list(
133 ctx: Context<'_>, 135 ctx: Context<'_>,
134 #[description = "Group name"] 136 #[description = "Group name"]
@@ -178,7 +180,7 @@ pub async fn list(
178} 180}
179 181
180/// Display trigger command usage info 182/// Display trigger command usage info
181#[poise::command(slash_command)] 183#[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")]
182pub async fn help(ctx: Context<'_>) -> Result<()> { 184pub async fn help(ctx: Context<'_>) -> Result<()> {
183 let help = [ 185 let help = [
184 "**Trigger Commands**", 186 "**Trigger Commands**",
diff --git a/src/commands/utilities.rs b/src/commands/utilities.rs
index 2179ce9..bf93491 100644
--- a/src/commands/utilities.rs
+++ b/src/commands/utilities.rs
@@ -1016,7 +1016,7 @@ pub async fn message_download(ctx: Context<'_>, message: serenity::Message) -> R
1016} 1016}
1017 1017
1018/// Echo text to channel 1018/// Echo text to channel
1019#[poise::command(slash_command)] 1019#[poise::command(slash_command, required_permissions = "MANAGE_MESSAGES")]
1020pub async fn say(ctx: Context<'_>, #[description = "Message to send"] text: String) -> Result<()> { 1020pub async fn say(ctx: Context<'_>, #[description = "Message to send"] text: String) -> Result<()> {
1021 // Acknowledge the interaction with an invisible ephemeral reply, delete it, 1021 // Acknowledge the interaction with an invisible ephemeral reply, delete it,
1022 // then post the actual text as a normal channel message (not a reply to the 1022 // then post the actual text as a normal channel message (not a reply to the