forked from Skynet/discord-bot
feat: bumped serenity to the latest version
Lots of changes to how it runs
This commit is contained in:
parent
a8c1cc9cf1
commit
6b84f33d2e
12 changed files with 352 additions and 485 deletions
|
@ -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::<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();
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue