feat: move Cron to status

This commit is contained in:
Max batleforc 2025-06-03 23:26:55 +02:00
parent 6d7d4a6b4f
commit 8600ecf7ee
No known key found for this signature in database
GPG Key ID: 25D243AB4B6AC9E7
2 changed files with 26 additions and 26 deletions

View File

@ -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<u64>,
#[description = "Whether to send an ephemeral message when the answer is taken into account"]
taken_into_account: Option<bool>,
#[description = "When to ask the question, in cron format (e.g. '0 0 * * *' for daily)"]
cron: Option<String>,
#[description = "When to answer the question, in cron format (e.g. '0 0 * * *' for daily)"]
cron_answer: Option<String>,
) -> 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);

View File

@ -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<Channel>,
#[description = "Whether to start/stop the trivia game"] enabled: Option<bool>,
#[description = "When to ask the question, in cron format (e.g. '0 0 * * *' for daily)"]
cron: Option<String>,
#[description = "When to answer the question, in cron format (e.g. '0 0 * * *' for daily)"]
cron_answer: Option<String>,
) -> 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 {