forked from Skynet/discord-bot
feat: now using seperate tables for key info, joined when needed
This commit is contained in:
parent
f405cbbb93
commit
591c61b009
6 changed files with 225 additions and 198 deletions
|
@ -1,17 +1,11 @@
|
|||
use serenity::builder::CreateApplicationCommand;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::application::interaction::Interaction;
|
||||
use serenity::model::application::interaction::application_command::ApplicationCommandInteraction;
|
||||
use serenity::model::id::GuildId;
|
||||
use serenity::model::prelude::command::CommandOptionType;
|
||||
use serenity::model::prelude::interaction::application_command::{
|
||||
CommandDataOption,
|
||||
CommandDataOptionValue,
|
||||
};
|
||||
use serenity::model::user::User;
|
||||
use serenity::model::prelude::interaction::application_command::CommandDataOptionValue;
|
||||
use skynet_discord_bot::{get_now_iso, DataBase, Wolves};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use skynet_discord_bot::DataBase;
|
||||
|
||||
|
||||
pub async fn run(options: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
let db_lock = {
|
||||
|
@ -19,11 +13,15 @@ pub async fn run(options: &ApplicationCommandInteraction, ctx: &Context) -> Stri
|
|||
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
||||
};
|
||||
let db = db_lock.read().await;
|
||||
|
||||
|
||||
|
||||
|
||||
let option = options.data.options.get(0).expect("Expected email option").resolved.as_ref().expect("Expected email object");
|
||||
|
||||
let option = options
|
||||
.data
|
||||
.options
|
||||
.get(0)
|
||||
.expect("Expected email option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected email object");
|
||||
|
||||
if let CommandDataOptionValue::String(email) = option {
|
||||
format!("Email is {}, user is {} {:?}", email, options.user.name, options.guild_id)
|
||||
|
@ -33,26 +31,28 @@ pub async fn run(options: &ApplicationCommandInteraction, ctx: &Context) -> Stri
|
|||
}
|
||||
|
||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||
command.name("link").description("Set Wolves Email").create_option(|option| {
|
||||
option
|
||||
.name("email")
|
||||
.description("UL Wolves Email")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(true)
|
||||
})
|
||||
command
|
||||
.name("link")
|
||||
.description("Set Wolves Email")
|
||||
.create_option(|option| option.name("email").description("UL Wolves Email").kind(CommandOptionType::String).required(true))
|
||||
}
|
||||
|
||||
async fn get_server_member(db: &Pool<Sqlite>, server: &GuildId) -> Vec<Accounts> {
|
||||
sqlx::query_as::<_, Accounts>(
|
||||
async fn get_server_member_bulk(db: &Pool<Sqlite>, server: &GuildId) -> Vec<Wolves> {
|
||||
sqlx::query_as::<_, Wolves>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM wolves
|
||||
WHERE server = ? AND discord IS NOT NULL AND expiry > ?
|
||||
"#,
|
||||
SELECT *
|
||||
FROM server_members
|
||||
JOIN wolves ON server_members.id_wolves = wolves.id_wolves
|
||||
WHERE (
|
||||
server = ?
|
||||
AND discord IS NOT NULL
|
||||
AND expiry > ?
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.bind(*server.as_u64() as i64)
|
||||
.bind(get_now_iso(true))
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
}
|
||||
.bind(*server.as_u64() as i64)
|
||||
.bind(get_now_iso(true))
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
pub mod link_email;
|
||||
pub mod link_email;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue