Skip to content

Commit

Permalink
grah
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jul 19, 2024
1 parent b6ff995 commit 3135a0a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
35 changes: 18 additions & 17 deletions aurora/commands/town.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ import {

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

const invalidUsageEmbed = () => new EmbedBuilder()
.setColor(Colors.Red)
.setTitle("Invalid Arguments")
.setDescription(
"**Command Usage**:\n" +
"Get info on a single town - `/town <name>`\n" +
"Show a page-by-page display of all towns - `/town list`\n" +
"Shows a list "
)

export default {
name: "town",
description: "Displays info for a town.",
slashCommand: true,
aliases: ["t"],
run: async (client: Client, message: Message, args: string[]) => {
const req = args.join(" ")
if (!req) return await message.reply({embeds: [new EmbedBuilder()
.setColor(Colors.Red)
.setTitle("Command Usage")
.setDescription("**Command Usage**:\nGet info on a single town - `/town <name>`\nShows a page-by-page display of all towns - `/town list`")
]}).then((m => setTimeout(() => m.delete(), 15000))).catch(() => {})
if (!req) return await message.reply({ embeds: [invalidUsageEmbed()] })
.then(m => setTimeout(() => m.delete(), 15000)).catch(() => {})

const m = await message.reply({embeds: [new EmbedBuilder()
.setTitle("<a:loading:966778243615191110> Fetching town data, this might take a moment.")
Expand Down Expand Up @@ -228,13 +235,7 @@ export default {
.editMessage(m)
}
else if (args.length > 3 || args.length == null || opt == null) {
return await m.edit({embeds: [new EmbedBuilder()
.setDescription("Invalid arguments! Usage: `/t townName` or `/t list`")
.setFooter(devsFooter(client))
.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL() })
.setTimestamp()
.setColor(Colors.Red)
]}).then(m => setTimeout(() => m.delete(), 10000)).catch(() => {})
return await m.edit({ embeds: [invalidUsageEmbed()] }).then(m => setTimeout(() => m.delete(), 10000)).catch(() => {})
}

//#region /t <name>
Expand Down Expand Up @@ -293,8 +294,8 @@ export default {
: townResidentsLength == 1 ? "Hermit " : "" }\`${mayor}\``, true))
}

const discord = townNation?.discord
const nationString = !discord ? `\`${town.nation}\`` : `[${townNation.name}](${townNation.discord})`
const nationWiki = town?.wikis.nation
const nationString = !nationWiki ? `\`${town.nation}\`` : `[${town.nation}](${nationWiki})`

townEmbed.addFields(
embedField("Nation", nationString, true),
Expand Down Expand Up @@ -340,7 +341,7 @@ export default {
"```" + town.residents.join(", ") + "```"
))
}
else townEmbed.addFields(embedField("Residents", townResidentsLength.toString()))
else townEmbed.addFields(embedField("Residents", `\`${townResidentsLength.toString()}\``))
}
else townEmbed.addFields(embedField("Residents", "There are no residents in this town?"))

Expand Down Expand Up @@ -434,9 +435,9 @@ async function sendList(client: Client, msg: Message, comparator: string, towns:
const townData = extractTownData(towns)
const allData = townData.map((town, index) => `**${(index + 1)}**. ${town.name} (**${town.nation}**)\n` +
`Residents: \`${town.residentNames.length}\`\n` +
`Chunks: \`${town.area}\`\n`
`Chunks: \`${town.area}\``
//`${wealthStr(town.wealth)}`
).join('\n\n').match(/(?:^.*$\n\n?){1,16}/mg)
).join('\n\n').match(/(?:^.*$\n\n?){1,15}/mg)

const embed = new CustomEmbed(client, "Town Info | Town List")
.setType(EntityType.Town)
Expand Down
4 changes: 2 additions & 2 deletions aurora/slashcommands/nation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ export default {
const alliances = await database.Aurora.getAlliances()
if (alliances) {
const nationAlliances = alliances
.filter(alliance => alliance.nations.map(e => e.toLowerCase())
.includes(nation.name.toLowerCase())).map(a => a.allianceName)
.filter(A => A.nations.map(e => e.toLowerCase()).includes(nation.name.toLowerCase()))
.map(a => a.allianceName)

const len = nationAlliances?.length
if (len > 0) nationEmbed.addFields(fn.embedField(
Expand Down
35 changes: 18 additions & 17 deletions aurora/slashcommands/town.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ import { Aurora, formatString, NotFoundError } from 'earthmc'

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

const invalidUsageEmbed = () => new EmbedBuilder()
.setColor(Colors.Red)
.setTitle("Invalid Arguments")
.setDescription(
"**Command Usage**:\n" +
"Get info on a single town - `/town <name>`\n" +
"Show a page-by-page display of all towns - `/town list`\n" +
"Shows a list "
)

export default {
name: "town",
description: "Displays info for a town.",
run: async (client: Client, interaction: ChatInputCommandInteraction) => {
if (!interaction.options.getSubcommand()) {
return await interaction.reply({embeds: [new EmbedBuilder()
.setColor(Colors.Red)
.setTitle("Command Usage")
.setDescription("`/town <name>`, `/town list` or `/town activity <name>`")
], ephemeral: true})
return await interaction.reply({ embeds: [invalidUsageEmbed()], ephemeral: true })
}

await interaction.deferReply()
Expand Down Expand Up @@ -232,8 +238,8 @@ export default {
))
}

const disc = townNation?.discord
const nationString = !disc ? `\`${town.nation}\`` : `[${townNation.name}](${disc})`
const nationWiki = town?.wikis.nation
const nationString = !nationWiki ? `\`${town.nation}\`` : `[${town.nation}](${nationWiki})`

townEmbed.addFields(
embedField("Nation", nationString, true),
Expand Down Expand Up @@ -278,8 +284,8 @@ export default {
"```" + town.residents.join(", ") + "```"
))
}
else townEmbed.addFields(embedField("Residents", townResidentsLength.toString()))
}
else townEmbed.addFields(embedField("Residents", `\`${townResidentsLength.toString()}\``))
}
else townEmbed.addFields(embedField("Residents", "There are no residents in this town?"))

const townCouncillorsLen = town.councillors.length
Expand Down Expand Up @@ -337,12 +343,7 @@ export default {
})
}

return await interaction.editReply({embeds: [new EmbedBuilder()
.setDescription("Invalid arguments! Usage: `/t townName` or `/t list`")
.setFooter(devsFooter(client))
.setTimestamp()
.setColor(Colors.Red)
]})
return await interaction.editReply({embeds: [invalidUsageEmbed()]})
}, data: new SlashCommandBuilder()
.setName("town")
.setDescription("Displays info for a town.")
Expand Down Expand Up @@ -395,9 +396,9 @@ function sendList(

const allData = townData.map((town, index) => `**${(index + 1)}**. ${town.name} (**${town.nation}**)\n` +
`Residents: \`${town.residentNames.length}\`\n` +
`Chunks: \`${town.area}\`\n`
`Chunks: \`${town.area}\``
//`${wealthStr(town.wealth)}`
).join('\n\n').match(/(?:^.*$\n\n?){1,16}/mg)
).join('\n\n').match(/(?:^.*$\n\n?){1,15}/mg)

new CustomEmbed(client, "Town Info | Town List")
.setType(EntityType.Town)
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"importHelpers": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"noImplicitAny": true,
//"noImplicitAny": true,
"outDir": "dist",
"types": ["node"],
"paths": {
Expand Down

0 comments on commit 3135a0a

Please sign in to comment.