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: silver
GPG key ID: 36F93D61BAD3FD7D
11 changed files with 62 additions and 47 deletions

View file

@ -42,6 +42,7 @@ pub struct ServerMembersWolves {
pub email: String,
pub discord: Option<UserId>,
pub minecraft: Option<String>,
pub minecraft_uid: Option<String>,
}
impl<'r> FromRow<'r, SqliteRow> for ServerMembersWolves {
@ -67,6 +68,7 @@ impl<'r> FromRow<'r, SqliteRow> for ServerMembersWolves {
email: row.try_get("email")?,
discord,
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::Config;
use crate::{whitelist_update, Config};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
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![];
for member in get_server_member_bulk(db, g_id).await {
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() {
@ -98,18 +101,6 @@ struct BodyDelete {
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) {
let url_base = format!("http://panel.games.skynet.ie/api/client/servers/{server}");
let bearer = format!("Bearer {token}");

View file

@ -199,11 +199,11 @@ pub mod committee {
for committee in &committees {
// 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()),
None => {
// 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),
Err(_) => None,
}
@ -211,16 +211,16 @@ pub mod committee {
};
// 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
.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
{
Ok(x) => {
// update teh channels name list
channels_name.insert(x.name.to_owned(), x.to_owned());
println!("Created channel: {}", &committee.name);
println!("Created channel: {}", &committee.name_profile);
}
Err(x) => {
dbg!("Unable to create channel: ", x);

View file

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