moover_rust/src/other/notice.rs

69 lines
1.6 KiB
Rust
Raw Normal View History

2024-02-14 12:44:29 +00:00
use chrono::{Datelike, Local};
2024-02-14 12:22:29 +00:00
use serenity::prelude::*;
use crate::util::debug::send_error;
use anyhow::Result;
pub async fn notice_wrapper(ctx: Context) {
match notice(ctx.clone()).await {
Ok(_) => return,
Err(e) => {
send_error(ctx.http.clone(), e.to_string()).await;
2024-02-14 12:44:29 +00:00
return;
2024-02-14 12:22:29 +00:00
}
}
}
struct BirtdayRow {
day: u8,
month: u8,
2024-02-14 12:44:29 +00:00
nick: String,
2024-02-14 12:22:29 +00:00
}
async fn notice(ctx: Context) -> anyhow::Result<()> {
let local = Local::now();
let day = local.day();
let month = local.month();
2024-02-14 12:44:29 +00:00
let pool = sqlx::sqlite::SqlitePoolOptions::new()
.connect("my.db")
.await?;
2024-02-14 12:22:29 +00:00
2024-02-14 12:44:29 +00:00
let birtdays: Vec<BirtdayRow> = sqlx::query_as!(
BirtdayRow,
"SELECT * FROM birthdays WHERE day=6 AND month=3;"
)
.fetch(&pool)
.await?;
2024-02-14 12:22:29 +00:00
// let result = Vec::new();
// let stmt = client.conn(|conn| {
// // conn.prepare(format!("SELECT * FROM {db} WHERE day={day} AND month={month};").as_str());
// conn.prepare("SELECT * FROM birthdays WHERE day=6 AND month=3;")
// }).await?;
let rows = stmt.query([])?;
let result: Vec<BirtdayRow> = Vec::new();
while let Some(row) = rows.next()? {
let bd = BirtdayRow {
day: row.get(1)?,
month: row.get(2)?,
2024-02-14 12:44:29 +00:00
nick: row.get(3)?,
2024-02-14 12:22:29 +00:00
};
result.push(bd);
}
println!("VALUE: {:?}", result[0].day);
// for db in ["birthdays", "events"] {
2024-02-14 12:44:29 +00:00
2024-02-14 12:22:29 +00:00
// // let mut stmt = client.conn(|conn| {
// // conn.
// // }).await;
// }
Ok(())
2024-02-14 12:44:29 +00:00
}