feat: initial register functionality
This commit is contained in:
parent
f8ce315d8e
commit
e834b3308a
15 changed files with 183 additions and 1 deletions
|
|
@ -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
45
src/commands/users.rs
Normal 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(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue