Skip to content

Commit

Permalink
??
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jun 9, 2024
1 parent 1fdef0e commit a060583
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 60 deletions.
39 changes: 16 additions & 23 deletions aurora/slashcommands/nationset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,31 @@ 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: [
new EmbedBuilder()
.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 = ""
Expand All @@ -63,8 +66,7 @@ export default {
.setTimestamp()

await interaction.editReply({ embeds: [embed] })

break
return save(nation)
}
case "discord": {
if (cleared) nation.discord = ""
Expand All @@ -89,8 +91,7 @@ export default {
.setTimestamp()

await interaction.editReply({ embeds: [embed] })

break
return save(nation)
}
case "flag": {
if (cleared) nation.flag = ""
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion aurora/slashcommands/staff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
12 changes: 6 additions & 6 deletions aurora/slashcommands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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!")
Expand Down
13 changes: 11 additions & 2 deletions bot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,4 +93,13 @@ export const SkinType3D = {
HEAD: 'head',
BUST: 'bust',
FULL: 'full'
} as const
} as const

export type ResidentProfile = {
name: string
linkedID: string | number
lastOnline: {
nova: Date | Timestamp
aurora: Date | Timestamp
}
}
25 changes: 9 additions & 16 deletions bot/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
12 changes: 1 addition & 11 deletions bot/utils/linking.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion bot/utils/nova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions common/alliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class AllianceHelper extends BaseHelper {
super(client, isNova)
this.embed.setColor(Colors.DarkBlue)
}

async setupEmbed() {

}
}

export {
Expand Down
4 changes: 4 additions & 0 deletions common/nation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class NationHelper extends BaseHelper {
super(client, isNova)
this.embed.setColor(Colors.Orange)
}

async setupEmbed() {

}
}

export {
Expand Down
4 changes: 4 additions & 0 deletions common/town.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class TownHelper extends BaseHelper {
super(client, isNova)
this.embed.setColor(Colors.Green)
}

async setupEmbed() {

}
}

export {
Expand Down

0 comments on commit a060583

Please sign in to comment.