feat: bumped serenity to the latest version

Lots of changes to how it runs
This commit is contained in:
silver 2025-02-19 00:17:02 +00:00
parent a8c1cc9cf1
commit 6b84f33d2e
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
12 changed files with 352 additions and 485 deletions

255
Cargo.lock generated
View file

@ -111,6 +111,15 @@ version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
[[package]]
name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "async-channel" name = "async-channel"
version = "1.9.0" version = "1.9.0"
@ -257,22 +266,6 @@ dependencies = [
"syn 2.0.89", "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]] [[package]]
name = "atoi" name = "atoi"
version = "2.0.0" version = "2.0.0"
@ -629,6 +622,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "data-encoding"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "575f75dfd25738df5b91b8e43e14d44bda14637a58fae779fd2b064f8bf3e010"
[[package]] [[package]]
name = "der" name = "der"
version = "0.7.9" version = "0.7.9"
@ -815,7 +814,7 @@ checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"spin 0.9.8", "spin",
] ]
[[package]] [[package]]
@ -975,6 +974,15 @@ dependencies = [
"slab", "slab",
] ]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.7"
@ -1298,7 +1306,7 @@ dependencies = [
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project-lite", "pin-project-lite",
"socket2 0.4.10", "socket2 0.5.7",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing", "tracing",
@ -1518,7 +1526,7 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
dependencies = [ dependencies = [
"spin 0.9.8", "spin",
] ]
[[package]] [[package]]
@ -1846,15 +1854,6 @@ dependencies = [
"vcpkg", "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]] [[package]]
name = "parking" name = "parking"
version = "2.2.1" version = "2.2.1"
@ -2237,21 +2236,6 @@ dependencies = [
"windows-registry", "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]] [[package]]
name = "ring" name = "ring"
version = "0.17.8" version = "0.17.8"
@ -2262,8 +2246,8 @@ dependencies = [
"cfg-if", "cfg-if",
"getrandom 0.2.15", "getrandom 0.2.15",
"libc", "libc",
"spin 0.9.8", "spin",
"untrusted 0.9.0", "untrusted",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@ -2315,18 +2299,6 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "rustls" name = "rustls"
version = "0.21.12" version = "0.21.12"
@ -2334,11 +2306,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e"
dependencies = [ dependencies = [
"log", "log",
"ring 0.17.8", "ring",
"rustls-webpki 0.101.7", "rustls-webpki 0.101.7",
"sct", "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]] [[package]]
name = "rustls" name = "rustls"
version = "0.23.18" version = "0.23.18"
@ -2382,8 +2368,8 @@ version = "0.101.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765"
dependencies = [ dependencies = [
"ring 0.17.8", "ring",
"untrusted 0.9.0", "untrusted",
] ]
[[package]] [[package]]
@ -2392,9 +2378,9 @@ version = "0.102.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9"
dependencies = [ dependencies = [
"ring 0.17.8", "ring",
"rustls-pki-types", "rustls-pki-types",
"untrusted 0.9.0", "untrusted",
] ]
[[package]] [[package]]
@ -2424,8 +2410,18 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414"
dependencies = [ dependencies = [
"ring 0.17.8", "ring",
"untrusted 0.9.0", "untrusted",
]
[[package]]
name = "secrecy"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e"
dependencies = [
"serde",
"zeroize",
] ]
[[package]] [[package]]
@ -2476,12 +2472,11 @@ dependencies = [
] ]
[[package]] [[package]]
name = "serde-value" name = "serde_cow"
version = "0.7.0" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" checksum = "1e7bbbec7196bfde255ab54b65e34087c0849629280028238e67ee25d6a4b7da"
dependencies = [ dependencies = [
"ordered-float",
"serde", "serde",
] ]
@ -2533,45 +2528,35 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.11.7" version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a7a89cef23483fc9d4caf2df41e6d3928e18aada84c56abd237439d929622c6" checksum = "3d72ec4323681bf9a3cabe40fd080abc2435859b502a1b5aa9bf693f125bfa76"
dependencies = [ dependencies = [
"arrayvec",
"async-trait", "async-trait",
"async-tungstenite", "base64 0.22.1",
"base64 0.21.7", "bitflags 2.6.0",
"bitflags 1.3.2",
"bytes 1.7.1", "bytes 1.7.1",
"cfg-if",
"dashmap", "dashmap",
"flate2", "flate2",
"futures", "futures",
"mime", "fxhash",
"mime_guess", "mime_guess",
"parking_lot", "parking_lot",
"percent-encoding", "percent-encoding",
"reqwest 0.11.27", "reqwest 0.11.27",
"secrecy",
"serde", "serde",
"serde-value", "serde_cow",
"serde_json", "serde_json",
"time 0.3.36", "time 0.3.36",
"tokio", "tokio",
"tokio-tungstenite",
"tracing", "tracing",
"typemap_rev", "typemap_rev",
"url", "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]] [[package]]
name = "sha1" name = "sha1"
version = "0.6.1" version = "0.6.1"
@ -2711,12 +2696,6 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "spin" name = "spin"
version = "0.9.8" version = "0.9.8"
@ -3281,17 +3260,6 @@ dependencies = [
"tokio", "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]] [[package]]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.24.1" version = "0.24.1"
@ -3302,6 +3270,17 @@ dependencies = [
"tokio", "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]] [[package]]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.26.0" version = "0.26.0"
@ -3337,6 +3316,22 @@ dependencies = [
"tokio-stream", "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]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.12" version = "0.7.12"
@ -3406,30 +3401,30 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]] [[package]]
name = "tungstenite" name = "tungstenite"
version = "0.17.3" version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1"
dependencies = [ dependencies = [
"base64 0.13.1",
"byteorder", "byteorder",
"bytes 1.7.1", "bytes 1.7.1",
"http 0.2.12", "data-encoding",
"http 1.1.0",
"httparse", "httparse",
"log", "log",
"rand 0.8.5", "rand 0.8.5",
"rustls 0.20.9", "rustls 0.22.4",
"sha-1", "rustls-pki-types",
"sha1 0.10.6",
"thiserror", "thiserror",
"url", "url",
"utf-8", "utf-8",
"webpki",
] ]
[[package]] [[package]]
name = "typemap_rev" name = "typemap_rev"
version = "0.1.5" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5b74f0a24b5454580a79abb6994393b09adf0ab8070f15827cb666255de155" checksum = "74b08b0c1257381af16a5c3605254d529d3e7e109f3c62befc5d168968192998"
[[package]] [[package]]
name = "typenum" name = "typenum"
@ -3495,12 +3490,6 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]] [[package]]
name = "untrusted" name = "untrusted"
version = "0.9.0" version = "0.9.0"
@ -3672,31 +3661,21 @@ dependencies = [
"wasm-bindgen", "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]] [[package]]
name = "webpki-roots" name = "webpki-roots"
version = "0.25.4" version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" 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]] [[package]]
name = "whoami" name = "whoami"
version = "1.5.2" version = "1.5.2"

View file

@ -16,7 +16,7 @@ name = "update_minecraft"
[dependencies] [dependencies]
# discord library # 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"] } tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "full"] }
# wolves api # wolves api

View file

@ -1,68 +1,53 @@
use serenity::{ use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption};
builder::CreateApplicationCommand, use serenity::{builder::CreateCommand, client::Context};
client::Context,
model::{
application::interaction::application_command::ApplicationCommandInteraction,
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
},
};
use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers}; 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::set_roles::normal::update_server;
use skynet_discord_bot::common::wolves::cns::get_wolves; use skynet_discord_bot::common::wolves::cns::get_wolves;
use skynet_discord_bot::is_admin; use skynet_discord_bot::is_admin;
use sqlx::{Error, Pool, Sqlite}; 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 // check if user has high enough permisssions
if let Some(msg) = is_admin(command, ctx).await { if let Some(msg) = is_admin(command, ctx).await {
return msg; return msg;
} }
let api_key = if let CommandDataOptionValue::String(key) = command let wolves_api = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::String(key),
.options ..
.first() }) = command.data.options.first()
.expect("Expected user option")
.resolved
.as_ref()
.expect("Expected user object")
{ {
key key.to_string()
} else { } else {
return "Please provide a wolves API key".to_string(); return "Please provide a wolves API key".to_string();
}; };
let role_current = if let CommandDataOptionValue::Role(role) = command let role_current = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::Role(role),
.options ..
.get(1) }) = command.data.options.get(1)
.expect("Expected role option")
.resolved
.as_ref()
.expect("Expected role object")
{ {
role.id.to_owned() role.to_owned()
} else { } else {
return "Please provide a valid role for ``Role Current``".to_string(); return "Please provide a valid role for ``Role Current``".to_string();
}; };
let mut role_past = None; let role_past = if let Some(CommandDataOption {
if let Some(x) = command.data.options.get(5) { value: CommandDataOptionValue::Role(role),
if let Some(CommandDataOptionValue::Role(role)) = &x.resolved { ..
role_past = Some(role.id.to_owned()); }) = command.data.options.get(5)
} {
Some(role.to_owned())
} else {
None
}; };
let bot_channel_id = if let CommandDataOptionValue::Channel(channel) = command let bot_channel_id = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::Channel(channel),
.options ..
.get(2) }) = command.data.options.get(2)
.expect("Expected channel option")
.resolved
.as_ref()
.expect("Expected channel object")
{ {
channel.id.to_owned() channel.to_owned()
} else { } else {
return "Please provide a valid channel for ``Bot Channel``".to_string(); 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 { let server_data = Servers {
server: command.guild_id.unwrap_or_default(), server: command.guild_id.unwrap_or_default(),
wolves_api: api_key.to_owned(), wolves_api,
role_past, role_past,
role_current, role_current,
member_past: 0, member_past: 0,
@ -95,43 +80,18 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
"Added/Updated server info".to_string() "Added/Updated server info".to_string()
} }
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register() -> CreateCommand {
command CreateCommand::new("add")
.name("add")
.description("Enable the bot for this discord") .description("Enable the bot for this discord")
.create_option(|option| { .add_option(CreateCommandOption::new(CommandOptionType::String, "api_key", "UL Wolves API Key").required(true))
option .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_current", "Role for Current members").required(true))
.name("api_key") .add_option(CreateCommandOption::new(CommandOptionType::Channel, "bot_channel", "Safe space for folks to use the bot commands.").required(true))
.description("UL Wolves API Key") .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_past", "Role for Past members").required(false))
.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)
})
} }
async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Result<Option<Servers>, Error> { async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Result<Option<Servers>, Error> {
let existing = get_server_config(db, &server.server).await; 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>( let insert = sqlx::query_as::<_, Servers>(
" "
@ -139,11 +99,11 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
VALUES (?1, ?2, ?3, ?4, ?5) VALUES (?1, ?2, ?3, ?4, ?5)
", ",
) )
.bind(*server.server.as_u64() as i64) .bind(server.server.get() as i64)
.bind(&server.wolves_api) .bind(&server.wolves_api)
.bind(role_past) .bind(role_past)
.bind(*server.role_current.as_u64() as i64) .bind(server.role_current.get() as i64)
.bind(*server.bot_channel_id.as_u64() as i64) .bind(server.bot_channel_id.get() as i64)
.fetch_optional(db) .fetch_optional(db)
.await; .await;

View file

@ -4,15 +4,7 @@ use lettre::{
Message, SmtpTransport, Transport, Message, SmtpTransport, Transport,
}; };
use maud::html; use maud::html;
use serenity::{ use serenity::{builder::CreateCommand, client::Context, model::id::UserId};
builder::CreateApplicationCommand,
client::Context,
model::{
application::interaction::application_command::ApplicationCommandInteraction,
id::UserId,
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
},
};
use skynet_discord_bot::common::database::{DataBase, Wolves, WolvesVerify}; use skynet_discord_bot::common::database::{DataBase, Wolves, WolvesVerify};
use skynet_discord_bot::{get_now_iso, random_string, Config}; use skynet_discord_bot::{get_now_iso, random_string, Config};
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
@ -20,8 +12,9 @@ use sqlx::{Pool, Sqlite};
pub mod link { pub mod link {
use super::*; use super::*;
use serde::{Deserialize, Serialize}; 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 db_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone() 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(); return "Linking already in process, please check email.".to_string();
} }
let option = command let email = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::String(email),
.options ..
.first() }) = command.data.options.first()
.expect("Expected email option") {
.resolved
.as_ref()
.expect("Expected email object");
let email = if let CommandDataOptionValue::String(email) = option {
email.trim() email.trim()
} else { } else {
return "Please provide a valid user".to_string(); 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) 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 { pub fn register() -> CreateCommand {
command CreateCommand::new("link_wolves")
.name("link_wolves")
.description("Set Wolves Email") .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> { pub async fn get_server_member_discord(db: &Pool<Sqlite>, user: &UserId) -> Option<Wolves> {
@ -130,7 +117,7 @@ pub mod link {
WHERE discord = ? WHERE discord = ?
"#, "#,
) )
.bind(*user.as_u64() as i64) .bind(user.get() as i64)
.fetch_one(db) .fetch_one(db)
.await .await
.ok() .ok()
@ -242,7 +229,7 @@ pub mod link {
WHERE discord = ? WHERE discord = ?
"#, "#,
) )
.bind(*user.as_u64() as i64) .bind(user.get() as i64)
.fetch_one(db) .fetch_one(db)
.await .await
.ok() .ok()
@ -256,7 +243,7 @@ pub mod link {
", ",
) )
.bind(record.email.to_owned()) .bind(record.email.to_owned())
.bind(*user.as_u64() as i64) .bind(user.get() as i64)
.bind(auth.to_owned()) .bind(auth.to_owned())
.bind(get_now_iso(false)) .bind(get_now_iso(false))
.fetch_optional(db) .fetch_optional(db)
@ -294,12 +281,13 @@ pub mod link {
pub mod verify { pub mod verify {
use super::*; use super::*;
use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db}; 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 serenity::model::user::User;
use skynet_discord_bot::common::database::get_server_config; use skynet_discord_bot::common::database::get_server_config;
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers}; use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
use sqlx::Error; 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 db_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone() 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(); return "Please use /link_wolves first".to_string();
}; };
let option = command let code = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::String(code),
.options ..
.first() }) = command.data.options.first()
.expect("Expected code option") {
.resolved
.as_ref()
.expect("Expected code object");
let code = if let CommandDataOptionValue::String(code) = option {
code code
} else { } else {
return "Please provide a verification code".to_string(); return "Please provide a verification code".to_string();
@ -354,14 +337,10 @@ pub mod verify {
"Failed to verify".to_string() "Failed to verify".to_string()
} }
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register() -> CreateCommand {
command.name("verify").description("Verify Wolves Email").create_option(|option| { CreateCommand::new("verify")
option .description("Verify Wolves Email")
.name("code") .add_option(CreateCommandOption::new(CommandOptionType::String, "code", "Code from verification email").required(true))
.description("Code from verification email")
.kind(CommandOptionType::String)
.required(true)
})
} }
async fn db_pending_clear_successful(pool: &Pool<Sqlite>, user: &UserId) -> Result<Option<WolvesVerify>, Error> { async fn db_pending_clear_successful(pool: &Pool<Sqlite>, user: &UserId) -> Result<Option<WolvesVerify>, Error> {
@ -372,7 +351,7 @@ pub mod verify {
WHERE discord = ? WHERE discord = ?
"#, "#,
) )
.bind(*user.as_u64() as i64) .bind(user.get() as i64)
.fetch_optional(pool) .fetch_optional(pool)
.await .await
} }
@ -385,7 +364,7 @@ pub mod verify {
WHERE email = ? WHERE email = ?
", ",
) )
.bind(*discord.as_u64() as i64) .bind(discord.get() as i64)
.bind(email) .bind(email)
.fetch_optional(db) .fetch_optional(db)
.await .await
@ -394,7 +373,7 @@ pub mod verify {
async fn set_server_roles(db: &Pool<Sqlite>, discord: &User, ctx: &Context) { async fn set_server_roles(db: &Pool<Sqlite>, discord: &User, ctx: &Context) {
if let Ok(servers) = get_servers(db, &discord.id).await { if let Ok(servers) = get_servers(db, &discord.id).await {
for server in servers { 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 { if let Some(config) = get_server_config(db, &server.server).await {
let Servers { let Servers {
role_past, role_past,
@ -432,7 +411,7 @@ pub mod verify {
WHERE discord = ? WHERE discord = ?
", ",
) )
.bind(*discord.as_u64() as i64) .bind(discord.get() as i64)
.fetch_all(db) .fetch_all(db)
.await .await
} }

View file

@ -1,11 +1,4 @@
use serenity::{ use serenity::{builder::CreateCommand, client::Context};
builder::CreateApplicationCommand,
client::Context,
model::{
application::interaction::application_command::ApplicationCommandInteraction,
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
},
};
use skynet_discord_bot::common::database::DataBase; use skynet_discord_bot::common::database::DataBase;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
@ -16,33 +9,21 @@ pub(crate) mod user {
use super::*; use super::*;
use crate::commands::link_email::link::get_server_member_discord; use crate::commands::link_email::link::get_server_member_discord;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption};
use serenity::model::id::UserId; use serenity::model::id::UserId;
use skynet_discord_bot::common::database::Wolves; use skynet_discord_bot::common::database::Wolves;
use skynet_discord_bot::common::minecraft::{whitelist_update, Minecraft}; use skynet_discord_bot::common::minecraft::{whitelist_update, Minecraft};
use skynet_discord_bot::Config; use skynet_discord_bot::Config;
use sqlx::Error; use sqlx::Error;
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register() -> CreateCommand {
command CreateCommand::new("link_minecraft")
.name("link_minecraft")
.description("Link your minecraft account") .description("Link your minecraft account")
.create_option(|option| { .add_option(CreateCommandOption::new(CommandOptionType::String, "minecraft_username", "Your Minecraft username").required(true))
option .add_option(CreateCommandOption::new(CommandOptionType::Boolean, "bedrock_account", "Is this a Bedrock account?").required(false))
.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)
})
} }
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String { pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
let db_lock = { let db_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone() data_read.get::<DataBase>().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(); return "Not linked with wolves, please use ``/link_wolves`` with your wolves email.".to_string();
} }
let username = if let CommandDataOptionValue::String(username) = command let username = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::String(username),
.options ..
.first() }) = command.data.options.first()
.expect("Expected username option")
.resolved
.as_ref()
.expect("Expected username object")
{ {
username.trim() username.trim()
} else { } else {
@ -75,12 +52,15 @@ pub(crate) mod user {
}; };
// this is always true unless they state its not // this is always true unless they state its not
let mut java = true; let java = if let Some(CommandDataOption {
if let Some(x) = command.data.options.get(1) { value: CommandDataOptionValue::Boolean(z),
if let Some(CommandDataOptionValue::Boolean(z)) = x.to_owned().resolved { ..
java = !z; }) = command.data.options.get(1)
} {
} !z
} else {
true
};
let username_mc; let username_mc;
if java { if java {
@ -130,7 +110,7 @@ pub(crate) mod user {
WHERE discord = ?1; WHERE discord = ?1;
", ",
) )
.bind(*user.as_u64() as i64) .bind(user.get() as i64)
.bind(minecraft) .bind(minecraft)
.fetch_optional(db) .fetch_optional(db)
.await .await
@ -175,7 +155,7 @@ pub(crate) mod user {
WHERE discord = ?1; WHERE discord = ?1;
", ",
) )
.bind(*user.as_u64() as i64) .bind(user.get() as i64)
.bind(minecraft) .bind(minecraft)
.fetch_optional(db) .fetch_optional(db)
.await .await
@ -194,7 +174,7 @@ pub(crate) mod user {
) sub on minecraft.server_discord = sub.server ) sub on minecraft.server_discord = sub.server
", ",
) )
.bind(*discord.as_u64() as i64) .bind(discord.get() as i64)
.fetch_all(db) .fetch_all(db)
.await .await
} }
@ -205,6 +185,7 @@ pub(crate) mod server {
use super::*; use super::*;
pub(crate) mod add { pub(crate) mod add {
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommand, CreateCommandOption};
use serenity::model::id::GuildId; use serenity::model::id::GuildId;
use sqlx::Error; use sqlx::Error;
// this is to managfe the server side of commands related to minecraft // 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::common::minecraft::Minecraft;
use skynet_discord_bot::{is_admin, Config}; use skynet_discord_bot::{is_admin, Config};
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register() -> CreateCommand {
command.name("minecraft_add").description("Add a minecraft server").create_option(|option| { CreateCommand::new("minecraft_add").description("Add a minecraft server").add_option(
option CreateCommandOption::new(CommandOptionType::String, "server_id", "ID of the Minecraft server hosted by the Computer Society").required(true),
.name("server_id") )
.description("ID of the Minecraft server hosted by the Computer Society")
.kind(CommandOptionType::String)
.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 // check if user has high enough permisssions
if let Some(msg) = is_admin(command, ctx).await { if let Some(msg) = is_admin(command, ctx).await {
return msg; return msg;
@ -233,16 +210,12 @@ pub(crate) mod server {
Some(x) => x, Some(x) => x,
}; };
let server_minecraft = if let CommandDataOptionValue::String(id) = command let server_minecraft = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::String(id),
.options ..
.first() }) = command.data.options.first()
.expect("Expected server_id option")
.resolved
.as_ref()
.expect("Expected server_id object")
{ {
id.to_owned() id.to_string()
} else { } else {
return String::from("Expected Server ID"); return String::from("Expected Server ID");
}; };
@ -279,7 +252,7 @@ pub(crate) mod server {
VALUES (?1, ?2) VALUES (?1, ?2)
", ",
) )
.bind(*discord.as_u64() as i64) .bind(discord.get() as i64)
.bind(minecraft) .bind(minecraft)
.fetch_optional(db) .fetch_optional(db)
.await .await
@ -287,18 +260,18 @@ pub(crate) mod server {
} }
pub(crate) mod list { pub(crate) mod list {
use serenity::builder::CreateApplicationCommand; use serenity::all::CommandInteraction;
use serenity::builder::CreateCommand;
use serenity::client::Context; use serenity::client::Context;
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
use skynet_discord_bot::common::database::DataBase; use skynet_discord_bot::common::database::DataBase;
use skynet_discord_bot::common::minecraft::{get_minecraft_config_server, server_information}; use skynet_discord_bot::common::minecraft::{get_minecraft_config_server, server_information};
use skynet_discord_bot::{is_admin, Config}; use skynet_discord_bot::{is_admin, Config};
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register() -> CreateCommand {
command.name("minecraft_list").description("List your minecraft servers") 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 { if let Some(msg) = is_admin(command, ctx).await {
return msg; return msg;
} }
@ -348,27 +321,22 @@ pub(crate) mod server {
} }
pub(crate) mod delete { 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::client::Context;
use serenity::model::application::command::CommandOptionType;
use serenity::model::id::GuildId; 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::database::DataBase;
use skynet_discord_bot::common::minecraft::Minecraft; use skynet_discord_bot::common::minecraft::Minecraft;
use skynet_discord_bot::is_admin; use skynet_discord_bot::is_admin;
use sqlx::{Error, Pool, Sqlite}; use sqlx::{Error, Pool, Sqlite};
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register() -> CreateCommand {
command.name("minecraft_delete").description("Delete a minecraft server").create_option(|option| { CreateCommand::new("minecraft_delete").description("Delete a minecraft server").add_option(
option CreateCommandOption::new(CommandOptionType::String, "server_id", "ID of the Minecraft server hosted by the Computer Society").required(true),
.name("server_id") )
.description("ID of the Minecraft server hosted by the Computer Society")
.kind(CommandOptionType::String)
.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 // check if user has high enough permisssions
if let Some(msg) = is_admin(command, ctx).await { if let Some(msg) = is_admin(command, ctx).await {
return msg; return msg;
@ -378,16 +346,12 @@ pub(crate) mod server {
Some(x) => x, Some(x) => x,
}; };
let server_minecraft = if let CommandDataOptionValue::String(id) = command let server_minecraft = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::String(id),
.options ..
.first() }) = command.data.options.first()
.expect("Expected server_id option")
.resolved
.as_ref()
.expect("Expected server_id object")
{ {
id.to_owned() id.to_string()
} else { } else {
return String::from("Expected Server ID"); return String::from("Expected Server ID");
}; };
@ -418,7 +382,7 @@ pub(crate) mod server {
WHERE server_discord = ?1 AND server_minecraft = ?2 WHERE server_discord = ?1 AND server_minecraft = ?2
", ",
) )
.bind(*discord.as_u64() as i64) .bind(discord.get() as i64)
.bind(minecraft) .bind(minecraft)
.fetch_optional(db) .fetch_optional(db)
.await .await

View file

@ -1,11 +1,4 @@
use serenity::{ use serenity::client::Context;
builder::CreateApplicationCommand,
client::Context,
model::{
application::interaction::application_command::ApplicationCommandInteraction,
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
},
};
use skynet_discord_bot::common::database::{DataBase, RoleAdder}; use skynet_discord_bot::common::database::{DataBase, RoleAdder};
use skynet_discord_bot::is_admin; use skynet_discord_bot::is_admin;
@ -13,51 +6,40 @@ use sqlx::{Error, Pool, Sqlite};
pub mod edit { pub mod edit {
use super::*; 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 // check if user has high enough permisssions
if let Some(msg) = is_admin(command, ctx).await { if let Some(msg) = is_admin(command, ctx).await {
return msg; return msg;
} }
let role_a = if let CommandDataOptionValue::Role(role) = command let role_a = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::Role(role),
.options ..
.first() }) = command.data.options.first()
.expect("Expected role option")
.resolved
.as_ref()
.expect("Expected role object")
{ {
role.id.to_owned() role.to_owned()
} else { } else {
return "Please provide a valid role for ``Role Current``".to_string(); return "Please provide a valid role for ``Role Current``".to_string();
}; };
let role_b = if let CommandDataOptionValue::Role(role) = command let role_b = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::Role(role),
.options ..
.get(1) }) = command.data.options.get(1)
.expect("Expected role option")
.resolved
.as_ref()
.expect("Expected role object")
{ {
role.id.to_owned() role.to_owned()
} else { } else {
return "Please provide a valid role for ``Role Current``".to_string(); return "Please provide a valid role for ``Role Current``".to_string();
}; };
let role_c = if let CommandDataOptionValue::Role(role) = command let role_c = if let Some(CommandDataOption {
.data value: CommandDataOptionValue::Role(role),
.options ..
.get(2) }) = command.data.options.get(2)
.expect("Expected role option")
.resolved
.as_ref()
.expect("Expected role object")
{ {
role.id.to_owned() role.to_owned()
} else { } else {
return "Please provide a valid role for ``Role Current``".to_string(); 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(); return "Role C cannot be same as A or B".to_string();
} }
let mut delete = false; let delete = if let Some(CommandDataOption {
value: CommandDataOptionValue::Boolean(z),
if let Some(x) = command.data.options.get(3) { ..
let tmp = x.to_owned(); }) = command.data.options.get(3)
if let Some(CommandDataOptionValue::Boolean(z)) = tmp.resolved { {
delete = z; *z
} } else {
} false
};
let db_lock = { let db_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;
@ -124,32 +107,13 @@ pub mod edit {
} }
} }
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register() -> CreateCommand {
command CreateCommand::new("roles_adder")
.name("roles_adder")
.description("Combine roles together to an new one") .description("Combine roles together to an new one")
.create_option(|option| { .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_a", "A role you want to add to Role B").required(true))
option .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_b", "A role you want to add to Role A").required(true))
.name("role_a") .add_option(CreateCommandOption::new(CommandOptionType::Role, "role_c", "Sum of A and B").required(true))
.description("A role you want to add to Role B") .add_option(CreateCommandOption::new(CommandOptionType::Boolean, "delete", "Delete this entry.").required(false))
.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)
})
} }
async fn add_server(db: &Pool<Sqlite>, server: &RoleAdder, delete: bool) -> Result<Option<RoleAdder>, Error> { async fn add_server(db: &Pool<Sqlite>, server: &RoleAdder, delete: bool) -> Result<Option<RoleAdder>, Error> {
@ -160,10 +124,10 @@ pub mod edit {
WHERE server = ?1 AND role_a = ?2 AND role_b = ?3 AND role_c = ?4 WHERE server = ?1 AND role_a = ?2 AND role_b = ?3 AND role_c = ?4
", ",
) )
.bind(*server.server.as_u64() as i64) .bind(server.server.get() as i64)
.bind(*server.role_a.as_u64() as i64) .bind(server.role_a.get() as i64)
.bind(*server.role_b.as_u64() as i64) .bind(server.role_b.get() as i64)
.bind(*server.role_c.as_u64() as i64) .bind(server.role_c.get() as i64)
.fetch_optional(db) .fetch_optional(db)
.await .await
} else { } else {
@ -173,10 +137,10 @@ pub mod edit {
VALUES (?1, ?2, ?3, ?4) VALUES (?1, ?2, ?3, ?4)
", ",
) )
.bind(*server.server.as_u64() as i64) .bind(server.server.get() as i64)
.bind(*server.role_a.as_u64() as i64) .bind(server.role_a.get() as i64)
.bind(*server.role_b.as_u64() as i64) .bind(server.role_b.get() as i64)
.bind(*server.role_c.as_u64() as i64) .bind(server.role_c.get() as i64)
.fetch_optional(db) .fetch_optional(db)
.await .await
} }
@ -192,7 +156,7 @@ pub mod tools {
use skynet_discord_bot::common::database::RoleAdder; use skynet_discord_bot::common::database::RoleAdder;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
pub async fn on_role_change(db: &Pool<Sqlite>, ctx: &Context, mut new_data: Member) { pub async fn on_role_change(db: &Pool<Sqlite>, ctx: &Context, new_data: Member) {
// check if the role changed is part of the oens for this server // check if the role changed is part of the oens for this server
if let Ok(role_adders) = sqlx::query_as::<_, RoleAdder>( if let Ok(role_adders) = sqlx::query_as::<_, RoleAdder>(
r#" r#"
@ -201,7 +165,7 @@ pub mod tools {
WHERE server = ? WHERE server = ?
"#, "#,
) )
.bind(*new_data.guild_id.as_u64() as i64) .bind(new_data.guild_id.get() as i64)
.fetch_all(db) .fetch_all(db)
.await .await
{ {

View file

@ -194,7 +194,7 @@ fn get_role_from_row(row: &SqliteRow, col: &str) -> RoleId {
match row.try_get(col) { match row.try_get(col) {
Ok(x) => { Ok(x) => {
let tmp: i64 = x; let tmp: i64 = x;
RoleId(tmp as u64) RoleId::new(tmp as u64)
} }
_ => RoleId::from(0u64), _ => RoleId::from(0u64),
} }
@ -226,7 +226,7 @@ pub async fn get_server_config(db: &Pool<Sqlite>, server: &GuildId) -> Option<Se
WHERE server = ? WHERE server = ?
"#, "#,
) )
.bind(*server.as_u64() as i64) .bind(server.get() as i64)
.fetch_one(db) .fetch_one(db)
.await .await
.ok() .ok()
@ -241,8 +241,8 @@ pub async fn get_server_member(db: &Pool<Sqlite>, server: &GuildId, member: &gui
WHERE server = ? AND discord = ? WHERE server = ? AND discord = ?
"#, "#,
) )
.bind(*server.as_u64() as i64) .bind(server.get() as i64)
.bind(*member.user.id.as_u64() as i64) .bind(member.user.id.get() as i64)
.fetch_one(db) .fetch_one(db)
.await .await
} }

View file

@ -148,7 +148,7 @@ pub async fn get_minecraft_config_server(db: &Pool<Sqlite>, g_id: GuildId) -> Ve
WHERE server_discord = ?1 WHERE server_discord = ?1
"#, "#,
) )
.bind(*g_id.as_u64() as i64) .bind(g_id.get() as i64)
.fetch_all(db) .fetch_all(db)
.await .await
.unwrap_or_default() .unwrap_or_default()

