Compare commits
4 commits
50d2923425
...
982814d99c
Author | SHA1 | Date | |
---|---|---|---|
982814d99c | |||
44399fe277 | |||
790c01949d | |||
269984b8e6 |
6 changed files with 71 additions and 39 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.0"
|
||||
channel = "1.69"
|
|
@ -13,13 +13,13 @@ use serenity::{
|
|||
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
|
||||
},
|
||||
};
|
||||
use skynet_discord_bot::{get_now_iso, random_string, Config, DataBase, Wolves, WolvesVerify};
|
||||
use skynet_discord_bot::{random_string, Config, DataBase};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
|
||||
pub mod link {
|
||||
use serenity::model::id::GuildId;
|
||||
use super::*;
|
||||
use serenity::model::id::GuildId;
|
||||
use skynet_discord_bot::Committee;
|
||||
|
||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
let committee_server = GuildId(1220150752656363520);
|
||||
|
@ -34,7 +34,6 @@ pub mod link {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
let option = command
|
||||
.data
|
||||
.options
|
||||
|
@ -55,7 +54,6 @@ 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()
|
||||
|
@ -76,7 +74,6 @@ 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) {
|
||||
|
@ -98,11 +95,17 @@ 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<Wolves> {
|
||||
sqlx::query_as::<_, Wolves>(
|
||||
pub async fn get_server_member_discord(db: &Pool<Sqlite>, user: &UserId) -> Option<Committee> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM committee
|
||||
|
@ -175,8 +178,8 @@ pub mod link {
|
|||
mailer.send(&email)
|
||||
}
|
||||
|
||||
pub async fn get_verify_from_db(db: &Pool<Sqlite>, user: &UserId) -> Option<WolvesVerify> {
|
||||
sqlx::query_as::<_, WolvesVerify>(
|
||||
pub async fn get_verify_from_db(db: &Pool<Sqlite>, user: &UserId) -> Option<Committee> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM committee
|
||||
|
@ -189,8 +192,8 @@ pub mod link {
|
|||
.ok()
|
||||
}
|
||||
|
||||
async fn save_to_db(db: &Pool<Sqlite>, email: &str, auth: &str, user: &UserId) -> Result<Option<WolvesVerify>, sqlx::Error> {
|
||||
sqlx::query_as::<_, WolvesVerify>(
|
||||
async fn save_to_db(db: &Pool<Sqlite>, email: &str, auth: &str, user: &UserId) -> Result<Option<Committee>, sqlx::Error> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
"
|
||||
INSERT INTO committee (email, discord, auth_code)
|
||||
VALUES (?1, ?2, ?3)
|
||||
|
@ -205,11 +208,11 @@ pub mod link {
|
|||
}
|
||||
|
||||
pub mod verify {
|
||||
use serenity::model::id::{GuildId, RoleId};
|
||||
use super::*;
|
||||
use crate::commands::committee::link::{get_verify_from_db};
|
||||
use crate::commands::committee::link::get_verify_from_db;
|
||||
use serenity::model::id::{GuildId, RoleId};
|
||||
use serenity::model::user::User;
|
||||
use skynet_discord_bot::{get_server_config, ServerMembersWolves, Servers};
|
||||
use skynet_discord_bot::Committee;
|
||||
use sqlx::Error;
|
||||
|
||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
|
@ -227,7 +230,7 @@ pub mod verify {
|
|||
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||
};
|
||||
let db = db_lock.read().await;
|
||||
|
||||
|
@ -257,7 +260,7 @@ pub mod verify {
|
|||
return "Invalid verification code".to_string();
|
||||
}
|
||||
|
||||
return match set_discord(&db, &command.user.id).await {
|
||||
match set_discord(&db, &command.user.id).await {
|
||||
Ok(_) => {
|
||||
// get teh right roles for the user
|
||||
set_server_roles(&command.user, ctx).await;
|
||||
|
@ -267,11 +270,14 @@ 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| {
|
||||
command
|
||||
.name("verify_committee")
|
||||
.description("Verify Wolves Committee Email")
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("code")
|
||||
.description("Code from verification email")
|
||||
|
@ -280,8 +286,8 @@ pub mod verify {
|
|||
})
|
||||
}
|
||||
|
||||
async fn set_discord(db: &Pool<Sqlite>, discord: &UserId) -> Result<Option<Wolves>, Error> {
|
||||
sqlx::query_as::<_, Wolves>(
|
||||
async fn set_discord(db: &Pool<Sqlite>, discord: &UserId) -> Result<Option<Committee>, Error> {
|
||||
sqlx::query_as::<_, Committee>(
|
||||
"
|
||||
UPDATE committee
|
||||
SET committee = 1
|
||||
|
@ -302,5 +308,4 @@ 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,6 +218,27 @@ 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,6 +64,9 @@ 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
|
||||
{
|
||||
|
@ -89,6 +92,9 @@ 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