diff --git a/aurora/commands/playerposition.ts b/aurora/commands/playerposition.ts index 585ad37c..d7c8ca33 100644 --- a/aurora/commands/playerposition.ts +++ b/aurora/commands/playerposition.ts @@ -30,8 +30,8 @@ export default { .setFooter(fn.devsFooter(client))] }) - const townydata = await db.Aurora.getOnlinePlayerData() as any - if (!townydata) return m.edit({embeds: [new EmbedBuilder() + const opsData = await db.Aurora.getOnlinePlayerData() + if (!opsData) return m.edit({embeds: [new EmbedBuilder() .setTimestamp() .setColor(Colors.Red) .setTitle("Connection Issues") @@ -40,7 +40,7 @@ export default { .setFooter(fn.devsFooter(client))] }).then((m => setTimeout(() => m.delete(), 10000))).catch(() => {}) - const onlinePlayers = townydata.players + const onlinePlayers = opsData.players const arg0 = args[0]?.toLowerCase() if (arg0 != "live") { @@ -50,8 +50,7 @@ export default { const acc = foundPlayer.account if (foundPlayer.world == "-some-other-bogus-world-") { - return m.edit({embeds: [ - new EmbedBuilder() + return m.edit({embeds: [new EmbedBuilder() .setTitle("Location Unavailable") .setDescription(`${acc} seems to be invisible, under a block, or in the nether. Please try again later.`) .setColor(Colors.DarkGold) @@ -73,7 +72,7 @@ export default { if (acc !== foundPlayerNickname) locationEmbed.addFields(fn.embedField("Nickname", foundPlayerNickname)) - locationEmbed.addFields(fn.embedField("Coordinates", "X: " + foundPlayer.x + "\nY: " + (foundPlayer.y - 1) + "\nZ: " + foundPlayer.z)) + locationEmbed.addFields(fn.embedField("Coordinates", "X: " + foundPlayer.x + "\nY: " + (Number(foundPlayer.y) - 1) + "\nZ: " + foundPlayer.z)) locationEmbed.addFields(fn.embedField( "Dynmap Link", "[" + foundPlayer.x + ", " + foundPlayer.z + "]" + "(https://earthmc.net/map/aurora/?worldname=earth&mapname=flat&zoom=7&x=" + foundPlayer.x + "&y=64&z=" + foundPlayer.z + ")" @@ -81,17 +80,17 @@ export default { return m.edit({ embeds: [locationEmbed] }).catch(() => {}) } - } else return m.edit({embeds: [ - new EmbedBuilder() - .setTitle("Error fetching player") - .setDescription(args[0] + " isn't online or does not exist!") - .setTimestamp() - .setColor(Colors.Red) - .setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL() }) + } + + return m.edit({embeds: [new EmbedBuilder() + .setTitle("Error fetching player") + .setDescription(args[0] + " isn't online or does not exist!") + .setTimestamp() + .setColor(Colors.Red) + .setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL() }) ]}).then((m => setTimeout(() => m.delete(), 10000))).catch(() => {}) } else { - if (!args[1]) return m.edit({embeds: [ - new EmbedBuilder() + if (!args[1]) return m.edit({embeds: [new EmbedBuilder() .setTitle("No player specified") .setDescription("Please specify a player! Usage: `/pos live playerName`") .setTimestamp() @@ -118,7 +117,7 @@ export default { .setFooter(fn.devsFooter(client)) .setTitle("Location Info | " + foundPlayerOld.account) .setDescription( - "Live Location: \nX: " + foundPlayerOld.x + "\nY: " + (foundPlayerOld.y - 1) + "\nZ: " + foundPlayerOld.z + + "Live Location: \nX: " + foundPlayerOld.x + "\nY: " + (Number(foundPlayerOld.y) - 1) + "\nZ: " + foundPlayerOld.z + "\n\nDynmap Link: " + "[" + foundPlayerOld.x + ", " + foundPlayerOld.z + "]" + "(https://earthmc.net/map/aurora/?worldname=earth&mapname=flat&zoom=7&x=" + foundPlayerOld.x + "&y=64&z=" + foundPlayerOld.z + ")" ) @@ -188,22 +187,23 @@ export default { liveLocationEmbed.setFooter({ text: `Embed will timeout in: ${minutes}m ${seconds}s` }) setTimeout(livePosFunc, 5000) } else { - if (lastValidLocation == null || lastValidLocation == undefined) return m.edit({embeds: [ - new EmbedBuilder() - .setTitle("Live Location | Timed Out") - .setDescription("No last known location!") + const embed = new EmbedBuilder() .setColor(Colors.DarkVividPink) .setTimestamp() - ]}).catch(() => {}) - return m.edit({embeds: [new EmbedBuilder() + if (lastValidLocation == null || lastValidLocation == undefined) { + return m.edit({embeds: [embed + .setTitle("Live Location | Timed Out") + .setDescription("No last known location!") + ]}).catch(() => {}) + } + + return m.edit({embeds: [embed .setTitle("Live Location | " + foundPlayerOld.account + " | Timed Out") .setDescription( "Last Known Location: \nX: " + lastValidLocation.x + "\nY: " + (lastValidLocation.y - 1) + "\nZ: " + lastValidLocation.z + "\n\nDynmap Link: " + "[" + lastValidLocation.x + ", " + lastValidLocation.z + "]" + "(https://earthmc.net/map/aurora/?worldname=earth&mapname=flat&zoom=7&x=" + lastValidLocation.x + "&y=64&z=" + lastValidLocation.z + ")") - .setColor(Colors.DarkVividPink) - .setTimestamp() ]}).catch(() => {}) } } diff --git a/aurora/slashcommands/playerposition.ts b/aurora/slashcommands/playerposition.ts index cfe1b9b9..624e859a 100644 --- a/aurora/slashcommands/playerposition.ts +++ b/aurora/slashcommands/playerposition.ts @@ -22,8 +22,8 @@ export default { .setFooter(fn.devsFooter(client)) ], ephemeral: true}) - const townyData = await db.Aurora.getOnlinePlayerData() - if (!townyData) return interaction.reply({embeds: [new EmbedBuilder() + const opsData = await db.Aurora.getOnlinePlayerData() + if (!opsData) return interaction.reply({embeds: [new EmbedBuilder() .setTimestamp() .setColor(Colors.Red) .setTitle("Connection Issues") @@ -32,7 +32,7 @@ export default { .setFooter(fn.devsFooter(client)) ]}).then((m: any) => setTimeout(() => m.delete(), 10000)).catch(() => {}) - const ops = townyData.players + const ops = opsData.players const foundPlayer = ops.find(op => op.account.toLowerCase() == player.toLowerCase()) if (foundPlayer && !fn.botDevs.includes(player.toLowerCase())) { @@ -60,7 +60,7 @@ export default { const { x, y, z } = foundPlayer locationEmbed.addFields( - fn.embedField("Coordinates", `X: ${x}\nY: ${parseInt(String(y))-1}\nZ: ${z}`), + fn.embedField("Coordinates", `X: ${x}\nY: ${Number(y) - 1}\nZ: ${z}`), fn.embedField("Dynmap Link", `[${x}, ${z}](https://earthmc.net/map/aurora/?worldname=earth&mapname=flat&zoom=6&x=${x}&y=64&z=${z})`) ) diff --git a/bot/utils/nova.ts b/bot/utils/nova.ts index 1b76b0d6..5368e62d 100644 --- a/bot/utils/nova.ts +++ b/bot/utils/nova.ts @@ -3,10 +3,18 @@ import cache from 'memory-cache' import { request } from "undici" import { db } from "../constants.js" +import { MapResponse, PlayersResponse } from "earthmc" const novaUrl = 'https://earthmc.net/map/nova/' -const getTownyData = () => request(`${novaUrl}standalone/MySQL_markers.php?marker=_markers_/marker_earth.json`).then(res => res.body.json()) -const getOnlinePlayerData = () => request(`${novaUrl}standalone/MySQL_update.php?world=earth`).then(res => res.body.json()) +const getTownyData = async () => { + const res = await request(`${novaUrl}standalone/MySQL_markers.php?marker=_markers_/marker_earth.json`) + return await res.body.json() as MapResponse +} + +const getOnlinePlayerData = async () => { + const res = await request(`${novaUrl}standalone/MySQL_update.php?world=earth`) + return await res.body.json() as PlayersResponse +} async function getResidents() { const residentDataCollection = db.collection("residentData") diff --git a/nova/commands/playerposition.ts b/nova/commands/playerposition.ts index 081849df..445181df 100644 --- a/nova/commands/playerposition.ts +++ b/nova/commands/playerposition.ts @@ -26,8 +26,8 @@ export default { .setFooter(fn.devsFooter(client))] }) - const townyData = await db.Nova.getOnlinePlayerData() as any - if (!townyData) return m.edit({embeds: [new EmbedBuilder() + const opsData = await db.Nova.getOnlinePlayerData() + if (!opsData) return m.edit({embeds: [new EmbedBuilder() .setTimestamp() .setColor(Colors.Red) .setTitle("Connection Issues") @@ -36,7 +36,7 @@ export default { .setFooter(fn.devsFooter(client))] }).then((m => setTimeout(() => m.delete(), 10000))).catch(() => {}) - const onlinePlayers = townyData.players + const onlinePlayers = opsData.players if (args[0].toLowerCase() != "live") { const foundPlayer = onlinePlayers.find(op => op.account.toLowerCase() == args[0].toLowerCase()) @@ -67,7 +67,7 @@ export default { locationEmbed.addFields(fn.embedField( "Coordinates", - "X: " + foundPlayer.x + "\nY: " + (foundPlayer.y - 1) + "\nZ: " + foundPlayer.z + "X: " + foundPlayer.x + "\nY: " + (Number(foundPlayer.y) - 1) + "\nZ: " + foundPlayer.z )) locationEmbed.addFields(fn.embedField( @@ -109,7 +109,7 @@ export default { const liveLocationEmbed = new EmbedBuilder() .setTitle("(Nova) Location Info | " + foundPlayerOld.account) - .setDescription("Live Location: \nX: " + foundPlayerOld.x + "\nY: " + (foundPlayerOld.y - 1) + "\nZ: " + foundPlayerOld.z + + .setDescription("Live Location: \nX: " + foundPlayerOld.x + "\nY: " + (Number(foundPlayerOld.y) - 1) + "\nZ: " + foundPlayerOld.z + "\n\nDynmap Link: " + "[" + foundPlayerOld.x + ", " + foundPlayerOld.z + "]" + "(https://earthmc.net/map/nova/?worldname=earth&mapname=flat&zoom=7&x=" + foundPlayerOld.x + "&y=64&z=" + foundPlayerOld.z + ")" ) @@ -118,14 +118,14 @@ export default { .setFooter(fn.devsFooter(client)) .setTimestamp() - let lastValidLocation = { x: 0, y: 0, z: 0 }, - timedOut = false + let lastValidLocation = { x: 0, y: 0, z: 0 } + let timedOut = false - const fiveMin = 5*60*1000, - countDownDate = Date.now() + fiveMin + const fiveMin = 5*60*1000 + const countDownDate = Date.now() + fiveMin async function livePosFunc() { - const townyData = await db.Nova.getOnlinePlayerData() as any + const townyData = await db.Nova.getOnlinePlayerData() if (!townyData) return m.edit({embeds: [new EmbedBuilder() .setTitle("Connection Issues | Timed Out") .setDescription( @@ -152,13 +152,13 @@ export default { // If they are in the earth world if (foundPlayerNew.world != "-some-other-bogus-world-") { lastValidLocation = { - x: foundPlayerNew.x, - y: foundPlayerNew.y, - z: foundPlayerNew.z + x: Number(foundPlayerNew.x), + y: Number(foundPlayerNew.y), + z: Number(foundPlayerNew.z) } liveLocationEmbed.setDescription( - "Live Location: \nX: " + foundPlayerNew.x + "\nY: " + (foundPlayerNew.y - 1) + "\nZ: " + foundPlayerNew.z + + "Live Location: \nX: " + foundPlayerNew.x + "\nY: " + (Number(foundPlayerNew.y) - 1) + "\nZ: " + foundPlayerNew.z + "\n\nDynmap Link: " + "[" + foundPlayerNew.x + ", " + foundPlayerNew.z + "]" + "(https://earthmc.net/map/nova/?worldname=earth&mapname=flat&zoom=7&x=" + foundPlayerNew.x + "&y=64&z=" + foundPlayerNew.z + ")" ) @@ -178,10 +178,10 @@ export default { } if (!timedOut) { - const now = new Date().getTime(), - diff = countDownDate - now, - minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)), - seconds = Math.floor((diff % (1000 * 60)) / 1000) + const now = new Date().getTime() + const diff = countDownDate - now + const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)) + const seconds = Math.floor((diff % (1000 * 60)) / 1000) liveLocationEmbed.setFooter({text: `Embed will timeout in: ${minutes}m ${seconds}s`}) setTimeout(livePosFunc, 5000) // Timeout after 5 minutes