From 17ea052e5f14524d3dd4b16695b0eb599dc09d34 Mon Sep 17 00:00:00 2001 From: O3H Date: Sun, 9 Jun 2024 17:35:14 +0100 Subject: [PATCH] . --- bot/types.ts | 11 +++++------ bot/updater.ts | 33 ++++++++------------------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/bot/types.ts b/bot/types.ts index 40b41120..35c56c8e 100644 --- a/bot/types.ts +++ b/bot/types.ts @@ -63,18 +63,17 @@ export type MCSessionProfile = MCUserProfile & { } export type MapDB = { - getAlliance(name: string): Promise - getAlliances(skipCache: boolean): Promise - setAlliances(alliances: any[]): Promise + getAlliance(name: string): Promise + getAlliances(skipCache: boolean): Promise + setAlliances(alliances: DBAlliance[]): Promise + getResidents(): Promise + setResidents(residents: DBResident[]): Promise getTowns(): Promise setTowns(towns: any[]): Promise getNations(): Promise setNations(nations: any[]): Promise - getResidents(): Promise - setResidents(residents: any[]): Promise } - export type DBAlliance = { allianceName: string leaderName: string, diff --git a/bot/updater.ts b/bot/updater.ts index e83514ec..15e61188 100644 --- a/bot/updater.ts +++ b/bot/updater.ts @@ -115,28 +115,18 @@ async function updateAlliances(map: MapInstance) { if (!nations) return console.warn(`Couldn't update ${mapToString(map)} alliances, failed to fetch nations.`) const alliances = await map.db.getAlliances(true) as DBAlliance[] - if (!alliances) { - console.log("Couldn't update alliances, failed to fetch from DB.") - return - } + if (!alliances) return console.log("Couldn't update alliances, failed to fetch from DB.") const alliancesAmt = alliances.length for (let index = 0; index < alliancesAmt; index++) { const a = alliances[index] - if (nations.length > 0) { - const existing = nations.filter(n => a.nations.includes(n.name)) - - // No nations exist in the alliance anymore, disband it. - if (existing.length < 2) { - console.log(`Alliance '${a.allianceName}' has no nations.`) - - // TODO: Bring back disband logic (once bug is confirmed fixed) - - return - } + const existing = nations.filter(n => a.nations.includes(n.name)) + if (existing.length > 1) a.nations = existing.map(n => n.name) + else { + console.log(`Alliance '${a.allianceName}' has no nations.`) - a.nations = existing.map(n => n.name) + // TODO: Bring back disband logic (once bug is confirmed fixed) } const noInvite = "No discord invite has been set for this alliance" @@ -155,21 +145,14 @@ async function sendEmptyAllianceNotif(map: MapInstance) { const nations = await map.emc.Nations.all() if (!nations) return console.warn(`Couldn't check empty ${mapToString(map)} alliances, failed to fetch nations.`) - const alliances = await map.db.getAlliances(true) as DBAlliance[] - if (!alliances) return + const alliances = await map.db.getAlliances(true) + if (!alliances) return console.log("Couldn't send notifs! Failed to fetch alliances from DB.") const emptyAlliances: string[] = [] const alliancesAmt = alliances.length for (let index = 0; index < alliancesAmt; index++) { const a = alliances[index] - - if (nations.length < 1) { - emptyAlliances.push(a.allianceName) - console.log(`Alliance '${a.allianceName}' has less than 2 nations.`) - - continue - } const existing = nations.filter(n => a.nations.includes(n.name)) if (existing.length < 2) {