68 lines
1.7 KiB
Rust
68 lines
1.7 KiB
Rust
use crate::db::users::{NewUser, User};
|
|
use crate::{Context, Error};
|
|
use diesel::RunQueryDsl;
|
|
|
|
#[poise::command(prefix_command, slash_command)]
|
|
pub async fn register(
|
|
ctx: Context<'_>,
|
|
first_name: String,
|
|
last_name: String,
|
|
email: String,
|
|
) -> Result<(), Error> {
|
|
if let Some(guild_id) = ctx.guild_id() {
|
|
let discord_id = ctx.author().id.0 as i64;
|
|
|
|
{
|
|
let mut conn = ctx.data().pool.get()?;
|
|
|
|
if User::get(&mut conn, guild_id.into(), discord_id)?.is_some() {
|
|
ctx.say("You've already been registered.").await?;
|
|
|
|
return Ok(());
|
|
}
|
|
|
|
let new_user = NewUser {
|
|
discord_id,
|
|
guild_id: guild_id.into(),
|
|
first_name,
|
|
last_name,
|
|
email,
|
|
};
|
|
|
|
new_user.insert(&mut conn)?;
|
|
}
|
|
|
|
ctx.say("You have been registered.").await?;
|
|
} else {
|
|
ctx.say("You have to send this message from a guild.")
|
|
.await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[poise::command(prefix_command, slash_command)]
|
|
pub async fn registered(ctx: Context<'_>) -> Result<(), Error> {
|
|
if let Some(guild_id) = ctx.guild_id() {
|
|
let users = {
|
|
let mut conn = ctx.data().pool.get()?;
|
|
User::by_guild_id(guild_id.into()).load(&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?;
|
|
} else {
|
|
ctx.say("You are not in a guild.").await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|