fmt: clippy and fmt
This commit is contained in:
parent
9481358068
commit
55b2e534d4
5 changed files with 67 additions and 73 deletions
|
@ -1,5 +1,5 @@
|
||||||
use std::collections::HashSet;
|
|
||||||
use skynet_discord_bot::{db_init, get_config, get_minecraft_config, update_server, whitelist_wipe};
|
use skynet_discord_bot::{db_init, get_config, get_minecraft_config, update_server, whitelist_wipe};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
|
||||||
role_past,
|
role_past,
|
||||||
role_current,
|
role_current,
|
||||||
member_past: 0,
|
member_past: 0,
|
||||||
member_current: 0
|
member_current: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
match add_server(&db, ctx, &server_data).await {
|
match add_server(&db, ctx, &server_data).await {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use serenity::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use skynet_discord_bot::{get_server_config, DataBase, Servers};
|
use skynet_discord_bot::DataBase;
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
pub(crate) mod user {
|
pub(crate) mod user {
|
||||||
|
@ -16,7 +16,7 @@ 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 serenity::model::id::UserId;
|
use serenity::model::id::UserId;
|
||||||
use skynet_discord_bot::{whitelist_update, Config, Wolves, Minecraft};
|
use skynet_discord_bot::{whitelist_update, Config, Minecraft, Wolves};
|
||||||
use sqlx::Error;
|
use sqlx::Error;
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
|
@ -88,10 +88,10 @@ pub(crate) mod user {
|
||||||
WHERE discord = ?1;
|
WHERE discord = ?1;
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(*user.as_u64() as i64)
|
.bind(*user.as_u64() as i64)
|
||||||
.bind(minecraft)
|
.bind(minecraft)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_servers(db: &Pool<Sqlite>, discord: &UserId) -> Result<Vec<Minecraft>, Error> {
|
async fn get_servers(db: &Pool<Sqlite>, discord: &UserId) -> Result<Vec<Minecraft>, Error> {
|
||||||
|
@ -107,9 +107,9 @@ 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.as_u64() as i64)
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,16 +125,13 @@ pub(crate) mod server {
|
||||||
use skynet_discord_bot::{is_admin, update_server, Config, Minecraft};
|
use skynet_discord_bot::{is_admin, update_server, Config, Minecraft};
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
command
|
command.name("minecraft_add").description("Add a minecraft server").create_option(|option| {
|
||||||
.name("minecraft_add")
|
option
|
||||||
.description("Add a minecraft server")
|
.name("server_id")
|
||||||
.create_option(|option| {
|
.description("ID of the Minecraft server hosted by the Computer Society")
|
||||||
option
|
.kind(CommandOptionType::String)
|
||||||
.name("server_id")
|
.required(true)
|
||||||
.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: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||||
|
@ -193,10 +190,10 @@ pub(crate) mod server {
|
||||||
VALUES (?1, ?2)
|
VALUES (?1, ?2)
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(*discord.as_u64() as i64)
|
.bind(*discord.as_u64() as i64)
|
||||||
.bind(minecraft)
|
.bind(minecraft)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,12 +201,10 @@ pub(crate) mod server {
|
||||||
use serenity::builder::CreateApplicationCommand;
|
use serenity::builder::CreateApplicationCommand;
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||||
use skynet_discord_bot::{Config, DataBase, get_minecraft_config_server, is_admin, server_information};
|
use skynet_discord_bot::{get_minecraft_config_server, is_admin, server_information, Config, DataBase};
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
command
|
command.name("minecraft_list").description("List your minecraft servers")
|
||||||
.name("minecraft_list")
|
|
||||||
.description("List your minecraft servers")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||||
|
@ -240,12 +235,15 @@ pub(crate) mod server {
|
||||||
let config = config_lock.read().await;
|
let config = config_lock.read().await;
|
||||||
|
|
||||||
let mut result = "|ID|Online|Name|Description|\n|:---|:---|:---|:---|".to_string();
|
let mut result = "|ID|Online|Name|Description|\n|:---|:---|:---|:---|".to_string();
|
||||||
for server in get_minecraft_config_server(&db, g_id).await {
|
for server in get_minecraft_config_server(&db, g_id).await {
|
||||||
if let Some(x) = server_information(&server.minecraft, &config.discord_minecraft).await {
|
if let Some(x) = server_information(&server.minecraft, &config.discord_minecraft).await {
|
||||||
write!(result, "\n|{}|{}|{}|{}|", &x.attributes.identifier, !x.attributes.is_suspended, &x.attributes.name, &x.attributes.description).unwrap();
|
result.push_str(&format!(
|
||||||
|
"\n|{}|{}|{}|{}|",
|
||||||
|
&x.attributes.identifier, !x.attributes.is_suspended, &x.attributes.name, &x.attributes.description
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result
|
result.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,20 +253,17 @@ pub(crate) mod server {
|
||||||
use serenity::model::application::command::CommandOptionType;
|
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 serenity::model::prelude::application_command::{ApplicationCommandInteraction, CommandDataOptionValue};
|
||||||
|
use skynet_discord_bot::{is_admin, DataBase, Minecraft};
|
||||||
use sqlx::{Error, Pool, Sqlite};
|
use sqlx::{Error, Pool, Sqlite};
|
||||||
use skynet_discord_bot::{Config, DataBase, get_minecraft_config_server, get_server_config, is_admin, Minecraft, server_information, Servers, update_server};
|
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
command
|
command.name("minecraft_delete").description("Delete a minecraft server").create_option(|option| {
|
||||||
.name("minecraft_delete")
|
option
|
||||||
.description("Delete a minecraft server")
|
.name("server_id")
|
||||||
.create_option(|option| {
|
.description("ID of the Minecraft server hosted by the Computer Society")
|
||||||
option
|
.kind(CommandOptionType::String)
|
||||||
.name("server_id")
|
.required(true)
|
||||||
.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: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||||
|
@ -321,10 +316,10 @@ 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.as_u64() as i64)
|
||||||
.bind(minecraft)
|
.bind(minecraft)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
pub mod minecraft;
|
|
||||||
pub mod add_server;
|
pub mod add_server;
|
||||||
pub mod link_email;
|
pub mod link_email;
|
||||||
|
pub mod minecraft;
|
||||||
|
|
33
src/lib.rs
33
src/lib.rs
|
@ -11,6 +11,7 @@ use serenity::{
|
||||||
use crate::set_roles::get_server_member_bulk;
|
use crate::set_roles::get_server_member_bulk;
|
||||||
use chrono::{Datelike, SecondsFormat, Utc};
|
use chrono::{Datelike, SecondsFormat, Utc};
|
||||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::id::UserId;
|
use serenity::model::id::UserId;
|
||||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||||
|
@ -264,7 +265,6 @@ impl<'r> FromRow<'r, SqliteRow> for Servers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct Minecraft {
|
pub struct Minecraft {
|
||||||
pub discord: GuildId,
|
pub discord: GuildId,
|
||||||
|
@ -697,7 +697,7 @@ loop through all members of server
|
||||||
get a list of folks with mc accounts that are members
|
get a list of folks with mc accounts that are members
|
||||||
and a list that arent members
|
and a list that arent members
|
||||||
*/
|
*/
|
||||||
pub async fn update_server(server_id: &String, db: &Pool<Sqlite>, g_id: &GuildId, config: &Config) {
|
pub async fn update_server(server_id: &str, db: &Pool<Sqlite>, g_id: &GuildId, config: &Config) {
|
||||||
let mut usernames = vec![];
|
let mut usernames = vec![];
|
||||||
for member in get_server_member_bulk(db, g_id).await {
|
for member in get_server_member_bulk(db, g_id).await {
|
||||||
if let Some(x) = member.minecraft {
|
if let Some(x) = member.minecraft {
|
||||||
|
@ -730,22 +730,22 @@ pub struct ServerDetailsResSub {
|
||||||
pub identifier: String,
|
pub identifier: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub is_suspended: String,
|
pub is_suspended: bool,
|
||||||
}
|
}
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
pub struct ServerDetailsRes {
|
pub struct ServerDetailsRes {
|
||||||
pub attributes: ServerDetailsResSub,
|
pub attributes: ServerDetailsResSub,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get<T: Serialize>(url: &str, bearer: &str) -> Option<T> {
|
async fn get<T: Serialize + DeserializeOwned>(url: &str, bearer: &str) -> Option<T> {
|
||||||
match surf::get(url)
|
match surf::get(url)
|
||||||
.header("Authorization", bearer)
|
.header("Authorization", bearer)
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.header("Accept", "Application/vnd.pterodactyl.v1+json").recv_json().await
|
.header("Accept", "Application/vnd.pterodactyl.v1+json")
|
||||||
|
.recv_json()
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
Ok(res) => {
|
Ok(res) => Some(res),
|
||||||
Some(res)
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
dbg!(e);
|
dbg!(e);
|
||||||
|
|
||||||
|
@ -804,7 +804,6 @@ pub async fn server_information(server: &str, token: &str) -> Option<ServerDetai
|
||||||
get::<ServerDetailsRes>(&format!("{url_base}/"), &bearer).await
|
get::<ServerDetailsRes>(&format!("{url_base}/"), &bearer).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_minecraft_config(db: &Pool<Sqlite>) -> Vec<Minecraft> {
|
pub async fn get_minecraft_config(db: &Pool<Sqlite>) -> Vec<Minecraft> {
|
||||||
sqlx::query_as::<_, Minecraft>(
|
sqlx::query_as::<_, Minecraft>(
|
||||||
r#"
|
r#"
|
||||||
|
@ -812,12 +811,12 @@ pub async fn get_minecraft_config(db: &Pool<Sqlite>) -> Vec<Minecraft> {
|
||||||
FROM minecraft
|
FROM minecraft
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_minecraft_config_server(db: &Pool<Sqlite>, g_id: GuildId) -> Vec<Minecraft> {
|
pub async fn get_minecraft_config_server(db: &Pool<Sqlite>, g_id: GuildId) -> Vec<Minecraft> {
|
||||||
sqlx::query_as::<_, Minecraft>(
|
sqlx::query_as::<_, Minecraft>(
|
||||||
r#"
|
r#"
|
||||||
SELECT *
|
SELECT *
|
||||||
|
@ -825,8 +824,8 @@ pub async fn get_minecraft_config_server(db: &Pool<Sqlite>, g_id: GuildId) -> V
|
||||||
WHERE server_discord = ?1
|
WHERE server_discord = ?1
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.bind(*g_id.as_u64() as i64)
|
.bind(*g_id.as_u64() as i64)
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
Loading…
Reference in a new issue