feat; modified the command that interacts with teh server to accomodate bedrock players
For #26
This commit is contained in:
parent
ee0c8f0987
commit
0478f634fa
2 changed files with 17 additions and 6 deletions
|
@ -107,7 +107,7 @@ pub(crate) mod user {
|
|||
// get a list of servers that the user is a member of
|
||||
if let Ok(servers) = get_servers(&db, &command.user.id).await {
|
||||
for server in servers {
|
||||
whitelist_update(&vec![username.to_string()], &server.minecraft, &config.discord_token_minecraft).await;
|
||||
whitelist_update(&vec![(username.to_string(), java)], &server.minecraft, &config.discord_token_minecraft).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
19
src/lib.rs
19
src/lib.rs
|
@ -135,6 +135,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 {
|
||||
fn from_row(row: &'r SqliteRow) -> Result<Self, Error> {
|
||||
|
@ -159,6 +160,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")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -704,7 +706,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, true));
|
||||
}
|
||||
}
|
||||
if !usernames.is_empty() {
|
||||
|
@ -768,13 +773,19 @@ struct BodyDelete {
|
|||
files: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn whitelist_update(add: &Vec<String>, server: &str, token: &str) {
|
||||
pub async fn whitelist_update(add: &Vec<(String, bool)>, 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 {
|
||||
for (name, java) in add {
|
||||
let data = if *java {
|
||||
BodyCommand {
|
||||
command: format!("whitelist add {name}"),
|
||||
}
|
||||
} else {
|
||||
BodyCommand {
|
||||
command: format!("fwhitelist add {name}"),
|
||||
}
|
||||
};
|
||||
post(&format!("{url_base}/command"), &bearer, &data).await;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue