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 std::collections::HashSet;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
|
|
@ -63,7 +63,7 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
|
|||
role_past,
|
||||
role_current,
|
||||
member_past: 0,
|
||||
member_current: 0
|
||||
member_current: 0,
|
||||
};
|
||||
|
||||
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};
|
||||
|
||||
pub(crate) mod user {
|
||||
|
@ -16,7 +16,7 @@ pub(crate) mod user {
|
|||
use super::*;
|
||||
use crate::commands::link_email::link::get_server_member_discord;
|
||||
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;
|
||||
|
||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||
|
@ -125,10 +125,7 @@ pub(crate) mod server {
|
|||
use skynet_discord_bot::{is_admin, update_server, Config, Minecraft};
|
||||
|
||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||
command
|
||||
.name("minecraft_add")
|
||||
.description("Add a minecraft server")
|
||||
.create_option(|option| {
|
||||
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")
|
||||
|
@ -204,12 +201,10 @@ pub(crate) mod server {
|
|||
use serenity::builder::CreateApplicationCommand;
|
||||
use serenity::client::Context;
|
||||
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 {
|
||||
command
|
||||
.name("minecraft_list")
|
||||
.description("List your minecraft servers")
|
||||
command.name("minecraft_list").description("List your minecraft servers")
|
||||
}
|
||||
|
||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||
|
@ -242,10 +237,13 @@ pub(crate) mod server {
|
|||
let mut result = "|ID|Online|Name|Description|\n|:---|:---|:---|:---|".to_string();
|
||||
for server in get_minecraft_config_server(&db, g_id).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,14 +253,11 @@ pub(crate) mod server {
|
|||
use serenity::model::application::command::CommandOptionType;
|
||||
use serenity::model::id::GuildId;
|
||||
use serenity::model::prelude::application_command::{ApplicationCommandInteraction, CommandDataOptionValue};
|
||||
use skynet_discord_bot::{is_admin, DataBase, Minecraft};
|
||||
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 {
|
||||
command
|
||||
.name("minecraft_delete")
|
||||
.description("Delete a minecraft server")
|
||||
.create_option(|option| {
|
||||
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")
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
pub mod minecraft;
|
||||
pub mod add_server;
|
||||
pub mod link_email;
|
||||
pub mod minecraft;
|
||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -11,6 +11,7 @@ use serenity::{
|
|||
use crate::set_roles::get_server_member_bulk;
|
||||
use chrono::{Datelike, SecondsFormat, Utc};
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::id::UserId;
|
||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||
|
@ -264,7 +265,6 @@ impl<'r> FromRow<'r, SqliteRow> for Servers {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Minecraft {
|
||||
pub discord: GuildId,
|
||||
|
@ -697,7 +697,7 @@ loop through all members of server
|
|||
get a list of folks with mc accounts that are 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![];
|
||||
for member in get_server_member_bulk(db, g_id).await {
|
||||
if let Some(x) = member.minecraft {
|
||||
|
@ -730,22 +730,22 @@ pub struct ServerDetailsResSub {
|
|||
pub identifier: String,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub is_suspended: String,
|
||||
pub is_suspended: bool,
|
||||
}
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct ServerDetailsRes {
|
||||
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)
|
||||
.header("Authorization", bearer)
|
||||
.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) => {
|
||||
Some(res)
|
||||
}
|
||||
Ok(res) => Some(res),
|
||||
Err(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
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_minecraft_config(db: &Pool<Sqlite>) -> Vec<Minecraft> {
|
||||
sqlx::query_as::<_, Minecraft>(
|
||||
r#"
|
||||
|
|
Loading…
Reference in a new issue