component models

This commit is contained in:
jude
2022-02-19 22:11:21 +00:00
parent afc376c44f
commit 06c4deeaa9
15 changed files with 269 additions and 184 deletions

View File

@ -1,23 +1,23 @@
mod sender;
use std::env;
use log::info;
use serenity::client::Context;
use sqlx::{Executor, MySql};
use std::env;
use tokio::time::sleep_until;
use tokio::time::{Duration, Instant};
use tokio::time::{sleep_until, Duration, Instant};
type Database = MySql;
pub async fn initialize(ctx: Context, pool: impl Executor<'_, Database = Database> + Copy) {
let REMIND_INTERVAL = env::var("REMIND_INTERVAL")
let remind_interval = env::var("REMIND_INTERVAL")
.map(|inner| inner.parse::<u64>().ok())
.ok()
.flatten()
.unwrap_or(10);
loop {
let sleep_to = Instant::now() + Duration::from_secs(REMIND_INTERVAL);
let sleep_to = Instant::now() + Duration::from_secs(remind_interval);
let reminders = sender::Reminder::fetch_reminders(pool).await;
if reminders.len() > 0 {