Skip to content

Commit

Permalink
yeyeyeyeyeyeyeyeyeyye
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jul 18, 2024
1 parent d3b7be1 commit b6ff995
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 134 deletions.
6 changes: 3 additions & 3 deletions aurora/commands/alliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default {
iconURL: message.author.displayAvatarURL()
})
.setFooter({
text: `Page ${++i}/${allData.length}`,
text: `Page ${i+1}/${allData.length}`,
iconURL: client.user.avatarURL()
})
}
Expand Down Expand Up @@ -1088,7 +1088,7 @@ async function sendAllianceList(client: Client, message: Message, m: Message, ar
.setDescription(allData[i])
.setTimestamp()
.setFooter({
text: `Page ${++i}/${len}`,
text: `Page ${i+1}/${len}`,
iconURL: client.user.avatarURL()
})
}
Expand Down Expand Up @@ -1118,7 +1118,7 @@ async function sendAllianceList(client: Client, message: Message, m: Message, ar
iconURL: message.author.displayAvatarURL()
})
.setFooter({
text: `Page ${++i}/${len}`,
text: `Page ${i+1}/${len}`,
iconURL: client.user.avatarURL()
})
}
Expand Down
34 changes: 6 additions & 28 deletions aurora/commands/nation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,7 @@ import News from "../../bot/objects/News.js"
import * as fn from '../../bot/utils/fn.js'
import * as database from "../../bot/utils/database.js"

import type { DBSquaremapNation } from "../../bot/types.js"

interface TownItem {
name: string
nation: string
chunks: number
residents: string[]
residentsAmt: number
onlineResidents?: string[]
}

interface NationItemMap {
[key: string]: NationItem
}

interface NationItem {
name: string
residents: string[]
onlineResidents: string[]
chunks: number
}
import type { DBSquaremapNation, NationItem, TownItem } from "../../bot/types.js"

