2023-09-16 22:47:26 +01:00
|
|
|
use serenity::builder::CreateApplicationCommand;
|
|
|
|
use serenity::client::Context;
|
|
|
|
use serenity::model::application::interaction::application_command::ApplicationCommandInteraction;
|
|
|
|
use serenity::model::id::GuildId;
|
|
|
|
use serenity::model::prelude::command::CommandOptionType;
|
2023-09-17 00:14:50 +01:00
|
|
|
use serenity::model::prelude::interaction::application_command::CommandDataOptionValue;
|
|
|
|
use skynet_discord_bot::{get_now_iso, DataBase, Wolves};
|
2023-09-16 22:47:26 +01:00
|
|
|
use sqlx::{Pool, Sqlite};
|
|
|
|
|
|
|
|
pub async fn run(options: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
|
|
|
let db_lock = {
|
|
|
|
let data_read = ctx.data.read().await;
|
|
|
|
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
|
|
|
};
|
|
|
|
let db = db_lock.read().await;
|
2023-09-17 00:14:50 +01:00
|
|
|
|
|
|
|
let option = options
|
|
|
|
.data
|
|
|
|
.options
|
|
|
|
.get(0)
|
|
|
|
.expect("Expected email option")
|
|
|
|
.resolved
|
|
|
|
.as_ref()
|
|
|
|
.expect("Expected email object");
|
2023-09-16 22:47:26 +01:00
|
|
|
|
|
|
|
if let CommandDataOptionValue::String(email) = option {
|
|
|
|
format!("Email is {}, user is {} {:?}", email, options.user.name, options.guild_id)
|
|
|
|
} else {
|
|
|
|
"Please provide a valid user".to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
2023-09-17 00:14:50 +01:00
|
|
|
command
|
|
|
|
.name("link")
|
|
|
|
.description("Set Wolves Email")
|
|
|
|
.create_option(|option| option.name("email").description("UL Wolves Email").kind(CommandOptionType::String).required(true))
|
2023-09-16 22:47:26 +01:00
|
|
|
}
|
|
|
|
|
2023-09-17 00:14:50 +01:00
|
|
|
async fn get_server_member_bulk(db: &Pool<Sqlite>, server: &GuildId) -> Vec<Wolves> {
|
|
|
|
sqlx::query_as::<_, Wolves>(
|
2023-09-16 22:47:26 +01:00
|
|
|
r#"
|
2023-09-17 00:14:50 +01:00
|
|
|
SELECT *
|
|
|
|
FROM server_members
|
|
|
|
JOIN wolves ON server_members.id_wolves = wolves.id_wolves
|
|
|
|
WHERE (
|
|
|
|
server = ?
|
|
|
|
AND discord IS NOT NULL
|
|
|
|
AND expiry > ?
|
|
|
|
)
|
|
|
|
"#,
|
2023-09-16 22:47:26 +01:00
|
|
|
)
|
2023-09-17 00:14:50 +01:00
|
|
|
.bind(*server.as_u64() as i64)
|
|
|
|
.bind(get_now_iso(true))
|
|
|
|
.fetch_all(db)
|
|
|
|
.await
|
|
|
|
.unwrap_or_default()
|
|
|
|
}
|