From 2ac6929ab1ad2d070fa294640336e2c95db9a1a5 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 26 Nov 2024 14:05:38 +0100 Subject: [PATCH] Silly mistake made by having an await outside of the box.pin --- src/io.rs | 6 +----- src/watchdog.rs | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/io.rs b/src/io.rs index 59091a3..9ae169e 100644 --- a/src/io.rs +++ b/src/io.rs @@ -378,12 +378,8 @@ pub async fn discord_main_loop(event_holder: EventHolder) { ..Default::default() }) .setup(|ctx, _ready, framework| { - event_holder - .discord_ctx - .lock() - .unwrap() - .replace(ctx.clone()); Box::pin(async move { + event_holder.discord_ctx.lock().await.replace(ctx.clone()); poise::builtins::register_globally(ctx, &framework.options().commands).await?; Ok(Data { event_holder }) }) diff --git a/src/watchdog.rs b/src/watchdog.rs index 3163b99..0c13eab 100644 --- a/src/watchdog.rs +++ b/src/watchdog.rs @@ -15,8 +15,7 @@ use crate::votes::EventHolder; use chrono::{DateTime, Local, NaiveDate}; -use poise::serenity_prelude::{CacheHttp, ChannelId}; -use serde::Serialize; +use poise::serenity_prelude::{self, CacheHttp, ChannelId, Message}; /// The main scheduler waiting and dispatch loop. /// @@ -28,7 +27,7 @@ use serde::Serialize; #[cfg(not(tarpaulin_include))] // This loop is untestable instead the logic is kept to the minimal pub async fn main_scheduler_loop(mut interval: tokio::time::Interval, ev_ctx: EventHolder) { loop { - fk_around(&ev_ctx); + fk_around(&ev_ctx).await; interval.tick().await; // tokio::spawn(async {watchdog_update().await;}); // For async task let ev = ev_ctx.clone(); @@ -37,22 +36,21 @@ pub async fn main_scheduler_loop(mut interval: tokio::time::Interval, ev_ctx: Ev } /// Close to finding out -fn fk_around(ev_ctx: &EventHolder) { +async fn fk_around(ev_ctx: &EventHolder) { println!( "In the fk_around function ({}):", Local::now() // &ev_ctx ); - // if let Some(discord_ctx) = ev_ctx.discord_ctx.lock().unwrap().as_mut() { - // println!("Fking around : {:#?}", discord_ctx); - // let _ = discord_ctx - // .http() - // .send_message( - // ChannelId::new(1300786300143800351), - // Vec::new(), - // &"This is a message".to_owned(), - // ) - // .await; - // } + if let Some(discord_ctx) = ev_ctx.discord_ctx.lock().await.as_mut() { + println!("Fking around : {:#?}", discord_ctx); + let mut m = serenity_prelude::Message::default(); + m.content = "Bob".into(); + let r = discord_ctx + .http() + .send_message(ChannelId::new(1300786300143800351), Vec::new(), &m) + .await; + println!("{:?}", r); + } } /// The `watchdog_update` function updates the state of the watchdog and executes the necessary tasks.