export default {
name: "nation",
Expand Down Expand Up @@ -81,20 +61,18 @@ export default {
const nationName = cur.nation

if (nationName == "No Nation") continue
else townsWithDuplicates.push({
townsWithDuplicates.push({
name: cur.name,
nation: nationName,
residents: cur.residents,
residentsAmt: cur.residents.length,
onlineResidents: [],
chunks: cur.area
})
}

const ctx: NationItemMap = Object.create(null)

// Function to get rid of duplicates and add up residents and chunks.
townsWithDuplicates.forEach(function(town) {
// Gets rid of duplicates and adds up residents and chunks.
const ctx: Record<string, NationItem> = {}
townsWithDuplicates.forEach(town => {
if (!ctx[town.nation]) {

// TODO: Use set, with O(n) `has` lookup.
Expand All @@ -113,7 +91,7 @@ export default {
}

// If it already exists, add up stuff.
ctx[town.nation].residents = fn.removeDuplicates(fn.fastMerge(ctx[town.nation].residents, town.residents))
ctx[town.nation].residents = fn.fastMergeUnique(ctx[town.nation].residents, town.residents)
ctx[town.nation].onlineResidents = ctx[town.nation].residents.filter(resident =>
onlinePlayers.some(op => resident === op.name || resident.includes(op.name)
))
Expand Down
19 changes: 4 additions & 15 deletions aurora/commands/town.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@ import {
AURORA
} from "../../bot/utils/fn.js"

import type { DBNation, DBSquaremapTown } from "../../bot/types.js"

interface TownDataItem {
name: string
nation: string
residents?: string[]
onlineResidents: string[]
}

interface TownDataItemMap {
[key: string]: TownDataItem
}
import type { DBNation, DBSquaremapTown, TownDataItem } from "../../bot/types.js"

export default {
name: "town",
Expand Down Expand Up @@ -92,8 +81,8 @@ export default {
}

// Function to get rid of duplicates and add up residents and chunks.
const ctx: TownDataItemMap = Object.create(null)
onlineTownData.forEach(function(town) {
const ctx: Record<string, TownDataItem> = {}
onlineTownData.forEach(town => {
// If town doesnt exist, add it.
if (!ctx[town.name]) {
town.onlineResidents = town.residents.filter(r => ops.some(op => r === op.name))
Expand All @@ -106,7 +95,7 @@ export default {

onlineTownDataFinal.push(ctx[town.name])
}
}, ctx)
})

onlineTownDataFinal.sort((a, b) => b.onlineResidents.length - a.onlineResidents.length)

Expand Down
12 changes: 6 additions & 6 deletions aurora/commands/townless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
.setTitle("<a:loading:966778243615191110> Fetching townless players, this may take a moment.")
]})

const townlessPlayers = await Aurora.Players.townless().catch(() => null)
const townlessPlayers = await Aurora.Players.townless()
if (!townlessPlayers) return await m.edit({ embeds: [fn.fetchError] })
.then(m => setTimeout(() => m.delete(), 10000)).catch(() => {})

Expand All @@ -31,7 +31,7 @@ export default {
const allData = townlessPlayers.map(player => player.name)
.join('\n').match(/(?:^.*$\n?){1,10}/mg)

const botembed = []
const embeds: EmbedBuilder[] = []
let i = 0

const len = allData.length
Expand All @@ -57,16 +57,16 @@ export default {
}
else { // More than one page, create paginator.
for (; i < len; i++) {
botembed[i] = embed.setDescription(
embeds[i] = embed.setDescription(
"```" + townlessPlayers[0].name + "\n" + allData[i] + "```"
).setFooter({
text: `Page ${++i}/${len}`,
text: `Page ${i+1}/${len}`,
iconURL: client.user.avatarURL()
})
}

await m.edit({ embeds: [botembed[page]] })
.then(msg => fn.paginator(message.author.id, msg, botembed, page))
await m.edit({ embeds: [embeds[page]] })
.then(msg => fn.paginator(message.author.id, msg, embeds, page))
.catch(err => console.log(err))
}
}
Expand Down
6 changes: 2 additions & 4 deletions aurora/slashcommands/alliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ const allianceCmd: SlashCommand<typeof cmdData> = {
switch(cmd) {
case "create": {
// Make sure it doesn't exist already.
if (foundAlliance) return interaction.reply({embeds: [
new EmbedBuilder()
if (foundAlliance) return interaction.reply({embeds: [new EmbedBuilder()
.setColor(Colors.Red)
.setTitle("Error creating alliance!")
.setDescription("That alliance already exists.\nChoose another name or disband/rename the current one.")
Expand All @@ -86,8 +85,7 @@ const allianceCmd: SlashCommand<typeof cmdData> = {
}
case "edit": {
// Make sure it exists already.
if (!foundAlliance) return interaction.reply({embeds: [
new EmbedBuilder()
if (!foundAlliance) return interaction.reply({embeds: [new EmbedBuilder()
.setColor(Colors.Red)
.setTitle("Error editing alliance!")
.setDescription("That alliance does not exist.")
Expand Down
33 changes: 15 additions & 18 deletions aurora/slashcommands/nation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import News from "../../bot/objects/News.js"
import type { SquaremapTown } from 'earthmc'
import { Aurora, NotFoundError } from 'earthmc'

import type { DBSquaremapNation } from '../../bot/types.js'
import type { DBSquaremapNation, NationItem, TownItem } from '../../bot/types.js'

export default {
name: "nation",
Expand All @@ -35,9 +35,6 @@ export default {

await interaction.deferReply()

const townsWithDuplicates = []
const nationsWithoutDuplicates = []

let nations = await database.Aurora.getNations()

// TODO: Should probably handle this error case
Expand All @@ -47,6 +44,9 @@ export default {
let comparator = interaction.options.getString("comparator")

if (comparator != null) {
const townsWithDuplicates: TownItem[] = []
const nationsWithoutDuplicates: NationItem[] = []

comparator = comparator.toLowerCase()

if (comparator == "online") {
Expand All @@ -63,29 +63,26 @@ export default {
const nationName = cur.nation

if (nationName == "No Nation") continue
const townData = {
townsWithDuplicates.push({
name: cur.name,
nation: nationName,
residents: cur.residents.length,
residentNames: cur.residents,
residents: cur.residents,
onlineResidents: [],
chunks: cur.area
}

townsWithDuplicates.push(townData)
})
}

// Gets rid of duplicates and add up residents and chunks.
const ctx: Record<string, any> = {}
// Gets rid of duplicates and adds up residents and chunks.
const ctx: Record<string, NationItem> = {}
townsWithDuplicates.forEach(town => {
if (!ctx[town.nation]) {
const onlineResidents = town.residentNames.filter(resident =>
const onlineResidents = town.residents.filter(resident =>
onlinePlayers.some(op => resident === op.name || resident.includes(op.name)
))

ctx[town.nation] = {
nation: town.nation,
residentNames: town.residentNames,
name: town.nation,
residents: town.residents,
onlineResidents: onlineResidents,
chunks: 0
}
Expand All @@ -95,15 +92,15 @@ export default {

// If it already exists, add up stuff.
ctx[town.nation].chunks += town.chunks
ctx[town.nation].residentNames = fn.removeDuplicates(ctx[town.nation].residentNames.concat(town.residentNames))
ctx[town.nation].onlineResidents = ctx[town.nation].residentNames.filter(resident =>
ctx[town.nation].residents = fn.fastMergeUnique(ctx[town.nation].residents, town.residents)
ctx[town.nation].onlineResidents = ctx[town.nation].residents.filter(resident =>
onlinePlayers.some(op => resident === op.name || resident.includes(op.name)
))
})

const allData = nationsWithoutDuplicates
.sort((a, b) => b.onlineResidents.length - a.onlineResidents.length)
.map(nation => nation.nation + " - " + nation.onlineResidents.length)
.map(nation => nation.name + " - " + nation.onlineResidents.length)
.join('\n').match(/(?:^.*$\n?){1,10}/mg)

new CustomEmbed(client, `Nation Info | Online Residents`)
Expand Down
2 changes: 1 addition & 1 deletion aurora/slashcommands/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
run: async (_: Client, interaction: ChatInputCommandInteraction) => {
await interaction.deferReply()

const server = await MojangLib.servers.get("play.earthmc.net").catch(() => {})
const server = await MojangLib.servers.get("play.earthmc.net")

const mapRes = await database.Aurora.getOnlinePlayerData()
//const nova = await database.Nova.getOnlinePlayerData().catch(() => {})
Expand Down
26 changes: 12 additions & 14 deletions aurora/slashcommands/town.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

import { Aurora, formatString, NotFoundError } from 'earthmc'

import type { DBNation, DBSquaremapTown } from '../../bot/types.js'
import type { DBNation, DBSquaremapTown, TownDataItem } from '../../bot/types.js'

export default {
name: "town",
Expand Down Expand Up @@ -57,11 +57,11 @@ export default {
const comparator = args2.toLowerCase()

if (comparator == "online") {
const onlinePlayers = await Aurora.Players.online().catch(() => {})
if (!onlinePlayers) return await interaction.editReply({ embeds: [fetchError] })
const ops = await Aurora.Players.online().catch(() => {})
if (!ops) return await interaction.editReply({ embeds: [fetchError] })

const onlineTownData = []
const onlineTownDataFinal = []
const onlineTownData: TownDataItem[] = []
const onlineTownDataFinal: TownDataItem[] = []

const len = towns.length
for (let i = 0; i < len; i++) {
Expand All @@ -70,33 +70,31 @@ export default {
onlineTownData.push({
name: cur.name,
nation: cur.nation,
residentNames: cur.residents,
onlineResidents: [],
onlineResidentAmount: 0
residents: cur.residents,
onlineResidents: []
})
}

// Function to get rid of duplicates and add up residents and chunks.
const ctx: Record<string, any> = {}
const ctx: Record<string, TownDataItem> = {}
onlineTownData.forEach(a => {
// If town doesnt exist, add it.
if (!ctx[a.name]) {
a.onlineResidents = a.residentNames.filter(resident => onlinePlayers.find(op => resident === op.name))
a.onlineResidents = a.residents.filter(res => ops.find(op => res === op.name))

ctx[a.name] = {
name: a.name,
nation: a.nation,
onlineResidents: a.onlineResidents,
onlineResidentAmount: a.onlineResidents.length
onlineResidents: a.onlineResidents
}

onlineTownDataFinal.push(ctx[a.name])
}
})

onlineTownDataFinal.sort((a, b) => b.onlineResidentAmount - a.onlineResidentAmount)
onlineTownDataFinal.sort((a, b) => b.onlineResidents.length - a.onlineResidents.length)

const allData = onlineTownDataFinal.map(town => `${town.name} (${town.nation}) - ${town.onlineResidentAmount}`)
const allData = onlineTownDataFinal.map(town => `${town.name} (${town.nation}) - ${town.onlineResidents.length}`)
.join('\n').match(/(?:^.*$\n?){1,10}/mg)

new CustomEmbed(client, "Town Info | Online Residents")
Expand Down
2 changes: 1 addition & 1 deletion aurora/slashcommands/townless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
botEmbed[i] = embed(
townlessLen,
"```" + townlessPlayers[0].name + "\n" + allData[i] + "```",
{ text: `Page ${++i}/${len}`, iconURL: client.user.avatarURL() }
{ text: `Page ${i+1}/${len}`, iconURL: client.user.avatarURL() }
)
}

Expand Down
Loading

0 comments on commit b6ff995

Please sign in to comment.