diff options
Diffstat (limited to 'src/commands/cron.rs')
| -rw-r--r-- | src/commands/cron.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/commands/cron.rs b/src/commands/cron.rs index 47c3d62..ebaa96d 100644 --- a/src/commands/cron.rs +++ b/src/commands/cron.rs | |||
| @@ -44,8 +44,10 @@ pub async fn dodaj_audio( | |||
| 44 | ctx.data().copyparty.build_url_no_pw(&audio_filename) | 44 | ctx.data().copyparty.build_url_no_pw(&audio_filename) |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
| 47 | let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; | ||
| 47 | database::add_cron_job( | 48 | database::add_cron_job( |
| 48 | &ctx.data().db_pool, | 49 | &ctx.data().db_pool, |
| 50 | guild_id.get() as i64, | ||
| 49 | &cron_expression, | 51 | &cron_expression, |
| 50 | "audio", | 52 | "audio", |
| 51 | channel_id, | 53 | channel_id, |
| @@ -72,8 +74,10 @@ pub async fn dodaj_wiadomość( | |||
| 72 | _ => return Err(lang::err_bad_channel_type()), | 74 | _ => return Err(lang::err_bad_channel_type()), |
| 73 | }; | 75 | }; |
| 74 | 76 | ||
| 77 | let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; | ||
| 75 | database::add_cron_job( | 78 | database::add_cron_job( |
| 76 | &ctx.data().db_pool, | 79 | &ctx.data().db_pool, |
| 80 | guild_id.get() as i64, | ||
| 77 | &cron_expression, | 81 | &cron_expression, |
| 78 | "wiadomość", | 82 | "wiadomość", |
| 79 | channel_id, | 83 | channel_id, |
| @@ -89,7 +93,8 @@ pub async fn dodaj_wiadomość( | |||
| 89 | /// List all cron jobs | 93 | /// List all cron jobs |
| 90 | #[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] | 94 | #[poise::command(slash_command, guild_only, required_permissions = "MANAGE_GUILD")] |
| 91 | pub async fn pokaż(ctx: Context<'_>) -> Result<()> { | 95 | pub async fn pokaż(ctx: Context<'_>) -> Result<()> { |
| 92 | let jobs = database::list_cron_jobs(&ctx.data().db_pool).await?; | 96 | let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; |
| 97 | let jobs = database::list_cron_jobs(&ctx.data().db_pool, guild_id.get() as i64).await?; | ||
| 93 | if jobs.is_empty() { | 98 | if jobs.is_empty() { |
| 94 | ctx.say(lang::L_CRON_NONE).await?; | 99 | ctx.say(lang::L_CRON_NONE).await?; |
| 95 | return Ok(()); | 100 | return Ok(()); |
| @@ -126,7 +131,8 @@ pub async fn usuń( | |||
| 126 | ctx: Context<'_>, | 131 | ctx: Context<'_>, |
| 127 | #[description = "ID pracy do usunięcia"] job_id: i64, | 132 | #[description = "ID pracy do usunięcia"] job_id: i64, |
| 128 | ) -> Result<()> { | 133 | ) -> Result<()> { |
| 129 | if database::delete_cron_job(&ctx.data().db_pool, job_id).await? { | 134 | let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; |
| 135 | if database::delete_cron_job(&ctx.data().db_pool, job_id, guild_id.get() as i64).await? { | ||
| 130 | ctx.say(lang::fmt_cron_deleted(job_id)).await?; | 136 | ctx.say(lang::fmt_cron_deleted(job_id)).await?; |
| 131 | } else { | 137 | } else { |
| 132 | ctx.say(lang::fmt_cron_not_found(job_id)).await?; | 138 | ctx.say(lang::fmt_cron_not_found(job_id)).await?; |
| @@ -140,7 +146,8 @@ pub async fn pauza( | |||
| 140 | ctx: Context<'_>, | 146 | ctx: Context<'_>, |
| 141 | #[description = "ID pracy do zapauzowania"] job_id: i64, | 147 | #[description = "ID pracy do zapauzowania"] job_id: i64, |
| 142 | ) -> Result<()> { | 148 | ) -> Result<()> { |
| 143 | if database::set_cron_job_active(&ctx.data().db_pool, job_id, false).await? { | 149 | let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; |
| 150 | if database::set_cron_job_active(&ctx.data().db_pool, job_id, guild_id.get() as i64, false).await? { | ||
| 144 | ctx.say(lang::fmt_cron_paused(job_id)).await?; | 151 | ctx.say(lang::fmt_cron_paused(job_id)).await?; |
| 145 | } else { | 152 | } else { |
| 146 | ctx.say(lang::fmt_cron_not_found(job_id)).await?; | 153 | ctx.say(lang::fmt_cron_not_found(job_id)).await?; |
| @@ -154,7 +161,8 @@ pub async fn wznów( | |||
| 154 | ctx: Context<'_>, | 161 | ctx: Context<'_>, |
| 155 | #[description = "ID pracy cron do wznowienia"] job_id: i64, | 162 | #[description = "ID pracy cron do wznowienia"] job_id: i64, |
| 156 | ) -> Result<()> { | 163 | ) -> Result<()> { |
| 157 | if database::set_cron_job_active(&ctx.data().db_pool, job_id, true).await? { | 164 | let guild_id = ctx.guild_id().ok_or_else(lang::err_not_in_guild)?; |
| 165 | if database::set_cron_job_active(&ctx.data().db_pool, job_id, guild_id.get() as i64, true).await? { | ||
| 158 | ctx.say(lang::fmt_cron_resumed(job_id)).await?; | 166 | ctx.say(lang::fmt_cron_resumed(job_id)).await?; |
| 159 | } else { | 167 | } else { |
| 160 | ctx.say(lang::fmt_cron_not_found(job_id)).await?; | 168 | ctx.say(lang::fmt_cron_not_found(job_id)).await?; |
