feat: move Cron to status
This commit is contained in:
parent
6d7d4a6b4f
commit
8600ecf7ee
@ -1,7 +1,6 @@
|
|||||||
use crate::helper::is_user_admin_right;
|
use crate::helper::is_user_admin_right;
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use clickhouse_pool::traits::Model;
|
use clickhouse_pool::traits::Model;
|
||||||
use croner::Cron;
|
|
||||||
use database::trivial::{Trivial, TrivialRewardKind};
|
use database::trivial::{Trivial, TrivialRewardKind};
|
||||||
use poise::serenity_prelude::{Channel, Role};
|
use poise::serenity_prelude::{Channel, Role};
|
||||||
use tracing::{debug, info, instrument};
|
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 = "Reward amount for the trivia game"] reward_amount: Option<u64>,
|
||||||
#[description = "Whether to send an ephemeral message when the answer is taken into account"]
|
#[description = "Whether to send an ephemeral message when the answer is taken into account"]
|
||||||
taken_into_account: Option<bool>,
|
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> {
|
) -> Result<(), Error> {
|
||||||
let guild_id = match ctx.guild_id() {
|
let guild_id = match ctx.guild_id() {
|
||||||
Some(id) => id.get(),
|
Some(id) => id.get(),
|
||||||
@ -116,27 +111,6 @@ pub async fn config(
|
|||||||
if let Some(taken_into_account) = taken_into_account {
|
if let Some(taken_into_account) = taken_into_account {
|
||||||
trivia_exists.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.updated_at = chrono::Utc::now();
|
||||||
trivia_exists.updater_id = ctx.author().id.get();
|
trivia_exists.updater_id = ctx.author().id.get();
|
||||||
debug!("Updated trivia game: {:?}", trivia_exists);
|
debug!("Updated trivia game: {:?}", trivia_exists);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::helper::is_user_admin_right;
|
use crate::helper::is_user_admin_right;
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use clickhouse_pool::traits::Model;
|
use clickhouse_pool::traits::Model;
|
||||||
|
use croner::Cron;
|
||||||
use database::trivial::{Trivial, TrivialStatus};
|
use database::trivial::{Trivial, TrivialStatus};
|
||||||
use poise::serenity_prelude::Channel;
|
use poise::serenity_prelude::Channel;
|
||||||
use tracing::{debug, info, instrument};
|
use tracing::{debug, info, instrument};
|
||||||
@ -18,6 +19,10 @@ pub async fn status(
|
|||||||
ctx: Context<'_>,
|
ctx: Context<'_>,
|
||||||
#[description = "Channel of the trivia game, or current"] channel_id: Option<Channel>,
|
#[description = "Channel of the trivia game, or current"] channel_id: Option<Channel>,
|
||||||
#[description = "Whether to start/stop the trivia game"] enabled: Option<bool>,
|
#[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> {
|
) -> Result<(), Error> {
|
||||||
let guild_id = match ctx.guild_id() {
|
let guild_id = match ctx.guild_id() {
|
||||||
Some(id) => id.get(),
|
Some(id) => id.get(),
|
||||||
@ -83,6 +88,27 @@ pub async fn status(
|
|||||||
} else {
|
} else {
|
||||||
TrivialStatus::Paused
|
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
|
trivia_exists.sign = 1; // Set sign to 1 to indicate a status change
|
||||||
inserter.write(&trivia_exists.clone()).await?;
|
inserter.write(&trivia_exists.clone()).await?;
|
||||||
match inserter.end().await {
|
match inserter.end().await {
|
||||||
|
Loading…
Reference in New Issue
Block a user