diff --git a/Cargo.lock b/Cargo.lock index a1c92c1..d0b769f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,6 +111,15 @@ version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +dependencies = [ + "serde", +] + [[package]] name = "async-channel" version = "1.9.0" @@ -257,22 +266,6 @@ dependencies = [ "syn 2.0.89", ] -[[package]] -name = "async-tungstenite" -version = "0.17.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1b71b31561643aa8e7df3effe284fa83ab1a840e52294c5f4bd7bfd8b2becbb" -dependencies = [ - "futures-io", - "futures-util", - "log", - "pin-project-lite", - "tokio", - "tokio-rustls 0.23.4", - "tungstenite", - "webpki-roots 0.22.6", -] - [[package]] name = "atoi" version = "2.0.0" @@ -629,6 +622,12 @@ dependencies = [ "serde", ] +[[package]] +name = "data-encoding" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "575f75dfd25738df5b91b8e43e14d44bda14637a58fae779fd2b064f8bf3e010" + [[package]] name = "der" version = "0.7.9" @@ -815,7 +814,7 @@ checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ "futures-core", "futures-sink", - "spin 0.9.8", + "spin", ] [[package]] @@ -975,6 +974,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -1298,7 +1306,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.7", "tokio", "tower-service", "tracing", @@ -1518,7 +1526,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin 0.9.8", + "spin", ] [[package]] @@ -1846,15 +1854,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "ordered-float" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" -dependencies = [ - "num-traits", -] - [[package]] name = "parking" version = "2.2.1" @@ -2237,21 +2236,6 @@ dependencies = [ "windows-registry", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.8" @@ -2262,8 +2246,8 @@ dependencies = [ "cfg-if", "getrandom 0.2.15", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "spin", + "untrusted", "windows-sys 0.52.0", ] @@ -2315,18 +2299,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustls" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" -dependencies = [ - "log", - "ring 0.16.20", - "sct", - "webpki", -] - [[package]] name = "rustls" version = "0.21.12" @@ -2334,11 +2306,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-webpki 0.101.7", "sct", ] +[[package]] +name = "rustls" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki 0.102.8", + "subtle", + "zeroize", +] + [[package]] name = "rustls" version = "0.23.18" @@ -2382,8 +2368,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -2392,9 +2378,9 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ - "ring 0.17.8", + "ring", "rustls-pki-types", - "untrusted 0.9.0", + "untrusted", ] [[package]] @@ -2424,8 +2410,18 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", +] + +[[package]] +name = "secrecy" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" +dependencies = [ + "serde", + "zeroize", ] [[package]] @@ -2476,12 +2472,11 @@ dependencies = [ ] [[package]] -name = "serde-value" -version = "0.7.0" +name = "serde_cow" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +checksum = "1e7bbbec7196bfde255ab54b65e34087c0849629280028238e67ee25d6a4b7da" dependencies = [ - "ordered-float", "serde", ] @@ -2533,45 +2528,35 @@ dependencies = [ [[package]] name = "serenity" -version = "0.11.7" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a7a89cef23483fc9d4caf2df41e6d3928e18aada84c56abd237439d929622c6" +checksum = "3d72ec4323681bf9a3cabe40fd080abc2435859b502a1b5aa9bf693f125bfa76" dependencies = [ + "arrayvec", "async-trait", - "async-tungstenite", - "base64 0.21.7", - "bitflags 1.3.2", + "base64 0.22.1", + "bitflags 2.6.0", "bytes 1.7.1", - "cfg-if", "dashmap", "flate2", "futures", - "mime", + "fxhash", "mime_guess", "parking_lot", "percent-encoding", "reqwest 0.11.27", + "secrecy", "serde", - "serde-value", + "serde_cow", "serde_json", "time 0.3.36", "tokio", + "tokio-tungstenite", "tracing", "typemap_rev", "url", ] -[[package]] -name = "sha-1" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - [[package]] name = "sha1" version = "0.6.1" @@ -2711,12 +2696,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -3281,17 +3260,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-rustls" -version = "0.23.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" -dependencies = [ - "rustls 0.20.9", - "tokio", - "webpki", -] - [[package]] name = "tokio-rustls" version = "0.24.1" @@ -3302,6 +3270,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls 0.22.4", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.0" @@ -3337,6 +3316,22 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "tokio-tungstenite" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" +dependencies = [ + "futures-util", + "log", + "rustls 0.22.4", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.25.0", + "tungstenite", + "webpki-roots 0.26.8", +] + [[package]] name = "tokio-util" version = "0.7.12" @@ -3406,30 +3401,30 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tungstenite" -version = "0.17.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" dependencies = [ - "base64 0.13.1", "byteorder", "bytes 1.7.1", - "http 0.2.12", + "data-encoding", + "http 1.1.0", "httparse", "log", "rand 0.8.5", - "rustls 0.20.9", - "sha-1", + "rustls 0.22.4", + "rustls-pki-types", + "sha1 0.10.6", "thiserror", "url", "utf-8", - "webpki", ] [[package]] name = "typemap_rev" -version = "0.1.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed5b74f0a24b5454580a79abb6994393b09adf0ab8070f15827cb666255de155" +checksum = "74b08b0c1257381af16a5c3605254d529d3e7e109f3c62befc5d168968192998" [[package]] name = "typenum" @@ -3495,12 +3490,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -3672,31 +3661,21 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" -dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", -] - -[[package]] -name = "webpki-roots" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" -dependencies = [ - "webpki", -] - [[package]] name = "webpki-roots" version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "webpki-roots" +version = "0.26.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2210b291f7ea53617fbafcc4939f10914214ec15aace5ba62293a668f322c5c9" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "whoami" version = "1.5.2" diff --git a/Cargo.toml b/Cargo.toml index fa0ffdc..d637ae8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ name = "update_minecraft" [dependencies] # discord library -serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] } +serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] } tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "full"] } # wolves api diff --git a/src/commands/add_server.rs b/src/commands/add_server.rs index 8f06527..fdc0f23 100644 --- a/src/commands/add_server.rs +++ b/src/commands/add_server.rs @@ -1,68 +1,53 @@ -use serenity::{ - builder::CreateApplicationCommand, - client::Context, - model::{ - application::interaction::application_command::ApplicationCommandInteraction, - prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue}, - }, -}; +use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption}; +use serenity::{builder::CreateCommand, client::Context}; use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers}; use skynet_discord_bot::common::set_roles::normal::update_server; use skynet_discord_bot::common::wolves::cns::get_wolves; use skynet_discord_bot::is_admin; use sqlx::{Error, Pool, Sqlite}; -pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String { +pub async fn run(command: &CommandInteraction, ctx: &Context) -> String { // check if user has high enough permisssions if let Some(msg) = is_admin(command, ctx).await { return msg; } - let api_key = if let CommandDataOptionValue::String(key) = command - .data - .options - .first() - .expect("Expected user option") - .resolved - .as_ref() - .expect("Expected user object") + let wolves_api = if let Some(CommandDataOption { + value: CommandDataOptionValue::String(key), + .. + }) = command.data.options.first() { - key + key.to_string() } else { return "Please provide a wolves API key".to_string(); }; - let role_current = if let CommandDataOptionValue::Role(role) = command - .data - .options - .get(1) - .expect("Expected role option") - .resolved - .as_ref() - .expect("Expected role object") + let role_current = if let Some(CommandDataOption { + value: CommandDataOptionValue::Role(role), + .. + }) = command.data.options.get(1) { - role.id.to_owned() + role.to_owned() } else { return "Please provide a valid role for ``Role Current``".to_string(); }; - let mut role_past = None; - if let Some(x) = command.data.options.get(5) { - if let Some(CommandDataOptionValue::Role(role)) = &x.resolved { - role_past = Some(role.id.to_owned()); - } + let role_past = if let Some(CommandDataOption { + value: CommandDataOptionValue::Role(role), + .. + }) = command.data.options.get(5) + { + Some(role.to_owned()) + } else { + None }; - let bot_channel_id = if let CommandDataOptionValue::Channel(channel) = command - .data - .options - .get(2) - .expect("Expected channel option") - .resolved - .as_ref() - .expect("Expected channel object") + let bot_channel_id = if let Some(CommandDataOption { + value: CommandDataOptionValue::Channel(channel), + .. + }) = command.data.options.get(2) { - channel.id.to_owned() + channel.to_owned() } else { return "Please provide a valid channel for ``Bot Channel``".to_string(); }; @@ -75,7 +60,7 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri let server_data = Servers { server: command.guild_id.unwrap_or_default(), - wolves_api: api_key.to_owned(), + wolves_api, role_past, role_current, member_past: 0, @@ -95,43 +80,18 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri "Added/Updated server info".to_string() } -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("add") +pub fn register() -> CreateCommand { + CreateCommand::new("add") .description("Enable the bot for this discord") - .create_option(|option| { - option - .name("api_key") - .description("UL Wolves API Key") - .kind(CommandOptionType::String) - .required(true) - }) - .create_option(|option| { - option - .name("role_current") - .description("Role for Current members") - .kind(CommandOptionType::Role) - .required(true) - }) - .create_option(|option| { - option - .name("bot_channel") - .description("Safe space for folks to use the bot commands.") - .kind(CommandOptionType::Channel) - .required(true) - }) - .create_option(|option| { - option - .name("role_past") - .description("Role for Past members") - .kind(CommandOptionType::Role) - .required(false) - }) + .add_option(CreateCommandOption::new(CommandOptionType::String, "api_key", "UL Wolves API Key").required(true)) + .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_current", "Role for Current members").required(true)) + .add_option(CreateCommandOption::new(CommandOptionType::Channel, "bot_channel", "Safe space for folks to use the bot commands.").required(true)) + .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_past", "Role for Past members").required(false)) } async fn add_server(db: &Pool, ctx: &Context, server: &Servers) -> Result, Error> { let existing = get_server_config(db, &server.server).await; - let role_past = server.role_past.map(|x| *x.as_u64() as i64); + let role_past = server.role_past.map(|x| x.get() as i64); let insert = sqlx::query_as::<_, Servers>( " @@ -139,11 +99,11 @@ async fn add_server(db: &Pool, ctx: &Context, server: &Servers) -> Resul VALUES (?1, ?2, ?3, ?4, ?5) ", ) - .bind(*server.server.as_u64() as i64) + .bind(server.server.get() as i64) .bind(&server.wolves_api) .bind(role_past) - .bind(*server.role_current.as_u64() as i64) - .bind(*server.bot_channel_id.as_u64() as i64) + .bind(server.role_current.get() as i64) + .bind(server.bot_channel_id.get() as i64) .fetch_optional(db) .await; diff --git a/src/commands/link_email.rs b/src/commands/link_email.rs index a76769f..750e0ee 100644 --- a/src/commands/link_email.rs +++ b/src/commands/link_email.rs @@ -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::().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, user: &UserId) -> Option { @@ -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::().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, user: &UserId) -> Result, 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, 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 } diff --git a/src/commands/minecraft.rs b/src/commands/minecraft.rs index 45c4643..54bf35c 100644 --- a/src/commands/minecraft.rs +++ b/src/commands/minecraft.rs @@ -1,11 +1,4 @@ -use serenity::{ - builder::CreateApplicationCommand, - client::Context, - model::{ - application::interaction::application_command::ApplicationCommandInteraction, - prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue}, - }, -}; +use serenity::{builder::CreateCommand, client::Context}; use skynet_discord_bot::common::database::DataBase; use sqlx::{Pool, Sqlite}; @@ -16,33 +9,21 @@ pub(crate) mod user { use super::*; use crate::commands::link_email::link::get_server_member_discord; use serde::{Deserialize, Serialize}; + use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption}; use serenity::model::id::UserId; use skynet_discord_bot::common::database::Wolves; use skynet_discord_bot::common::minecraft::{whitelist_update, Minecraft}; use skynet_discord_bot::Config; use sqlx::Error; - pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("link_minecraft") + pub fn register() -> CreateCommand { + CreateCommand::new("link_minecraft") .description("Link your minecraft account") - .create_option(|option| { - option - .name("minecraft_username") - .description("Your Minecraft username") - .kind(CommandOptionType::String) - .required(true) - }) - .create_option(|option| { - option - .name("bedrock_account") - .description("Is this a Bedrock account?") - .kind(CommandOptionType::Boolean) - .required(false) - }) + .add_option(CreateCommandOption::new(CommandOptionType::String, "minecraft_username", "Your Minecraft username").required(true)) + .add_option(CreateCommandOption::new(CommandOptionType::Boolean, "bedrock_account", "Is this a Bedrock account?").required(false)) } - 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::().expect("Expected Databse in TypeMap.").clone() @@ -60,14 +41,10 @@ pub(crate) mod user { return "Not linked with wolves, please use ``/link_wolves`` with your wolves email.".to_string(); } - let username = if let CommandDataOptionValue::String(username) = command - .data - .options - .first() - .expect("Expected username option") - .resolved - .as_ref() - .expect("Expected username object") + let username = if let Some(CommandDataOption { + value: CommandDataOptionValue::String(username), + .. + }) = command.data.options.first() { username.trim() } else { @@ -75,12 +52,15 @@ pub(crate) mod user { }; // this is always true unless they state its not - let mut java = true; - if let Some(x) = command.data.options.get(1) { - if let Some(CommandDataOptionValue::Boolean(z)) = x.to_owned().resolved { - java = !z; - } - } + let java = if let Some(CommandDataOption { + value: CommandDataOptionValue::Boolean(z), + .. + }) = command.data.options.get(1) + { + !z + } else { + true + }; let username_mc; if java { @@ -130,7 +110,7 @@ pub(crate) mod user { WHERE discord = ?1; ", ) - .bind(*user.as_u64() as i64) + .bind(user.get() as i64) .bind(minecraft) .fetch_optional(db) .await @@ -175,7 +155,7 @@ pub(crate) mod user { WHERE discord = ?1; ", ) - .bind(*user.as_u64() as i64) + .bind(user.get() as i64) .bind(minecraft) .fetch_optional(db) .await @@ -194,7 +174,7 @@ pub(crate) mod user { ) sub on minecraft.server_discord = sub.server ", ) - .bind(*discord.as_u64() as i64) + .bind(discord.get() as i64) .fetch_all(db) .await } @@ -205,6 +185,7 @@ pub(crate) mod server { use super::*; pub(crate) mod add { + use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommand, CreateCommandOption}; use serenity::model::id::GuildId; use sqlx::Error; // this is to managfe the server side of commands related to minecraft @@ -213,17 +194,13 @@ pub(crate) mod server { use skynet_discord_bot::common::minecraft::Minecraft; use skynet_discord_bot::{is_admin, Config}; - pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command.name("minecraft_add").description("Add a minecraft server").create_option(|option| { - option - .name("server_id") - .description("ID of the Minecraft server hosted by the Computer Society") - .kind(CommandOptionType::String) - .required(true) - }) + pub fn register() -> CreateCommand { + CreateCommand::new("minecraft_add").description("Add a minecraft server").add_option( + CreateCommandOption::new(CommandOptionType::String, "server_id", "ID of the Minecraft server hosted by the Computer Society").required(true), + ) } - pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String { + pub async fn run(command: &CommandInteraction, ctx: &Context) -> String { // check if user has high enough permisssions if let Some(msg) = is_admin(command, ctx).await { return msg; @@ -233,16 +210,12 @@ pub(crate) mod server { Some(x) => x, }; - let server_minecraft = if let CommandDataOptionValue::String(id) = command - .data - .options - .first() - .expect("Expected server_id option") - .resolved - .as_ref() - .expect("Expected server_id object") + let server_minecraft = if let Some(CommandDataOption { + value: CommandDataOptionValue::String(id), + .. + }) = command.data.options.first() { - id.to_owned() + id.to_string() } else { return String::from("Expected Server ID"); }; @@ -279,7 +252,7 @@ pub(crate) mod server { VALUES (?1, ?2) ", ) - .bind(*discord.as_u64() as i64) + .bind(discord.get() as i64) .bind(minecraft) .fetch_optional(db) .await @@ -287,18 +260,18 @@ pub(crate) mod server { } pub(crate) mod list { - use serenity::builder::CreateApplicationCommand; + use serenity::all::CommandInteraction; + use serenity::builder::CreateCommand; use serenity::client::Context; - use serenity::model::prelude::application_command::ApplicationCommandInteraction; use skynet_discord_bot::common::database::DataBase; use skynet_discord_bot::common::minecraft::{get_minecraft_config_server, server_information}; use skynet_discord_bot::{is_admin, Config}; - pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command.name("minecraft_list").description("List your minecraft servers") + pub fn register() -> CreateCommand { + CreateCommand::new("minecraft_list").description("List your minecraft servers") } - pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String { + pub async fn run(command: &CommandInteraction, ctx: &Context) -> String { if let Some(msg) = is_admin(command, ctx).await { return msg; } @@ -348,27 +321,22 @@ pub(crate) mod server { } pub(crate) mod delete { - use serenity::builder::CreateApplicationCommand; + use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption}; + use serenity::builder::CreateCommand; use serenity::client::Context; - use serenity::model::application::command::CommandOptionType; use serenity::model::id::GuildId; - use serenity::model::prelude::application_command::{ApplicationCommandInteraction, CommandDataOptionValue}; use skynet_discord_bot::common::database::DataBase; use skynet_discord_bot::common::minecraft::Minecraft; use skynet_discord_bot::is_admin; use sqlx::{Error, Pool, Sqlite}; - pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command.name("minecraft_delete").description("Delete a minecraft server").create_option(|option| { - option - .name("server_id") - .description("ID of the Minecraft server hosted by the Computer Society") - .kind(CommandOptionType::String) - .required(true) - }) + pub fn register() -> CreateCommand { + CreateCommand::new("minecraft_delete").description("Delete a minecraft server").add_option( + CreateCommandOption::new(CommandOptionType::String, "server_id", "ID of the Minecraft server hosted by the Computer Society").required(true), + ) } - pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String { + pub async fn run(command: &CommandInteraction, ctx: &Context) -> String { // check if user has high enough permisssions if let Some(msg) = is_admin(command, ctx).await { return msg; @@ -378,16 +346,12 @@ pub(crate) mod server { Some(x) => x, }; - let server_minecraft = if let CommandDataOptionValue::String(id) = command - .data - .options - .first() - .expect("Expected server_id option") - .resolved - .as_ref() - .expect("Expected server_id object") + let server_minecraft = if let Some(CommandDataOption { + value: CommandDataOptionValue::String(id), + .. + }) = command.data.options.first() { - id.to_owned() + id.to_string() } else { return String::from("Expected Server ID"); }; @@ -418,7 +382,7 @@ pub(crate) mod server { WHERE server_discord = ?1 AND server_minecraft = ?2 ", ) - .bind(*discord.as_u64() as i64) + .bind(discord.get() as i64) .bind(minecraft) .fetch_optional(db) .await diff --git a/src/commands/role_adder.rs b/src/commands/role_adder.rs index d45d445..182eeb9 100644 --- a/src/commands/role_adder.rs +++ b/src/commands/role_adder.rs @@ -1,11 +1,4 @@ -use serenity::{ - builder::CreateApplicationCommand, - client::Context, - model::{ - application::interaction::application_command::ApplicationCommandInteraction, - prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue}, - }, -}; +use serenity::client::Context; use skynet_discord_bot::common::database::{DataBase, RoleAdder}; use skynet_discord_bot::is_admin; @@ -13,51 +6,40 @@ use sqlx::{Error, Pool, Sqlite}; pub mod edit { use super::*; + 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 { // check if user has high enough permisssions if let Some(msg) = is_admin(command, ctx).await { return msg; } - let role_a = if let CommandDataOptionValue::Role(role) = command - .data - .options - .first() - .expect("Expected role option") - .resolved - .as_ref() - .expect("Expected role object") + let role_a = if let Some(CommandDataOption { + value: CommandDataOptionValue::Role(role), + .. + }) = command.data.options.first() { - role.id.to_owned() + role.to_owned() } else { return "Please provide a valid role for ``Role Current``".to_string(); }; - let role_b = if let CommandDataOptionValue::Role(role) = command - .data - .options - .get(1) - .expect("Expected role option") - .resolved - .as_ref() - .expect("Expected role object") + let role_b = if let Some(CommandDataOption { + value: CommandDataOptionValue::Role(role), + .. + }) = command.data.options.get(1) { - role.id.to_owned() + role.to_owned() } else { return "Please provide a valid role for ``Role Current``".to_string(); }; - let role_c = if let CommandDataOptionValue::Role(role) = command - .data - .options - .get(2) - .expect("Expected role option") - .resolved - .as_ref() - .expect("Expected role object") + let role_c = if let Some(CommandDataOption { + value: CommandDataOptionValue::Role(role), + .. + }) = command.data.options.get(2) { - role.id.to_owned() + role.to_owned() } else { return "Please provide a valid role for ``Role Current``".to_string(); }; @@ -70,14 +52,15 @@ pub mod edit { return "Role C cannot be same as A or B".to_string(); } - let mut delete = false; - - if let Some(x) = command.data.options.get(3) { - let tmp = x.to_owned(); - if let Some(CommandDataOptionValue::Boolean(z)) = tmp.resolved { - delete = z; - } - } + let delete = if let Some(CommandDataOption { + value: CommandDataOptionValue::Boolean(z), + .. + }) = command.data.options.get(3) + { + *z + } else { + false + }; let db_lock = { let data_read = ctx.data.read().await; @@ -124,32 +107,13 @@ pub mod edit { } } - pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("roles_adder") + pub fn register() -> CreateCommand { + CreateCommand::new("roles_adder") .description("Combine roles together to an new one") - .create_option(|option| { - option - .name("role_a") - .description("A role you want to add to Role B") - .kind(CommandOptionType::Role) - .required(true) - }) - .create_option(|option| { - option - .name("role_b") - .description("A role you want to add to Role A") - .kind(CommandOptionType::Role) - .required(true) - }) - .create_option(|option| option.name("role_c").description("Sum of A and B").kind(CommandOptionType::Role).required(true)) - .create_option(|option| { - option - .name("delete") - .description("Delete this entry.") - .kind(CommandOptionType::Boolean) - .required(false) - }) + .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_a", "A role you want to add to Role B").required(true)) + .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_b", "A role you want to add to Role A").required(true)) + .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_c", "Sum of A and B").required(true)) + .add_option(CreateCommandOption::new(CommandOptionType::Boolean, "delete", "Delete this entry.").required(false)) } async fn add_server(db: &Pool, server: &RoleAdder, delete: bool) -> Result, Error> { @@ -160,10 +124,10 @@ pub mod edit { WHERE server = ?1 AND role_a = ?2 AND role_b = ?3 AND role_c = ?4 ", ) - .bind(*server.server.as_u64() as i64) - .bind(*server.role_a.as_u64() as i64) - .bind(*server.role_b.as_u64() as i64) - .bind(*server.role_c.as_u64() as i64) + .bind(server.server.get() as i64) + .bind(server.role_a.get() as i64) + .bind(server.role_b.get() as i64) + .bind(server.role_c.get() as i64) .fetch_optional(db) .await } else { @@ -173,10 +137,10 @@ pub mod edit { VALUES (?1, ?2, ?3, ?4) ", ) - .bind(*server.server.as_u64() as i64) - .bind(*server.role_a.as_u64() as i64) - .bind(*server.role_b.as_u64() as i64) - .bind(*server.role_c.as_u64() as i64) + .bind(server.server.get() as i64) + .bind(server.role_a.get() as i64) + .bind(server.role_b.get() as i64) + .bind(server.role_c.get() as i64) .fetch_optional(db) .await } @@ -192,7 +156,7 @@ pub mod tools { use skynet_discord_bot::common::database::RoleAdder; use sqlx::{Pool, Sqlite}; - pub async fn on_role_change(db: &Pool, ctx: &Context, mut new_data: Member) { + pub async fn on_role_change(db: &Pool, ctx: &Context, new_data: Member) { // check if the role changed is part of the oens for this server if let Ok(role_adders) = sqlx::query_as::<_, RoleAdder>( r#" @@ -201,7 +165,7 @@ pub mod tools { WHERE server = ? "#, ) - .bind(*new_data.guild_id.as_u64() as i64) + .bind(new_data.guild_id.get() as i64) .fetch_all(db) .await { diff --git a/src/common/database.rs b/src/common/database.rs index fb413e2..596b411 100644 --- a/src/common/database.rs +++ b/src/common/database.rs @@ -194,7 +194,7 @@ fn get_role_from_row(row: &SqliteRow, col: &str) -> RoleId { match row.try_get(col) { Ok(x) => { let tmp: i64 = x; - RoleId(tmp as u64) + RoleId::new(tmp as u64) } _ => RoleId::from(0u64), } @@ -226,7 +226,7 @@ pub async fn get_server_config(db: &Pool, server: &GuildId) -> Option, server: &GuildId, member: &gui WHERE server = ? AND discord = ? "#, ) - .bind(*server.as_u64() as i64) - .bind(*member.user.id.as_u64() as i64) + .bind(server.get() as i64) + .bind(member.user.id.get() as i64) .fetch_one(db) .await } diff --git a/src/common/minecraft.rs b/src/common/minecraft.rs index 7b27d36..4faa8ed 100644 --- a/src/common/minecraft.rs +++ b/src/common/minecraft.rs @@ -148,7 +148,7 @@ pub async fn get_minecraft_config_server(db: &Pool, g_id: GuildId) -> Ve WHERE server_discord = ?1 "#, ) - .bind(*g_id.as_u64() as i64) + .bind(g_id.get() as i64) .fetch_all(db) .await .unwrap_or_default() diff --git a/src/common/set_roles.rs b/src/common/set_roles.rs index 9ebd39e..d47313d 100644 --- a/src/common/set_roles.rs +++ b/src/common/set_roles.rs @@ -31,7 +31,7 @@ pub mod normal { let mut members_all = members.len(); if let Ok(x) = server.members(ctx, None, None).await { - for mut member in x { + for member in x { // members_changed acts as an override to only deal with teh users in it if !members_changed.is_empty() && !members_changed.contains(&member.user.id) { continue; @@ -83,7 +83,7 @@ pub mod normal { set_server_numbers(&db, server, members_all as i64, members.len() as i64).await; // small bit of logging to note changes over time - println!("{:?} Changes: New: +{}, Current: +{}/-{}", server.as_u64(), roles_set[0], roles_set[1], roles_set[2]); + println!("{:?} Changes: New: +{}, Current: +{}/-{}", server.get(), roles_set[0], roles_set[1], roles_set[2]); } pub async fn get_server_member_bulk(db: &Pool, server: &GuildId) -> Vec { @@ -99,7 +99,7 @@ pub mod normal { ) "#, ) - .bind(*server.as_u64() as i64) + .bind(server.get() as i64) .bind(get_now_iso(true)) .fetch_all(db) .await @@ -116,13 +116,13 @@ pub mod normal { ) .bind(past) .bind(current) - .bind(*server.as_u64() as i64) + .bind(server.get() as i64) .fetch_optional(db) .await { Ok(_) => {} Err(e) => { - println!("Failure to insert into {}", server.as_u64()); + println!("Failure to insert into {}", server.get()); println!("{:?}", e); } } @@ -134,6 +134,8 @@ pub mod committee { use crate::common::database::{DataBase, Wolves}; use crate::common::wolves::committees::Committees; use crate::Config; + use serenity::all::EditRole; + use serenity::builder::CreateChannel; use serenity::client::Context; use serenity::model::channel::ChannelType; use serenity::model::guild::Member; @@ -170,9 +172,16 @@ pub mod committee { */ pub async fn update_committees(db: &Pool, ctx: &Context, config: &Config, members: &mut Vec) { let server = config.committee_server; - let committee_member = config.committee_role; + let committee_member = RoleId::new(1226602779968274573); let committees = get_committees(db).await; - let categories = vec![config.committee_category, ChannelId(1341457244973305927), ChannelId(1341457509717639279)]; + let categories = vec![ + // C&S Chats 1 + ChannelId::new(1226606560973815839), + // C&S Chats 2 + ChannelId::new(1341457244973305927), + // C&S Chats 3 + ChannelId::new(1341457509717639279), + ]; // information about the server let roles = server.roles(&ctx).await.unwrap_or_default(); @@ -216,7 +225,10 @@ pub mod committee { Some(x) => Some(x.to_owned()), None => { // create teh role if it does not exist - match server.create_role(&ctx, |r| r.hoist(false).mentionable(true).name(&committee.name_full)).await { + match server + .create_role(&ctx, EditRole::new().name(&committee.name_full).hoist(false).mentionable(true)) + .await + { Ok(x) => Some(x), Err(_) => None, } @@ -226,7 +238,12 @@ pub mod committee { // create teh channel if it does nto exist if !channels_name.contains_key(&committee.name_profile) { match server - .create_channel(&ctx, |c| c.name(&committee.name_profile).kind(ChannelType::Text).category(categories[category_index])) + .create_channel( + &ctx, + CreateChannel::new(&committee.name_profile) + .kind(ChannelType::Text) + .category(categories[category_index]), + ) .await { Ok(x) => { @@ -277,7 +294,7 @@ pub mod committee { Some(x) => { let mut tmp = x.to_owned(); if !tmp.is_empty() { - tmp.push(RoleId(1226602779968274573)); + tmp.push(committee_member); } tmp } @@ -309,7 +326,7 @@ pub mod committee { // these roles are flavor roles, only there to make folks mentionable member.add_roles(&ctx, &roles_add).await.unwrap_or_default(); } else { - member.remove_roles(&ctx, &[RoleId(1226602779968274573)]).await.unwrap_or_default(); + member.remove_roles(&ctx, &[committee_member]).await.unwrap_or_default(); } } @@ -347,8 +364,9 @@ pub mod committee { FROM committees "#, ) - .fetch_all(db) - .await.unwrap_or_else(|e| { + .fetch_all(db) + .await + .unwrap_or_else(|e| { dbg!(e); vec![] }) diff --git a/src/common/wolves.rs b/src/common/wolves.rs index 9141983..ea64699 100644 --- a/src/common/wolves.rs +++ b/src/common/wolves.rs @@ -144,13 +144,13 @@ pub mod cns { ", ) .bind(name) - .bind(*server.as_u64() as i64) + .bind(server.get() as i64) .fetch_optional(db) .await { Ok(_) => {} Err(e) => { - println!("Failure to set server name {}", server.as_u64()); + println!("Failure to set server name {}", server.get()); println!("{:?}", e); } } @@ -168,7 +168,7 @@ pub mod cns { ) "#, ) - .bind(*server.as_u64() as i64) + .bind(server.get() as i64) .fetch_all(db) .await .unwrap_or_default() @@ -181,7 +181,7 @@ pub mod cns { VALUES (?1, ?2, ?3) ", ) - .bind(*server.as_u64() as i64) + .bind(server.get() as i64) .bind(&user.member_id) .bind(&user.expiry) .fetch_optional(db) @@ -189,7 +189,7 @@ pub mod cns { { Ok(_) => {} Err(e) => { - println!("Failure to insert into ServerMembers {} {:?}", server.as_u64(), user); + println!("Failure to insert into ServerMembers {} {:?}", server.get(), user); println!("{:?}", e); } } diff --git a/src/lib.rs b/src/lib.rs index 5611a21..ba86483 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,9 +3,9 @@ pub mod common; use chrono::{Datelike, SecondsFormat, Utc}; use dotenvy::dotenv; use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use serenity::all::CommandInteraction; use serenity::client::Context; use serenity::model::id::{ChannelId, GuildId, RoleId}; -use serenity::model::prelude::application_command::ApplicationCommandInteraction; use serenity::prelude::TypeMapKey; use std::{env, sync::Arc}; use tokio::sync::RwLock; @@ -57,9 +57,9 @@ pub fn get_config() -> Config { mail_pass: "".to_string(), wolves_url: "".to_string(), wolves_api: "".to_string(), - committee_server: GuildId(0), - committee_role: RoleId(0), - committee_category: ChannelId(0), + committee_server: GuildId::new(0), + committee_role: RoleId::new(0), + committee_category: ChannelId::new(0), }; if let Ok(x) = env::var("DATABASE_HOME") { @@ -98,17 +98,17 @@ pub fn get_config() -> Config { if let Ok(x) = env::var("COMMITTEE_DISCORD") { if let Ok(x) = x.trim().parse::() { - config.committee_server = GuildId(x); + config.committee_server = GuildId::new(x); } } if let Ok(x) = env::var("COMMITTEE_DISCORD") { if let Ok(x) = x.trim().parse::() { - config.committee_role = RoleId(x); + config.committee_role = RoleId::new(x); } } if let Ok(x) = env::var("COMMITTEE_CATEGORY") { if let Ok(x) = x.trim().parse::() { - config.committee_category = ChannelId(x); + config.committee_category = ChannelId::new(x); } } @@ -131,7 +131,7 @@ pub fn random_string(len: usize) -> String { /** For any time ye need to check if a user who calls a command has admin privlages */ -pub async fn is_admin(command: &ApplicationCommandInteraction, ctx: &Context) -> Option { +pub async fn is_admin(command: &CommandInteraction, ctx: &Context) -> Option { let mut admin = false; let g_id = match command.guild_id { diff --git a/src/main.rs b/src/main.rs index 8b1b20a..36316d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,13 @@ pub mod commands; use crate::commands::role_adder::tools::on_role_change; +use serenity::all::{ActivityData, Command, CreateMessage, EditInteractionResponse, GuildMemberUpdateEvent, Interaction}; use serenity::model::guild::Member; use serenity::{ async_trait, client::{Context, EventHandler}, model::{ - application::{command::Command, interaction::Interaction}, gateway::{GatewayIntents, Ready}, - prelude::Activity, user::OnlineStatus, }, Client, @@ -26,7 +25,7 @@ struct Handler; #[async_trait] impl EventHandler for Handler { // handles previously linked accounts joining the server - async fn guild_member_addition(&self, ctx: Context, mut new_member: Member) { + async fn guild_member_addition(&self, ctx: Context, new_member: Member) { let db_lock = { let data_read = ctx.data.read().await; data_read.get::().expect("Expected Config in TypeMap.").clone() @@ -84,7 +83,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use &config_server.bot_channel_id ); - if let Err(err) = new_member.user.direct_message(&ctx, |m| m.content(&msg)).await { + if let Err(err) = new_member.user.direct_message(&ctx, CreateMessage::new().content(&msg)).await { dbg!(err); } } @@ -92,7 +91,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use } // handles role updates - async fn guild_member_update(&self, ctx: Context, _old_data: Option, new_data: Member) { + async fn guild_member_update(&self, ctx: Context, _old_data: Option, new_data: Option, _: GuildMemberUpdateEvent) { // get config/db let db_lock = { let data_read = ctx.data.read().await; @@ -102,24 +101,28 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use let db = db_lock.read().await; // check if the role changed is part of the oens for this server - on_role_change(&db, &ctx, new_data).await; + if let Some(x) = new_data { + on_role_change(&db, &ctx, x).await; + } } async fn ready(&self, ctx: Context, ready: Ready) { println!("[Main] {} is connected!", ready.user.name); - ctx.set_presence(Some(Activity::playing("with humanity's fate")), OnlineStatus::Online).await; + ctx.set_presence(Some(ActivityData::playing("with humanity's fate")), OnlineStatus::Online); - match Command::set_global_application_commands(&ctx.http, |commands| { - commands - .create_application_command(|command| commands::add_server::register(command)) - .create_application_command(|command| commands::role_adder::edit::register(command)) - .create_application_command(|command| commands::link_email::link::register(command)) - .create_application_command(|command| commands::link_email::verify::register(command)) - .create_application_command(|command| commands::minecraft::server::add::register(command)) - .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)) - }) + match Command::set_global_commands( + &ctx.http, + vec![ + commands::add_server::register(), + commands::role_adder::edit::register(), + commands::link_email::link::register(), + commands::link_email::verify::register(), + commands::minecraft::server::add::register(), + commands::minecraft::server::list::register(), + commands::minecraft::server::delete::register(), + commands::minecraft::user::add::register(), + ], + ) .await { Ok(_) => {} @@ -130,7 +133,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use } async fn interaction_create(&self, ctx: Context, interaction: Interaction) { - if let Interaction::ApplicationCommand(command) = interaction { + if let Interaction::Command(command) = interaction { let _ = command.defer_ephemeral(&ctx.http).await; //println!("Received command interaction: {:#?}", command); @@ -148,7 +151,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use _ => "not implemented :(".to_string(), }; - if let Err(why) = command.edit_original_interaction_response(&ctx.http, |response| response.content(content)).await { + if let Err(why) = command.edit_response(&ctx.http, EditInteractionResponse::new().content(content)).await { println!("Cannot respond to slash command: {}", why); } }