From 8ae9ec821f2d0683af35a7bb7ab891be5337fe44 Mon Sep 17 00:00:00 2001 From: Max batleforc Date: Mon, 1 Jul 2024 22:58:21 +0200 Subject: [PATCH] feat: fix period ++ burst_colours missing --- Cargo.lock | 17 +++++++++--- Cargo.toml | 2 ++ src/botv2/cmd/concour/period.rs | 46 +++++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 347f0ef..6ece55e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3535,6 +3535,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_cow" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e84ce5596a72f0c4c60759a10ff8c22d5eaf227b0dc2789c8746193309058b" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.203" @@ -3635,13 +3644,12 @@ dependencies = [ [[package]] name = "serenity" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64da29158bb55d70677cacd4f4f8eab1acef005fb830d9c3bea411b090e96a9" +version = "0.12.2" +source = "git+https://github.com/serenity-rs/serenity?branch=current#060ee3281b44f7e532f3ea5863c5df57340e1ec9" dependencies = [ "arrayvec", "async-trait", - "base64 0.21.7", + "base64 0.22.1", "bitflags 2.5.0", "bytes", "chrono", @@ -3655,6 +3663,7 @@ dependencies = [ "reqwest", "secrecy", "serde", + "serde_cow", "serde_json", "time", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 2e992bf..ce3536b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,8 @@ serde_with = "3.8.1" tokio-cron = "0.1.3" cron = "0.12.1" +[patch.crates-io] +serenity = { git = "https://github.com/serenity-rs/serenity", branch = "current" } [[bin]] name = "botdiscord" diff --git a/src/botv2/cmd/concour/period.rs b/src/botv2/cmd/concour/period.rs index fc0602e..0a11449 100644 --- a/src/botv2/cmd/concour/period.rs +++ b/src/botv2/cmd/concour/period.rs @@ -1,11 +1,14 @@ use std::str::FromStr; -use crate::botv2::{ - domain::concour::{ - check_if_allowed::check_if_allowed, - set_periode::{set_periode, SetPeriodeConcourError}, +use crate::{ + botv2::{ + domain::concour::{ + check_if_allowed::check_if_allowed, + set_periode::{set_periode, SetPeriodeConcourError}, + }, + init::{Context, Error}, }, - init::{Context, Error}, + db::concour::ConcourStatus, }; use chrono::{DateTime, Utc}; use cron::Schedule; @@ -134,6 +137,39 @@ pub async fn period( false, ); } + // Restart the cronjob if concour is ongoing + if concour.status == ConcourStatus::OnGoing { + { + let mut scheduler = ctx.data().scheduler.clone(); + match scheduler + .stop_scheduled_job(concour.server_id, concour.channel_id) + .await + { + Ok(_) => { + info!("Cronjob stopped"); + match scheduler + .add_concour_cron_job( + concour.server_id, + concour.channel_id, + concour.periode, + ctx.http(), + ) + .await + { + Ok(_) => { + info!("Cronjob restarted"); + } + Err(_) => { + warn!("Error restarting cronjob"); + } + }; + } + Err(err) => { + warn!(err = err.to_string(), "Error stopping cronjob"); + } + } + } + } output } }