Merge branch 'user-register' into dev
This commit is contained in:
commit
fe171fdc8e
15 changed files with 376 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![affluence::available(), minecraft::mc(), help()]
|
||||
vec![
|
||||
help(),
|
||||
affluence::available(),
|
||||
minecraft::mc(),
|
||||
users::register(),
|
||||
users::registered(),
|
||||
]
|
||||
}
|
||||
|
||||
/// Show this help menu
|
||||
|
|
|
|||
67
src/commands/users.rs
Normal file
67
src/commands/users.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
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(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue