Compare commits
No commits in common. "982814d99cd1c4e7d80d4182e4b88eab28f0cd39" and "7e40b862d30b18f18a3fd23a89f3a119d35296a4" have entirely different histories.
982814d99c
...
7e40b862d3
6 changed files with 39 additions and 71 deletions
|
@ -3,5 +3,5 @@ CREATE TABLE IF NOT EXISTS committee (
|
|||
discord integer PRIMARY KEY,
|
||||
email text not null,
|
||||
auth_code text not null,
|
||||
committee integer DEFAULT 0
|
||||
committee integer DEFAULT 0,
|
||||
);
|
|
@ -1,2 +1,2 @@
|
|||
[toolchain]
|
||||
channel = "1.69"
|
||||
channel = "1.69.0"
|
|
@ -13,13 +13,13 @@ use serenity::{
|
|||
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
|
||||
},
|
||||
};
|
||||
use skynet_discord_bot::{random_string, Config, DataBase};
|
||||
use skynet_discord_bot::{get_now_iso, random_string, Config, DataBase, Wolves, WolvesVerify};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
|
||||
pub mod link {
|
||||
use super::*;
|
||||
use serenity::model::id::GuildId;
|
||||
use skynet_discord_bot::Committee;
|
||||
use super::*;
|
||||
|
||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
let committee_server = GuildId(1220150752656363520);
|
||||
|
@ -34,14 +34,15 @@ pub mod link {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
let option = command
|
||||
.data
|
||||
.options
|
||||
.first()
|
||||
.expect("Expected email option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected email object");
|
||||
.data
|
||||
.options
|
||||
.first()
|
||||
.expect("Expected email option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected email object");
|
||||
|
||||
let email = if let CommandDataOptionValue::String(email) = option {
|
||||
email.trim()
|
||||
|
@ -54,6 +55,7 @@ pub mod link {
|
|||
return "Please use a @ulwolves.ie address you have access to.".to_string();
|
||||
}
|
||||
|
||||
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||
|
@ -74,6 +76,7 @@ pub mod link {
|
|||
return "Linking already in process, please check email.".to_string();
|
||||
}
|
||||
|
||||
|
||||
// generate a auth key
|
||||
let auth = random_string(20);
|
||||
match send_mail(&config, email, &auth, &command.user.name) {
|
||||
|
@ -95,17 +98,11 @@ pub mod link {
|
|||
command
|
||||
.name("link_committee")
|
||||
.description("Verify you are a committee member")
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("email")
|
||||
.description("UL Wolves Committee Email")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(true)
|
||||
})
|
||||
.create_option(|option| option.name("email").description("UL Wolves Committee Email").kind(CommandOptionType::String).required(true))
|
||||
}
|
||||
|
||||
pub async fn get_server_member_discord(db: &Pool<Sqlite>, user: &UserId) -> Option<Committee> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
pub async fn get_server_member_discord(db: &Pool<Sqlite>, user: &UserId) -> Option<Wolves> {
|
||||
sqlx::query_as::<_, Wolves>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM committee
|
||||
|
@ -178,8 +175,8 @@ pub mod link {
|
|||
mailer.send(&email)
|
||||
}
|
||||
|
||||
pub async fn get_verify_from_db(db: &Pool<Sqlite>, user: &UserId) -> Option<Committee> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
pub async fn get_verify_from_db(db: &Pool<Sqlite>, user: &UserId) -> Option<WolvesVerify> {
|
||||
sqlx::query_as::<_, WolvesVerify>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM committee
|
||||
|
@ -192,8 +189,8 @@ pub mod link {
|
|||
.ok()
|
||||
}
|
||||
|
||||
async fn save_to_db(db: &Pool<Sqlite>, email: &str, auth: &str, user: &UserId) -> Result<Option<Committee>, sqlx::Error> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
async fn save_to_db(db: &Pool<Sqlite>, email: &str, auth: &str, user: &UserId) -> Result<Option<WolvesVerify>, sqlx::Error> {
|
||||
sqlx::query_as::<_, WolvesVerify>(
|
||||
"
|
||||
INSERT INTO committee (email, discord, auth_code)
|
||||
VALUES (?1, ?2, ?3)
|
||||
|
@ -208,11 +205,11 @@ pub mod link {
|
|||
}
|
||||
|
||||
pub mod verify {
|
||||
use super::*;
|
||||
use crate::commands::committee::link::get_verify_from_db;
|
||||
use serenity::model::id::{GuildId, RoleId};
|
||||
use super::*;
|
||||
use crate::commands::committee::link::{get_verify_from_db};
|
||||
use serenity::model::user::User;
|
||||
use skynet_discord_bot::Committee;
|
||||
use skynet_discord_bot::{get_server_config, ServerMembersWolves, Servers};
|
||||
use sqlx::Error;
|
||||
|
||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
|
@ -230,7 +227,7 @@ pub mod verify {
|
|||
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||
};
|
||||
let db = db_lock.read().await;
|
||||
|
||||
|
@ -260,7 +257,7 @@ pub mod verify {
|
|||
return "Invalid verification code".to_string();
|
||||
}
|
||||
|
||||
match set_discord(&db, &command.user.id).await {
|
||||
return match set_discord(&db, &command.user.id).await {
|
||||
Ok(_) => {
|
||||
// get teh right roles for the user
|
||||
set_server_roles(&command.user, ctx).await;
|
||||
|
@ -270,24 +267,21 @@ pub mod verify {
|
|||
println!("{:?}", e);
|
||||
"Failed to save, please try /link_committee again".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||
command
|
||||
.name("verify_committee")
|
||||
.description("Verify Wolves Committee Email")
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("code")
|
||||
.description("Code from verification email")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(true)
|
||||
})
|
||||
command.name("verify_committee").description("Verify Wolves Committee Email").create_option(|option| {
|
||||
option
|
||||
.name("code")
|
||||
.description("Code from verification email")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(true)
|
||||
})
|
||||
}
|
||||
|
||||
async fn set_discord(db: &Pool<Sqlite>, discord: &UserId) -> Result<Option<Committee>, Error> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
async fn set_discord(db: &Pool<Sqlite>, discord: &UserId) -> Result<Option<Wolves>, Error> {
|
||||
sqlx::query_as::<_, Wolves>(
|
||||
"
|
||||
UPDATE committee
|
||||
SET committee = 1
|
||||
|
@ -308,4 +302,5 @@ pub mod verify {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub mod add_server;
|
||||
pub mod committee;
|
||||
pub mod link_email;
|
||||
pub mod minecraft;
|
||||
pub mod committee;
|
||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -218,27 +218,6 @@ impl<'r> FromRow<'r, SqliteRow> for WolvesVerify {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Committee {
|
||||
pub email: String,
|
||||
pub discord: UserId,
|
||||
pub auth_code: String,
|
||||
pub committee: i64,
|
||||
}
|
||||
impl<'r> FromRow<'r, SqliteRow> for Committee {
|
||||
fn from_row(row: &'r SqliteRow) -> Result<Self, Error> {
|
||||
let user_tmp: i64 = row.try_get("discord")?;
|
||||
let discord = UserId::from(user_tmp as u64);
|
||||
|
||||
Ok(Self {
|
||||
email: row.try_get("email")?,
|
||||
discord,
|
||||
auth_code: row.try_get("auth_code")?,
|
||||
committee: row.try_get("committee")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Servers {
|
||||
pub server: GuildId,
|
||||
|
|
|
@ -64,9 +64,6 @@ impl EventHandler for Handler {
|
|||
.create_application_command(|command| commands::minecraft::server::list::register(command))
|
||||
.create_application_command(|command| commands::minecraft::server::delete::register(command))
|
||||
.create_application_command(|command| commands::minecraft::user::add::register(command))
|
||||
// for committee server, temp
|
||||
.create_application_command(|command| commands::committee::link::register(command))
|
||||
.create_application_command(|command| commands::committee::verify::register(command))
|
||||
})
|
||||
.await
|
||||
{
|
||||
|
@ -92,9 +89,6 @@ impl EventHandler for Handler {
|
|||
"minecraft_add" => commands::minecraft::server::add::run(&command, &ctx).await,
|
||||
"minecraft_list" => commands::minecraft::server::list::run(&command, &ctx).await,
|
||||
"minecraft_delete" => commands::minecraft::server::delete::run(&command, &ctx).await,
|
||||
// for teh committee server, temporary
|
||||
"link_committee" => commands::committee::link::run(&command, &ctx).await,
|
||||
"verify_committee" => commands::committee::verify::run(&command, &ctx).await,
|
||||
_ => "not implemented :(".to_string(),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue