2024-06-22 16:40:56 +02:00
|
|
|
use crate::context::{Context, Error};
|
|
|
|
|
2024-06-22 23:07:11 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2024-06-22 16:40:56 +02:00
|
|
|
pub struct User {
|
|
|
|
pub id: u32,
|
|
|
|
pub discord_id: String,
|
|
|
|
pub nickname: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl User {
|
|
|
|
pub async fn from_context(ctx: &Context<'_>) -> Result<Self, Error> {
|
|
|
|
let id = ctx.author().id.get().to_string();
|
2024-06-22 23:07:11 +02:00
|
|
|
let user = sqlx::query!("SELECT * FROM users WHERE discord_id = ?", id)
|
2024-06-22 16:40:56 +02:00
|
|
|
.fetch_one(&ctx.data().db)
|
|
|
|
.await?;
|
|
|
|
|
2024-06-22 23:07:11 +02:00
|
|
|
Ok(User {
|
|
|
|
id: user.id as u32,
|
|
|
|
discord_id: user.discord_id,
|
|
|
|
nickname: user.nickname,
|
|
|
|
})
|
2024-06-22 16:40:56 +02:00
|
|
|
}
|
|
|
|
}
|