feat: server side aspects of adding minecraft whitelist added
This commit is contained in:
parent
2761098c8d
commit
d5877e99e6
6 changed files with 217 additions and 16 deletions
32
src/lib.rs
32
src/lib.rs
|
@ -12,12 +12,12 @@ use chrono::{Datelike, SecondsFormat, Utc};
|
|||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use serenity::client::Context;
|
||||
use serenity::model::id::UserId;
|
||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||
use sqlx::{
|
||||
sqlite::{SqliteConnectOptions, SqlitePoolOptions, SqliteRow},
|
||||
Error, FromRow, Pool, Row, Sqlite,
|
||||
};
|
||||
use std::{env, str::FromStr, sync::Arc};
|
||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct Config {
|
||||
|
@ -28,6 +28,7 @@ pub struct Config {
|
|||
|
||||
pub auth: String,
|
||||
pub discord_token: String,
|
||||
pub discord_minecraft: String,
|
||||
|
||||
pub mail_smtp: String,
|
||||
pub mail_user: String,
|
||||
|
@ -53,6 +54,7 @@ pub fn get_config() -> Config {
|
|||
ldap_api: "https://api.account.skynet.ie".to_string(),
|
||||
auth: "".to_string(),
|
||||
discord_token: "".to_string(),
|
||||
discord_minecraft: "".to_string(),
|
||||
|
||||
home: ".".to_string(),
|
||||
database: "database.db".to_string(),
|
||||
|
@ -83,6 +85,9 @@ pub fn get_config() -> Config {
|
|||
if let Ok(x) = env::var("DISCORD_TOKEN") {
|
||||
config.discord_token = x.trim().to_string();
|
||||
}
|
||||
if let Ok(x) = env::var("DISCORD_MINECRAFT") {
|
||||
config.discord_minecraft = x.trim().to_string();
|
||||
}
|
||||
|
||||
if let Ok(x) = env::var("EMAIL_SMTP") {
|
||||
config.mail_smtp = x.trim().to_string();
|
||||
|
@ -219,6 +224,7 @@ pub struct Servers {
|
|||
pub role_current: Option<RoleId>,
|
||||
pub member_past: i64,
|
||||
pub member_current: i64,
|
||||
pub server_minecraft: Option<String>,
|
||||
}
|
||||
impl<'r> FromRow<'r, SqliteRow> for Servers {
|
||||
fn from_row(row: &'r SqliteRow) -> Result<Self, Error> {
|
||||
|
@ -247,6 +253,11 @@ impl<'r> FromRow<'r, SqliteRow> for Servers {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
let server_minecraft = match row.try_get("server_minecraft") {
|
||||
Ok(x) => Some(x),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
server,
|
||||
wolves_api: row.try_get("wolves_api")?,
|
||||
|
@ -254,6 +265,7 @@ impl<'r> FromRow<'r, SqliteRow> for Servers {
|
|||
role_current,
|
||||
member_past: row.try_get("member_past")?,
|
||||
member_current: row.try_get("member_current")?,
|
||||
server_minecraft,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -271,9 +283,7 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
|
|||
.await?;
|
||||
|
||||
// migrations are amazing!
|
||||
sqlx::migrate!("./db/migrations")
|
||||
.run(&pool)
|
||||
.await?;
|
||||
sqlx::migrate!("./db/migrations").run(&pool).await.unwrap();
|
||||
|
||||
Ok(pool)
|
||||
}
|
||||
|
@ -419,7 +429,7 @@ pub mod set_roles {
|
|||
println!("{:?} Changes: New: +{}, Current: +{}/-{}", server.as_u64(), roles_set[0], roles_set[1], roles_set[2]);
|
||||
}
|
||||
|
||||
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> {
|
||||
sqlx::query_as::<_, ServerMembersWolves>(
|
||||
r#"
|
||||
SELECT *
|
||||
|
@ -633,9 +643,9 @@ pub mod get_data {
|
|||
}
|
||||
|
||||
/**
|
||||
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>{
|
||||
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> {
|
||||
let mut admin = false;
|
||||
|
||||
let g_id = match command.guild_id {
|
||||
|
@ -664,8 +674,8 @@ pub async fn is_admin(command: &ApplicationCommandInteraction, ctx: &Context) ->
|
|||
}
|
||||
}
|
||||
if !admin {
|
||||
return Some("Administrator permission required".to_string())
|
||||
Some("Administrator permission required".to_string())
|
||||
} else {
|
||||
return None
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue