diff --git a/libs/bot/src/trivia/config.rs b/libs/bot/src/trivia/config.rs index 6816e6a..b23295a 100644 --- a/libs/bot/src/trivia/config.rs +++ b/libs/bot/src/trivia/config.rs @@ -1,7 +1,6 @@ use crate::helper::is_user_admin_right; use crate::{Context, Error}; use clickhouse_pool::traits::Model; -use croner::Cron; use database::trivial::{Trivial, TrivialRewardKind}; use poise::serenity_prelude::{Channel, Role}; use tracing::{debug, info, instrument}; @@ -27,10 +26,6 @@ pub async fn config( #[description = "Reward amount for the trivia game"] reward_amount: Option, #[description = "Whether to send an ephemeral message when the answer is taken into account"] taken_into_account: Option, - #[description = "When to ask the question, in cron format (e.g. '0 0 * * *' for daily)"] - cron: Option, - #[description = "When to answer the question, in cron format (e.g. '0 0 * * *' for daily)"] - cron_answer: Option, ) -> Result<(), Error> { let guild_id = match ctx.guild_id() { Some(id) => id.get(), @@ -116,27 +111,6 @@ pub async fn config( if let Some(taken_into_account) = taken_into_account { trivia_exists.taken_into_account = taken_into_account; } - if let Some(cron) = cron { - match Cron::new(&cron).parse() { - Ok(_) => {} - Err(e) => { - ctx.say(format!("Invalid cron format: {}", e)).await?; - return Ok(()); - } - }; - trivia_exists.question_asked = cron; - } - if let Some(cron_answer) = cron_answer { - match Cron::new(&cron_answer).parse() { - Ok(_) => {} - Err(e) => { - ctx.say(format!("Invalid cron answer format: {}", e)) - .await?; - return Ok(()); - } - }; - trivia_exists.answer_given = cron_answer; - } trivia_exists.updated_at = chrono::Utc::now(); trivia_exists.updater_id = ctx.author().id.get(); debug!("Updated trivia game: {:?}", trivia_exists); diff --git a/libs/bot/src/trivia/status.rs b/libs/bot/src/trivia/status.rs index 7b0c9a1..01f865a 100644 --- a/libs/bot/src/trivia/status.rs +++ b/libs/bot/src/trivia/status.rs @@ -1,6 +1,7 @@ use crate::helper::is_user_admin_right; use crate::{Context, Error}; use clickhouse_pool::traits::Model; +use croner::Cron; use database::trivial::{Trivial, TrivialStatus}; use poise::serenity_prelude::Channel; use tracing::{debug, info, instrument}; @@ -18,6 +19,10 @@ pub async fn status( ctx: Context<'_>, #[description = "Channel of the trivia game, or current"] channel_id: Option, #[description = "Whether to start/stop the trivia game"] enabled: Option, + #[description = "When to ask the question, in cron format (e.g. '0 0 * * *' for daily)"] + cron: Option, + #[description = "When to answer the question, in cron format (e.g. '0 0 * * *' for daily)"] + cron_answer: Option, ) -> Result<(), Error> { let guild_id = match ctx.guild_id() { Some(id) => id.get(), @@ -83,6 +88,27 @@ pub async fn status( } else { TrivialStatus::Paused }; + if let Some(cron) = cron { + match Cron::new(&cron).parse() { + Ok(_) => {} + Err(e) => { + ctx.say(format!("Invalid cron format: {}", e)).await?; + return Ok(()); + } + }; + trivia_exists.question_asked = cron; + } + if let Some(cron_answer) = cron_answer { + match Cron::new(&cron_answer).parse() { + Ok(_) => {} + Err(e) => { + ctx.say(format!("Invalid cron answer format: {}", e)) + .await?; + return Ok(()); + } + }; + trivia_exists.answer_given = cron_answer; + } trivia_exists.sign = 1; // Set sign to 1 to indicate a status change inserter.write(&trivia_exists.clone()).await?; match inserter.end().await {