From a06058313aeac6ffc8295858f04220891c0f4f7f Mon Sep 17 00:00:00 2001 From: O3H Date: Sun, 9 Jun 2024 14:28:08 +0100 Subject: [PATCH] ?? --- aurora/slashcommands/nationset.ts | 39 +++++++++++++------------------ aurora/slashcommands/staff.ts | 2 +- aurora/slashcommands/status.ts | 12 +++++----- bot/types.ts | 13 +++++++++-- bot/updater.ts | 25 +++++++------------- bot/utils/linking.ts | 12 +--------- bot/utils/nova.ts | 2 +- common/alliance.ts | 4 ++++ common/nation.ts | 4 ++++ common/town.ts | 4 ++++ 10 files changed, 57 insertions(+), 60 deletions(-) diff --git a/aurora/slashcommands/nationset.ts b/aurora/slashcommands/nationset.ts index 70b050b6..b67cb08d 100644 --- a/aurora/slashcommands/nationset.ts +++ b/aurora/slashcommands/nationset.ts @@ -29,16 +29,14 @@ export default { const nationIndex = nations.findIndex(n => n.name.toLowerCase() == nationName) const nation = nations.find(n => n.name.toLowerCase() == nationName) - let save = false - if (!nation) return interaction.editReply({embeds: [new EmbedBuilder() .setDescription(`${nationName} is not a registered nation, please try again.`) .setColor(Colors.Red) .setTimestamp() - ]}).then((m: Message) => setTimeout(() => m.delete(), 10000)).catch(() => {}) + ]}).then(m => setTimeout(() => m.delete(), 10000)).catch(() => {}) - const userID = interaction.user.id, - linkedPlayer = await getLinkedPlayer(userID) + const userID = interaction.user.id + const linkedPlayer = await getLinkedPlayer(userID) const canEdit = fn.botDevs.includes(userID) || nation.king.toLowerCase() == linkedPlayer.name.toLowerCase() if (!linkedPlayer || !canEdit) return interaction.editReply({embeds: [ @@ -46,11 +44,16 @@ export default { .setDescription("You must be linked and be the owner of this nation in order to edit it.") .setColor(Colors.Red) .setTimestamp() - ]}).then((m: Message) => setTimeout(() => m.delete(), 10000)).catch(() => {}) + ]}).then(m => setTimeout(() => m.delete(), 10000)).catch(() => {}) const value = interaction.options.getString("value") const cleared = value.toLowerCase() == "none" || value.toLowerCase() == "clear" + const save = (n: any) => { + nations[nationIndex] = n + mapDB.setNations(nations) + } + switch (interaction.options.getString("type").toLowerCase()) { case "prefix": { if (cleared) nation.kingPrefix = "" @@ -63,8 +66,7 @@ export default { .setTimestamp() await interaction.editReply({ embeds: [embed] }) - - break + return save(nation) } case "discord": { if (cleared) nation.discord = "" @@ -89,8 +91,7 @@ export default { .setTimestamp() await interaction.editReply({ embeds: [embed] }) - - break + return save(nation) } case "flag": { if (cleared) nation.flag = "" @@ -115,20 +116,12 @@ export default { if (!cleared) embed.setThumbnail(value) await interaction.editReply({ embeds: [embed] }) - break - } - default: { - save = false - return interaction.editReply({embeds: [new EmbedBuilder() - .setDescription("<:red_tick:1036290475012915270> Invalid arguments! Options: Prefix, Discord or Flag") - .setColor(Colors.Red) - ]}).then((m: Message) => setTimeout(() => m.delete(), 10000)).catch(() => {}) + return save(nation) } - } - - if (save) { - nations[nationIndex] = nation - mapDB.setNations(nations) + default: return interaction.editReply({embeds: [new EmbedBuilder() + .setDescription("<:red_tick:1036290475012915270> Invalid arguments! Options: Prefix, Discord or Flag") + .setColor(Colors.Red) + ]}).then((m: Message) => setTimeout(() => m.delete(), 10000)).catch(() => {}) } }, data: new SlashCommandBuilder().setName("nationset") .setDescription(desc) diff --git a/aurora/slashcommands/staff.ts b/aurora/slashcommands/staff.ts index 80d4b8c0..7458a5ec 100644 --- a/aurora/slashcommands/staff.ts +++ b/aurora/slashcommands/staff.ts @@ -8,7 +8,7 @@ import { Aurora } from "earthmc" import * as fn from '../../bot/utils/fn.js' import * as database from "../../bot/utils/database.js" -async function getStaff(activeOnly: boolean) { +const getStaff = async(activeOnly: boolean) => { const players = await database.getPlayers() const staffList = activeOnly ? fn.staff.active : fn.staff.all() diff --git a/aurora/slashcommands/status.ts b/aurora/slashcommands/status.ts index 5db18ec0..e3dbf7fb 100644 --- a/aurora/slashcommands/status.ts +++ b/aurora/slashcommands/status.ts @@ -4,12 +4,12 @@ import { Colors, EmbedBuilder } from "discord.js" -import { MojangLib } from 'earthmc' +import { MojangLib, MapResponse } from 'earthmc' import * as fn from '../../bot/utils/fn.js' import * as database from "../../bot/utils/database.js" - -const status = data => !data ? "Offline :red_circle:" : "Online :green_circle:" + +const status = (data: MapResponse) => !data ? "Offline :red_circle:" : "Online :green_circle:" export default { name: "status", @@ -24,9 +24,9 @@ export default { .setFooter(fn.devsFooter(client)) .setTimestamp() - const serverData = await MojangLib.servers.get("play.earthmc.net").catch(() => {}), - auroraData = await database.Aurora.getTownyData().catch(() => {}), - novaData = await database.Nova.getTownyData().catch(() => {}) + const serverData = await MojangLib.servers.get("play.earthmc.net").catch(() => null) + const auroraData = await database.Aurora.getTownyData().catch(() => null) + const novaData = await database.Nova.getTownyData().catch(() => null) if (serverData && (!auroraData && !novaData)) embed.setDescription("The server seems to be up, but dynmap is unavailable!") diff --git a/bot/types.ts b/bot/types.ts index c6546b37..5fef2cd8 100644 --- a/bot/types.ts +++ b/bot/types.ts @@ -8,7 +8,7 @@ import { } from "discord.js" import { Map } from "earthmc" -import { WriteResult } from "firebase-admin/firestore" +import { Timestamp, WriteResult } from "firebase-admin/firestore" export type BaseCommand = { name: string @@ -93,4 +93,13 @@ export const SkinType3D = { HEAD: 'head', BUST: 'bust', FULL: 'full' -} as const \ No newline at end of file +} as const + +export type ResidentProfile = { + name: string + linkedID: string | number + lastOnline: { + nova: Date | Timestamp + aurora: Date | Timestamp + } +} \ No newline at end of file diff --git a/bot/updater.ts b/bot/updater.ts index 97cc0bf3..f03ea902 100644 --- a/bot/updater.ts +++ b/bot/updater.ts @@ -31,7 +31,7 @@ import { Message, TextChannel } from "discord.js" -import type { MapInstance } from "./types.js" +import type { MapInstance, ResidentProfile } from "./types.js" //#endregion //#region Call Updates @@ -139,26 +139,19 @@ async function updatePlayerData(players: any[], map: MapInstance) { for (let i = 0; i < len; i++) { const op = onlinePlayers[i] - const playerInDB = players.find(p => p.name == op.name), - playerIndex = players.findIndex(p => p.name == op.name) + const playerInDB = players.find(p => p.name == op.name) + const playerIndex = players.findIndex(p => p.name == op.name) - const player: { - name: string - lastOnline: { - nova: unknown - aurora: unknown - } - linkedID?: string - } = { + const player = { name: op.name, lastOnline: { nova: playerInDB?.lastOnline?.nova ?? null, aurora: playerInDB?.lastOnline?.aurora ?? null } - } + } as ResidentProfile - const linkedId = playerInDB?.linkedID - if (linkedId) player.linkedID = linkedId + const linkedID = playerInDB?.linkedID + if (linkedID) player.linkedID = linkedID player.lastOnline[mapName] = now @@ -194,8 +187,8 @@ async function updateMapData(map: MapInstance) { //#endregion //#region Resident Logic - const tLen = townsArray.length, - residentsArray = [] + const tLen = townsArray.length + const residentsArray = [] for (let i = 0; i < tLen; i++) { const currentTown = townsArray[i] diff --git a/bot/utils/linking.ts b/bot/utils/linking.ts index 0e274420..aef19a36 100644 --- a/bot/utils/linking.ts +++ b/bot/utils/linking.ts @@ -1,16 +1,6 @@ import { setPlayers, getPlayers} from "./database.js" import { Players } from "./minecraft.js" - -import { Timestamp } from "firebase-admin/firestore" - -type ResidentProfile = { - name: string - linkedID: string | number - lastOnline: { - nova: Date | Timestamp - aurora: Date | Timestamp - } -} +import { ResidentProfile } from "../types.js" const strEqual = (p: { name: string }, name: string) => p.name.toLowerCase() == name.toLowerCase() diff --git a/bot/utils/nova.ts b/bot/utils/nova.ts index 42862bd4..2daf3920 100644 --- a/bot/utils/nova.ts +++ b/bot/utils/nova.ts @@ -163,7 +163,7 @@ async function setAlliances(alliances: any[]) { return allianceDoc.set({ allianceArray: alliances }) } -const length = x => x.length +const length = (x: string | any[]) => x.length export { getResidents, setResidents, diff --git a/common/alliance.ts b/common/alliance.ts index 38127b50..85536c94 100644 --- a/common/alliance.ts +++ b/common/alliance.ts @@ -8,6 +8,10 @@ class AllianceHelper extends BaseHelper { super(client, isNova) this.embed.setColor(Colors.DarkBlue) } + + async setupEmbed() { + + } } export { diff --git a/common/nation.ts b/common/nation.ts index a8b52631..5c628652 100644 --- a/common/nation.ts +++ b/common/nation.ts @@ -8,6 +8,10 @@ class NationHelper extends BaseHelper { super(client, isNova) this.embed.setColor(Colors.Orange) } + + async setupEmbed() { + + } } export { diff --git a/common/town.ts b/common/town.ts index 6ccd063a..0b9e9083 100644 --- a/common/town.ts +++ b/common/town.ts @@ -8,6 +8,10 @@ class TownHelper extends BaseHelper { super(client, isNova) this.embed.setColor(Colors.Green) } + + async setupEmbed() { + + } } export {