feat: added support for multiple minecraft servers per discord server
Closes #9
This commit is contained in:
parent
c446c10f2d
commit
0f774258a1
4 changed files with 66 additions and 53 deletions
45
src/lib.rs
45
src/lib.rs
|
@ -697,18 +697,16 @@ 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_minecraft: &Option<String>, db: &Pool<Sqlite>, g_id: &GuildId, config: &Config) {
|
||||
if let Some(server_id) = server_minecraft {
|
||||
let mut usernames = vec![];
|
||||
for member in get_server_member_bulk(db, g_id).await {
|
||||
if let Some(x) = member.minecraft {
|
||||
usernames.push(x);
|
||||
}
|
||||
}
|
||||
if !usernames.is_empty() {
|
||||
whitelist_update(&usernames, server_id, &config.discord_minecraft).await;
|
||||
pub async fn update_server(server_id: &String, 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 {
|
||||
usernames.push(x);
|
||||
}
|
||||
}
|
||||
if !usernames.is_empty() {
|
||||
whitelist_update(&usernames, server_id, &config.discord_minecraft).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn post<T: Serialize>(url: &str, bearer: &str, data: &T) {
|
||||
|
@ -770,3 +768,30 @@ pub async fn whitelist_wipe(server: &str, token: &str) {
|
|||
};
|
||||
post(&format!("{url_base}/command"), &bearer, &data).await;
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_minecraft_config(db: &Pool<Sqlite>) -> Vec<Minecraft> {
|
||||
sqlx::query_as::<_, Minecraft>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM minecraft
|
||||
"#,
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub async fn get_minecraft_config_server(db: &Pool<Sqlite>, g_id: GuildId) -> Option<Minecraft> {
|
||||
sqlx::query_as::<_, Minecraft>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM minecraft
|
||||
WHERE server_discord = ?1
|
||||
"#,
|
||||
)
|
||||
.bind(*g_id.as_u64() as i64)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue