feat: initial register functionality
Some checks failed
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/clippy Pipeline failed
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Jef Roosens 2023-05-15 17:38:13 +02:00
parent f8ce315d8e
commit e834b3308a
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
15 changed files with 183 additions and 1 deletions

View file

@ -1,12 +1,19 @@
mod affluence;
mod minecraft;
mod users;
use crate::{Context, Data, Error};
type EmbedField = (String, String, bool);
pub fn commands() -> Vec<poise::structs::Command<Data, Error>> {
vec![help(), affluence::available(), minecraft::ping_mc()]
vec![
help(),
affluence::available(),
minecraft::ping_mc(),
users::register(),
users::registered(),
]
}
/// Show this help menu

45
src/commands/users.rs Normal file
View file

@ -0,0 +1,45 @@
use crate::db::users::{user_all, user_insert, User};
use crate::{Context, Error};
#[poise::command(prefix_command, slash_command)]
pub async fn register(
ctx: Context<'_>,
first_name: String,
last_name: String,
email: String,
) -> Result<(), Error> {
let user = User {
discord_id: ctx.author().id.0 as i64,
first_name,
last_name,
email,
};
{
let mut conn = ctx.data().conn.lock().unwrap();
user_insert(&mut conn, &user);
}
Ok(())
}
#[poise::command(prefix_command, slash_command)]
pub async fn registered(ctx: Context<'_>) -> Result<(), Error> {
let users = {
let mut conn = ctx.data().conn.lock().unwrap();
user_all(&mut conn)
};
ctx.send(|f| {
f.embed(|e| {
e.description("Registered users").fields(
users
.into_iter()
.map(|u| (format!("{} {}", u.first_name, u.last_name), u.email, false)),
)
})
})
.await?;
Ok(())
}