feat: fixed up the changes

This commit is contained in:
silver 2025-02-18 13:36:08 +00:00
parent c79113921d
commit cab04a068f
Signed by untrusted user: silver
GPG key ID: 36F93D61BAD3FD7D
11 changed files with 62 additions and 47 deletions

16
Cargo.lock generated
View file

@ -1298,7 +1298,7 @@ dependencies = [
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project-lite", "pin-project-lite",
"socket2 0.5.7", "socket2 0.4.10",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing", "tracing",
@ -2628,6 +2628,15 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "signature" name = "signature"
version = "2.2.0" version = "2.2.0"
@ -2648,6 +2657,7 @@ dependencies = [
"maud", "maud",
"rand 0.8.5", "rand 0.8.5",
"serde", "serde",
"serde_json",
"serenity", "serenity",
"sqlx", "sqlx",
"surf", "surf",
@ -3242,7 +3252,9 @@ dependencies = [
"bytes 1.7.1", "bytes 1.7.1",
"libc", "libc",
"mio", "mio",
"parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry",
"socket2 0.5.7", "socket2 0.5.7",
"tokio-macros", "tokio-macros",
"windows-sys 0.52.0", "windows-sys 0.52.0",
@ -3917,7 +3929,7 @@ dependencies = [
[[package]] [[package]]
name = "wolves_oxidised" name = "wolves_oxidised"
version = "0.1.0" version = "0.1.0"
source = "git+https://forgejo.skynet.ie/Skynet/wolves-oxidised.git#867778128c1ef580ebfded7808bbd4e86f22903b" source = "git+https://forgejo.skynet.ie/Skynet/wolves-oxidised.git#6101104c794c2dcf7100b057fe37fdf165b8b381"
dependencies = [ dependencies = [
"reqwest 0.12.9", "reqwest 0.12.9",
"serde", "serde",

View file

@ -20,11 +20,8 @@ serenity = { version = "0.11.6", default-features = false, features = ["client",
tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "full"] } tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "full"] }
# wolves api # wolves api
# TODO: move off of unstable
wolves_oxidised = { git = "https://forgejo.skynet.ie/Skynet/wolves-oxidised.git", features = ["unstable"] } wolves_oxidised = { git = "https://forgejo.skynet.ie/Skynet/wolves-oxidised.git", features = ["unstable"] }
# wolves_oxidised = { path = "../wolves-oxidised", features = ["unstable"] }
# wolves api
wolves_oxidised = { git = "https://forgejo.skynet.ie/Skynet/wolves-oxidised.git" }
# to make the http requests # to make the http requests
surf = "2.3.2" surf = "2.3.2"

View file

@ -1,10 +0,0 @@
-- No longer using the previous committee table
DROP TABLE committee;
-- new table pulling from teh api
CREATE TABLE IF NOT EXISTS committees (
id integer PRIMARY KEY,
name text not null,
link text not null,
committee text not null
);

View file

@ -0,0 +1,11 @@
-- No longer using the previous committee table
DROP TABLE committee;
-- new table pulling from teh api
CREATE TABLE IF NOT EXISTS committees (
id integer PRIMARY KEY,
name_profile text not null,
name_full text not null,
link text not null,
committee text not null
);

View file

@ -263,7 +263,6 @@ pub mod link {
.await .await
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)] #[serde(untagged)]
pub enum WolvesResultUserResult { pub enum WolvesResultUserResult {

View file

@ -18,8 +18,8 @@ pub(crate) mod user {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
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::Minecraft;
use skynet_discord_bot::Config; use skynet_discord_bot::{whitelist_update, Config};
use sqlx::Error; use sqlx::Error;
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {

View file

@ -42,6 +42,7 @@ pub struct ServerMembersWolves {
pub email: String, pub email: String,
pub discord: Option<UserId>, pub discord: Option<UserId>,
pub minecraft: Option<String>, pub minecraft: Option<String>,
pub minecraft_uid: Option<String>,
} }
impl<'r> FromRow<'r, SqliteRow> for ServerMembersWolves { impl<'r> FromRow<'r, SqliteRow> for ServerMembersWolves {
@ -67,6 +68,7 @@ impl<'r> FromRow<'r, SqliteRow> for ServerMembersWolves {
email: row.try_get("email")?, email: row.try_get("email")?,
discord, discord,
minecraft: row.try_get("minecraft")?, minecraft: row.try_get("minecraft")?,
minecraft_uid: row.try_get("minecraft_uid")?,
}) })
} }
} }

View file

@ -1,5 +1,5 @@
use crate::common::set_roles::normal::get_server_member_bulk; use crate::common::set_roles::normal::get_server_member_bulk;
use crate::Config; use crate::{whitelist_update, Config};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serenity::model::id::GuildId; use serenity::model::id::GuildId;
@ -33,7 +33,10 @@ pub async fn update_server(server_id: &str, db: &Pool<Sqlite>, g_id: &GuildId, c
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 {
usernames.push(x); usernames.push((x, true));
}
if let Some(x) = member.minecraft_uid {
usernames.push((x, false));
} }
} }
if !usernames.is_empty() { if !usernames.is_empty() {
@ -98,18 +101,6 @@ struct BodyDelete {
files: Vec<String>, files: Vec<String>,
} }
pub async fn whitelist_update(add: &Vec<String>, server: &str, token: &str) {
let url_base = format!("http://panel.games.skynet.ie/api/client/servers/{server}");
let bearer = format!("Bearer {token}");
for name in add {
let data = BodyCommand {
command: format!("whitelist add {name}"),
};
post(&format!("{url_base}/command"), &bearer, &data).await;
}
}
pub async fn whitelist_wipe(server: &str, token: &str) { pub async fn whitelist_wipe(server: &str, token: &str) {
let url_base = format!("http://panel.games.skynet.ie/api/client/servers/{server}"); let url_base = format!("http://panel.games.skynet.ie/api/client/servers/{server}");
let bearer = format!("Bearer {token}"); let bearer = format!("Bearer {token}");

View file

@ -199,11 +199,11 @@ pub mod committee {
for committee in &committees { for committee in &committees {
// get the role for this committee/club/soc // get the role for this committee/club/soc
let role = match roles_name.get(&committee.name) { let role = match roles_name.get(&committee.name_profile) {
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)).await { match server.create_role(&ctx, |r| r.hoist(false).mentionable(true).name(&committee.name_profile)).await {
Ok(x) => Some(x), Ok(x) => Some(x),
Err(_) => None, Err(_) => None,
} }
@ -211,16 +211,16 @@ 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) { if !channels_name.contains_key(&committee.name_profile) {
match server match server
.create_channel(&ctx, |c| c.name(&committee.name).kind(ChannelType::Text).category(config.committee_category)) .create_channel(&ctx, |c| c.name(&committee.name_profile).kind(ChannelType::Text).category(config.committee_category))
.await .await
{ {
Ok(x) => { Ok(x) => {
// update teh channels name list // update teh channels name list
channels_name.insert(x.name.to_owned(), x.to_owned()); channels_name.insert(x.name.to_owned(), x.to_owned());
println!("Created channel: {}", &committee.name); println!("Created channel: {}", &committee.name_profile);
} }
Err(x) => { Err(x) => {
dbg!("Unable to create channel: ", x); dbg!("Unable to create channel: ", x);

View file

@ -176,7 +176,8 @@ pub mod committees {
#[derive(Debug, Clone, sqlx::FromRow)] #[derive(Debug, Clone, sqlx::FromRow)]
pub struct Committees { pub struct Committees {
pub id: i64, pub id: i64,
pub name: String, pub name_full: String,
pub name_profile: String,
pub link: String, pub link: String,
#[sqlx(json)] #[sqlx(json)]
pub committee: Vec<i64>, pub committee: Vec<i64>,
@ -185,10 +186,11 @@ pub mod committees {
impl From<wolves_oxidised::WolvesCNS> for Committees { impl From<wolves_oxidised::WolvesCNS> for Committees {
fn from(value: wolves_oxidised::WolvesCNS) -> Self { fn from(value: wolves_oxidised::WolvesCNS) -> Self {
Self { Self {
id: value.id.parse().unwrap_or(0), id: value.id,
name: value.name, name_full: value.name_full,
name_profile: value.name_profile,
link: value.link, link: value.link,
committee: value.committee.iter().map(|x| x.parse::<i64>().unwrap_or(0)).collect(), committee: value.committee,
} }
} }
} }
@ -217,13 +219,14 @@ pub mod committees {
async fn add_committee(db: &Pool<Sqlite>, committee: &Committees) { async fn add_committee(db: &Pool<Sqlite>, committee: &Committees) {
match sqlx::query_as::<_, Committees>( match sqlx::query_as::<_, Committees>(
" "
INSERT INTO committees (id, name, link, committee) INSERT INTO committees (id, name_profile, name_full, link, committee)
VALUES ($1, $2, $3, $4) VALUES ($1, $2, $3, $4, $5)
ON CONFLICT(id) DO UPDATE SET committee = $4 ON CONFLICT(id) DO UPDATE SET committee = $4
", ",
) )
.bind(committee.id) .bind(committee.id)
.bind(&committee.name) .bind(&committee.name_profile)
.bind(&committee.name_full)
.bind(&committee.link) .bind(&committee.link)
.bind(serde_json::to_string(&committee.committee).unwrap_or_default()) .bind(serde_json::to_string(&committee.committee).unwrap_or_default())
.fetch_optional(db) .fetch_optional(db)

View file

@ -1,12 +1,19 @@
pub mod common; pub mod common;
use crate::common::set_roles::normal::get_server_member_bulk;
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 serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serenity::client::Context; use serenity::client::Context;
use serenity::model::id::{ChannelId, GuildId, RoleId}; use serenity::model::guild;
use serenity::model::id::{ChannelId, GuildId, RoleId, UserId};
use serenity::model::prelude::application_command::ApplicationCommandInteraction; use serenity::model::prelude::application_command::ApplicationCommandInteraction;
use serenity::prelude::TypeMapKey; use serenity::prelude::TypeMapKey;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions, SqliteRow};
use sqlx::{Error, FromRow, Pool, Row, Sqlite};
use std::str::FromStr;
use std::{env, sync::Arc}; use std::{env, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -56,6 +63,7 @@ pub fn get_config() -> Config {
mail_user: "".to_string(), mail_user: "".to_string(),
mail_pass: "".to_string(), mail_pass: "".to_string(),
wolves_url: "".to_string(), wolves_url: "".to_string(),
wolves_api: "".to_string(),
committee_server: GuildId(0), committee_server: GuildId(0),
committee_role: RoleId(0), committee_role: RoleId(0),
committee_category: ChannelId(0), committee_category: ChannelId(0),
@ -418,6 +426,7 @@ pub fn random_string(len: usize) -> String {
pub mod set_roles { pub mod set_roles {
use super::*; use super::*;
use crate::common::database::DataBase;
pub async fn update_server(ctx: &Context, server: &Servers, remove_roles: &[Option<RoleId>], members_changed: &[UserId]) { pub async fn update_server(ctx: &Context, server: &Servers, remove_roles: &[Option<RoleId>], members_changed: &[UserId]) {
let db_lock = { let db_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;
@ -544,6 +553,7 @@ pub mod set_roles {
pub mod get_data { pub mod get_data {
use super::*; use super::*;
use crate::common::database::DataBase;
use crate::set_roles::update_server; use crate::set_roles::update_server;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use wolves_oxidised::WolvesUser; use wolves_oxidised::WolvesUser;