View file

@ -31,7 +31,7 @@ pub mod normal {
let mut members_all = members.len(); let mut members_all = members.len();
if let Ok(x) = server.members(ctx, None, None).await { 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 // 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) { if !members_changed.is_empty() && !members_changed.contains(&member.user.id) {
continue; continue;
@ -83,7 +83,7 @@ pub mod normal {
set_server_numbers(&db, server, members_all as i64, members.len() as i64).await; set_server_numbers(&db, server, members_all as i64, members.len() as i64).await;
// small bit of logging to note changes over time // 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<Sqlite>, server: &GuildId) -> Vec<ServerMembersWolves> { pub async fn get_server_member_bulk(db: &Pool<Sqlite>, server: &GuildId) -> Vec<ServerMembersWolves> {
@ -99,7 +99,7 @@ pub mod normal {
) )
"#, "#,
) )
.bind(*server.as_u64() as i64) .bind(server.get() as i64)
.bind(get_now_iso(true)) .bind(get_now_iso(true))
.fetch_all(db) .fetch_all(db)
.await .await
@ -116,13 +116,13 @@ pub mod normal {
) )
.bind(past) .bind(past)
.bind(current) .bind(current)
.bind(*server.as_u64() as i64) .bind(server.get() as i64)
.fetch_optional(db) .fetch_optional(db)
.await .await
{ {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
println!("Failure to insert into {}", server.as_u64()); println!("Failure to insert into {}", server.get());
println!("{:?}", e); println!("{:?}", e);
} }
} }
@ -134,6 +134,8 @@ pub mod committee {
use crate::common::database::{DataBase, Wolves}; use crate::common::database::{DataBase, Wolves};
use crate::common::wolves::committees::Committees; use crate::common::wolves::committees::Committees;
use crate::Config; use crate::Config;
use serenity::all::EditRole;
use serenity::builder::CreateChannel;
use serenity::client::Context; use serenity::client::Context;
use serenity::model::channel::ChannelType; use serenity::model::channel::ChannelType;
use serenity::model::guild::Member; use serenity::model::guild::Member;
@ -170,9 +172,16 @@ pub mod committee {
*/ */
pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, config: &Config, members: &mut Vec<Member>) { pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, config: &Config, members: &mut Vec<Member>) {
let server = config.committee_server; let server = config.committee_server;
let committee_member = config.committee_role; let committee_member = RoleId::new(1226602779968274573);
let committees = get_committees(db).await; 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 // information about the server
let roles = server.roles(&ctx).await.unwrap_or_default(); let roles = server.roles(&ctx).await.unwrap_or_default();
@ -216,7 +225,10 @@ pub mod committee {
Some(x) => Some(x.to_owned()), Some(x) => Some(x.to_owned()),
None => { None => {
// create teh role if it does not exist // 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), Ok(x) => Some(x),
Err(_) => None, Err(_) => None,
} }
@ -226,7 +238,12 @@ pub mod committee {
// create teh channel if it does nto exist // create teh channel if it does nto exist
if !channels_name.contains_key(&committee.name_profile) { if !channels_name.contains_key(&committee.name_profile) {
match server 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 .await
{ {
Ok(x) => { Ok(x) => {
@ -277,7 +294,7 @@ pub mod committee {
Some(x) => { Some(x) => {
let mut tmp = x.to_owned(); let mut tmp = x.to_owned();
if !tmp.is_empty() { if !tmp.is_empty() {
tmp.push(RoleId(1226602779968274573)); tmp.push(committee_member);
} }
tmp tmp
} }
@ -309,7 +326,7 @@ pub mod committee {
// these roles are flavor roles, only there to make folks mentionable // these roles are flavor roles, only there to make folks mentionable
member.add_roles(&ctx, &roles_add).await.unwrap_or_default(); member.add_roles(&ctx, &roles_add).await.unwrap_or_default();
} else { } else {
member.remove_roles(&ctx, &[RoleId(1226602779968274573)]).await.unwrap_or_default(); member.remove_roles(&ctx, &[committee_member]).await.unwrap_or_default();
} }
} }
@ -348,7 +365,8 @@ pub mod committee {
"#, "#,
) )
.fetch_all(db) .fetch_all(db)
.await.unwrap_or_else(|e| { .await
.unwrap_or_else(|e| {
dbg!(e); dbg!(e);
vec![] vec![]
}) })

View file

@ -144,13 +144,13 @@ pub mod cns {
", ",
) )
.bind(name) .bind(name)
.bind(*server.as_u64() as i64) .bind(server.get() as i64)
.fetch_optional(db) .fetch_optional(db)
.await .await
{ {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
println!("Failure to set server name {}", server.as_u64()); println!("Failure to set server name {}", server.get());
println!("{:?}", e); println!("{:?}", e);
} }
} }
@ -168,7 +168,7 @@ pub mod cns {
) )
"#, "#,
) )
.bind(*server.as_u64() as i64) .bind(server.get() as i64)
.fetch_all(db) .fetch_all(db)
.await .await
.unwrap_or_default() .unwrap_or_default()
@ -181,7 +181,7 @@ pub mod cns {
VALUES (?1, ?2, ?3) VALUES (?1, ?2, ?3)
", ",
) )
.bind(*server.as_u64() as i64) .bind(server.get() as i64)
.bind(&user.member_id) .bind(&user.member_id)
.bind(&user.expiry) .bind(&user.expiry)
.fetch_optional(db) .fetch_optional(db)
@ -189,7 +189,7 @@ pub mod cns {
{ {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
println!("Failure to insert into ServerMembers {} {:?}", server.as_u64(), user); println!("Failure to insert into ServerMembers {} {:?}", server.get(), user);
println!("{:?}", e); println!("{:?}", e);
} }
} }

View file

@ -3,9 +3,9 @@ pub mod common;
use chrono::{Datelike, SecondsFormat, Utc}; use chrono::{Datelike, SecondsFormat, Utc};
use dotenvy::dotenv; use dotenvy::dotenv;
use rand::{distributions::Alphanumeric, thread_rng, Rng}; use rand::{distributions::Alphanumeric, thread_rng, Rng};
use serenity::all::CommandInteraction;
use serenity::client::Context; use serenity::client::Context;
use serenity::model::id::{ChannelId, GuildId, RoleId}; use serenity::model::id::{ChannelId, GuildId, RoleId};
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
use serenity::prelude::TypeMapKey; use serenity::prelude::TypeMapKey;
use std::{env, sync::Arc}; use std::{env, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -57,9 +57,9 @@ pub fn get_config() -> Config {
mail_pass: "".to_string(), mail_pass: "".to_string(),
wolves_url: "".to_string(), wolves_url: "".to_string(),
wolves_api: "".to_string(), wolves_api: "".to_string(),
committee_server: GuildId(0), committee_server: GuildId::new(0),
committee_role: RoleId(0), committee_role: RoleId::new(0),
committee_category: ChannelId(0), committee_category: ChannelId::new(0),
}; };
if let Ok(x) = env::var("DATABASE_HOME") { 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) = env::var("COMMITTEE_DISCORD") {
if let Ok(x) = x.trim().parse::<u64>() { if let Ok(x) = x.trim().parse::<u64>() {
config.committee_server = GuildId(x); config.committee_server = GuildId::new(x);
} }
} }
if let Ok(x) = env::var("COMMITTEE_DISCORD") { if let Ok(x) = env::var("COMMITTEE_DISCORD") {
if let Ok(x) = x.trim().parse::<u64>() { if let Ok(x) = x.trim().parse::<u64>() {
config.committee_role = RoleId(x); config.committee_role = RoleId::new(x);
} }
} }
if let Ok(x) = env::var("COMMITTEE_CATEGORY") { if let Ok(x) = env::var("COMMITTEE_CATEGORY") {
if let Ok(x) = x.trim().parse::<u64>() { if let Ok(x) = x.trim().parse::<u64>() {
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 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<String> { pub async fn is_admin(command: &CommandInteraction, ctx: &Context) -> Option<String> {
let mut admin = false; let mut admin = false;
let g_id = match command.guild_id { let g_id = match command.guild_id {

View file

@ -1,14 +1,13 @@
pub mod commands; pub mod commands;
use crate::commands::role_adder::tools::on_role_change; 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::model::guild::Member;
use serenity::{ use serenity::{
async_trait, async_trait,
client::{Context, EventHandler}, client::{Context, EventHandler},
model::{ model::{
application::{command::Command, interaction::Interaction},
gateway::{GatewayIntents, Ready}, gateway::{GatewayIntents, Ready},
prelude::Activity,
user::OnlineStatus, user::OnlineStatus,
}, },
Client, Client,
@ -26,7 +25,7 @@ struct Handler;
#[async_trait] #[async_trait]
impl EventHandler for Handler { impl EventHandler for Handler {
// handles previously linked accounts joining the server // 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 db_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone() data_read.get::<DataBase>().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 &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); dbg!(err);
} }
} }
@ -92,7 +91,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
} }
// handles role updates // handles role updates
async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Member) { async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Option<Member>, _: GuildMemberUpdateEvent) {
// get config/db // get config/db
let db_lock = { let db_lock = {
let data_read = ctx.data.read().await; 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; let db = db_lock.read().await;
// check if the role changed is part of the oens for this server // 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) { async fn ready(&self, ctx: Context, ready: Ready) {
println!("[Main] {} is connected!", ready.user.name); 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| { match Command::set_global_commands(
commands &ctx.http,
.create_application_command(|command| commands::add_server::register(command)) vec![
.create_application_command(|command| commands::role_adder::edit::register(command)) commands::add_server::register(),
.create_application_command(|command| commands::link_email::link::register(command)) commands::role_adder::edit::register(),
.create_application_command(|command| commands::link_email::verify::register(command)) commands::link_email::link::register(),
.create_application_command(|command| commands::minecraft::server::add::register(command)) commands::link_email::verify::register(),
.create_application_command(|command| commands::minecraft::server::list::register(command)) commands::minecraft::server::add::register(),
.create_application_command(|command| commands::minecraft::server::delete::register(command)) commands::minecraft::server::list::register(),
.create_application_command(|command| commands::minecraft::user::add::register(command)) commands::minecraft::server::delete::register(),
}) commands::minecraft::user::add::register(),
],
)
.await .await
{ {
Ok(_) => {} 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) { 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; let _ = command.defer_ephemeral(&ctx.http).await;
//println!("Received command interaction: {:#?}", command); //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(), _ => "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); println!("Cannot respond to slash command: {}", why);
} }
} }