feat: bumped serenity to the latest version
Lots of changes to how it runs
This commit is contained in:
parent
a8c1cc9cf1
commit
6b84f33d2e
12 changed files with 352 additions and 485 deletions
|
@ -4,15 +4,7 @@ use lettre::{
|
|||
Message, SmtpTransport, Transport,
|
||||
};
|
||||
use maud::html;
|
||||
use serenity::{
|
||||
builder::CreateApplicationCommand,
|
||||
client::Context,
|
||||
model::{
|
||||
application::interaction::application_command::ApplicationCommandInteraction,
|
||||
id::UserId,
|
||||
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
|
||||
},
|
||||
};
|
||||
use serenity::{builder::CreateCommand, client::Context, model::id::UserId};
|
||||
use skynet_discord_bot::common::database::{DataBase, Wolves, WolvesVerify};
|
||||
use skynet_discord_bot::{get_now_iso, random_string, Config};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
@ -20,8 +12,9 @@ use sqlx::{Pool, Sqlite};
|
|||
pub mod link {
|
||||
use super::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommand, CreateCommandOption};
|
||||
|
||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||
|
@ -44,16 +37,11 @@ pub mod link {
|
|||
return "Linking already in process, please check email.".to_string();
|
||||
}
|
||||
|
||||
let option = command
|
||||
.data
|
||||
.options
|
||||
.first()
|
||||
.expect("Expected email option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected email object");
|
||||
|
||||
let email = if let CommandDataOptionValue::String(email) = option {
|
||||
let email = if let Some(CommandDataOption {
|
||||
value: CommandDataOptionValue::String(email),
|
||||
..
|
||||
}) = command.data.options.first()
|
||||
{
|
||||
email.trim()
|
||||
} else {
|
||||
return "Please provide a valid user".to_string();
|
||||
|
@ -115,11 +103,10 @@ pub mod link {
|
|||
format!("Verification email sent to {}, it may take up to 15 min for it to arrive. If it takes longer check the Junk folder.", email)
|
||||
}
|
||||
|
||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||
command
|
||||
.name("link_wolves")
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("link_wolves")
|
||||
.description("Set Wolves Email")
|
||||
.create_option(|option| option.name("email").description("UL Wolves Email").kind(CommandOptionType::String).required(true))
|
||||
.add_option(CreateCommandOption::new(CommandOptionType::String, "email", "UL Wolves Email").required(true))
|
||||
}
|
||||
|
||||
pub async fn get_server_member_discord(db: &Pool<Sqlite>, user: &UserId) -> Option<Wolves> {
|
||||
|
@ -130,7 +117,7 @@ pub mod link {
|
|||
WHERE discord = ?
|
||||
"#,
|
||||
)
|
||||
.bind(*user.as_u64() as i64)
|
||||
.bind(user.get() as i64)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
|
@ -242,7 +229,7 @@ pub mod link {
|
|||
WHERE discord = ?
|
||||
"#,
|
||||
)
|
||||
.bind(*user.as_u64() as i64)
|
||||
.bind(user.get() as i64)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
|
@ -256,7 +243,7 @@ pub mod link {
|
|||
",
|
||||
)
|
||||
.bind(record.email.to_owned())
|
||||
.bind(*user.as_u64() as i64)
|
||||
.bind(user.get() as i64)
|
||||
.bind(auth.to_owned())
|
||||
.bind(get_now_iso(false))
|
||||
.fetch_optional(db)
|
||||
|
@ -294,12 +281,13 @@ pub mod link {
|
|||
pub mod verify {
|
||||
use super::*;
|
||||
use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db};
|
||||
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption};
|
||||
use serenity::model::user::User;
|
||||
use skynet_discord_bot::common::database::get_server_config;
|
||||
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
|
||||
use sqlx::Error;
|
||||
|
||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||
|
@ -313,16 +301,11 @@ pub mod verify {
|
|||
return "Please use /link_wolves first".to_string();
|
||||
};
|
||||
|
||||
let option = command
|
||||
.data
|
||||
.options
|
||||
.first()
|
||||
.expect("Expected code option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected code object");
|
||||
|
||||
let code = if let CommandDataOptionValue::String(code) = option {
|
||||
let code = if let Some(CommandDataOption {
|
||||
value: CommandDataOptionValue::String(code),
|
||||
..
|
||||
}) = command.data.options.first()
|
||||
{
|
||||
code
|
||||
} else {
|
||||
return "Please provide a verification code".to_string();
|
||||
|
@ -354,14 +337,10 @@ pub mod verify {
|
|||
"Failed to verify".to_string()
|
||||
}
|
||||
|
||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||
command.name("verify").description("Verify Wolves Email").create_option(|option| {
|
||||
option
|
||||
.name("code")
|
||||
.description("Code from verification email")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(true)
|
||||
})
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("verify")
|
||||
.description("Verify Wolves Email")
|
||||
.add_option(CreateCommandOption::new(CommandOptionType::String, "code", "Code from verification email").required(true))
|
||||
}
|
||||
|
||||
async fn db_pending_clear_successful(pool: &Pool<Sqlite>, user: &UserId) -> Result<Option<WolvesVerify>, Error> {
|
||||
|
@ -372,7 +351,7 @@ pub mod verify {
|
|||
WHERE discord = ?
|
||||
"#,
|
||||
)
|
||||
.bind(*user.as_u64() as i64)
|
||||
.bind(user.get() as i64)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
}
|
||||
|
@ -385,7 +364,7 @@ pub mod verify {
|
|||
WHERE email = ?
|
||||
",
|
||||
)
|
||||
.bind(*discord.as_u64() as i64)
|
||||
.bind(discord.get() as i64)
|
||||
.bind(email)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
|
@ -394,7 +373,7 @@ pub mod verify {
|
|||
async fn set_server_roles(db: &Pool<Sqlite>, discord: &User, ctx: &Context) {
|
||||
if let Ok(servers) = get_servers(db, &discord.id).await {
|
||||
for server in servers {
|
||||
if let Ok(mut member) = server.server.member(&ctx.http, &discord.id).await {
|
||||
if let Ok(member) = server.server.member(&ctx.http, &discord.id).await {
|
||||
if let Some(config) = get_server_config(db, &server.server).await {
|
||||
let Servers {
|
||||
role_past,
|
||||
|
@ -432,7 +411,7 @@ pub mod verify {
|
|||
WHERE discord = ?
|
||||
",
|
||||
)
|
||||
.bind(*discord.as_u64() as i64)
|
||||
.bind(discord.get() as i64)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue