Skip to content

Commit

Permalink
fix no. 891023345
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Apr 30, 2024
1 parent 52424c6 commit 4b51d22
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 48 deletions.
48 changes: 24 additions & 24 deletions aurora/commands/playerposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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") {
Expand All @@ -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)
Expand All @@ -73,25 +72,25 @@ 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 + ")"
))

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()
Expand All @@ -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 + ")"
)
Expand Down Expand Up @@ -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(() => {})
}
}
Expand Down
8 changes: 4 additions & 4 deletions aurora/slashcommands/playerposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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())) {
Expand Down Expand Up @@ -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})`)
)

Expand Down
12 changes: 10 additions & 2 deletions bot/utils/nova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 18 additions & 18 deletions nova/commands/playerposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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())
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 + ")"
)
Expand All @@ -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(
Expand All @@ -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 + ")"
)
Expand All @@ -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
Expand Down

0 comments on commit 4b51d22

Please sign in to comment.