feat: basic setup for link slash command
This commit is contained in:
parent
591c61b009
commit
14cbf0bcad
6 changed files with 238 additions and 41 deletions
41
src/lib.rs
41
src/lib.rs
|
@ -9,6 +9,7 @@ use serenity::{
|
|||
};
|
||||
|
||||
use chrono::{Datelike, SecondsFormat, Utc};
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use sqlx::{
|
||||
sqlite::{SqliteConnectOptions, SqlitePoolOptions, SqliteRow},
|
||||
Error, FromRow, Pool, Row, Sqlite,
|
||||
|
@ -127,23 +128,21 @@ impl<'r> FromRow<'r, SqliteRow> for ServerMembers {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, sqlx::FromRow)]
|
||||
pub struct Wolves {
|
||||
pub id_wolves: String,
|
||||
pub email: String,
|
||||
pub verified: bool,
|
||||
pub discord: Option<String>,
|
||||
pub minecraft: Option<String>,
|
||||
}
|
||||
|
||||
impl<'r> FromRow<'r, SqliteRow> for Wolves {
|
||||
fn from_row(row: &'r SqliteRow) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
id_wolves: row.try_get("id_wolves")?,
|
||||
email: row.try_get("email")?,
|
||||
discord: row.try_get("discord")?,
|
||||
minecraft: row.try_get("minecraft")?,
|
||||
})
|
||||
}
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, sqlx::FromRow)]
|
||||
pub struct WolvesVerify {
|
||||
pub email: String,
|
||||
pub discord: String,
|
||||
pub auth_code: String,
|
||||
pub date_expiry: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
|
@ -202,7 +201,8 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
|
|||
id_wolves text PRIMARY KEY,
|
||||
email text not null,
|
||||
discord text,
|
||||
minecraft text
|
||||
minecraft text,
|
||||
verified integer DEFAULT FALSE
|
||||
)",
|
||||
)
|
||||
.execute(&pool)
|
||||
|
@ -210,6 +210,21 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
|
|||
|
||||
sqlx::query("CREATE INDEX IF NOT EXISTS index_discord ON wolves (discord)").execute(&pool).await?;
|
||||
|
||||
sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS wolves_verify (
|
||||
email text PRIMARY KEY,
|
||||
discord text not null,
|
||||
auth_code text not null,
|
||||
date_expiry text not null
|
||||
)",
|
||||
)
|
||||
.execute(&pool)
|
||||
.await?;
|
||||
|
||||
sqlx::query("CREATE INDEX IF NOT EXISTS index_date_expiry ON wolves_verify (date_expiry)")
|
||||
.execute(&pool)
|
||||
.await?;
|
||||
|
||||
sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS server_members (
|
||||
server integer not null,
|
||||
|
@ -304,3 +319,7 @@ pub fn get_now_iso(short: bool) -> String {
|
|||
now.to_rfc3339_opts(SecondsFormat::Millis, true)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn random_string(len: usize) -> String {
|
||||
thread_rng().sample_iter(&Alphanumeric).take(len).map(char::from).collect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue