Skip to content

Commit e808ce3

Browse files
committed
Add Enemy command
1 parent f78d909 commit e808ce3

File tree

6 files changed

+2785
-19
lines changed

6 files changed

+2785
-19
lines changed

src/commands/misc/enemy.ts

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { AutocompleteInteraction, CommandInteraction, Message, MessageEmbed } from "discord.js"
2+
import config from "../../data/config.json"
3+
import client from "../../main"
4+
import Command from "../../utils/Command"
5+
import { CommandSource, Enemy, SendMessage } from "../../utils/Types"
6+
import { Bookmarkable, Colors, createTable, findFuzzyBestCandidates, PAD_END, PAD_START, paginator, sendMessage, simplePaginator } from "../../utils/Utils"
7+
8+
export default class EnemyCommand extends Command {
9+
constructor(name: string) {
10+
super({
11+
name,
12+
category: "Misc",
13+
usage: "enemy [name]",
14+
help: `Displays enemy information. If no name is provided, a list of all enemies will be displayed.
15+
16+
Note: this command supports fuzzy search.`,
17+
aliases: ["en", "enemies"],
18+
options: [{
19+
name: "name",
20+
description: "Enemy name",
21+
type: "STRING",
22+
autocomplete: true,
23+
required: false
24+
}]
25+
})
26+
}
27+
28+
async autocomplete(source: AutocompleteInteraction): Promise<void> {
29+
const targetNames = Object.keys(client.data.enemies)
30+
const search = source.options.getFocused().toString()
31+
32+
if (search == "") {
33+
return await source.respond([
34+
{ name: "List all enemies", value: "" },
35+
...targetNames.filter((_, i) => i < 19).map(value => {
36+
return { name: value, value }
37+
})
38+
])
39+
}
40+
41+
await source.respond(findFuzzyBestCandidates(targetNames, search, 20).map(value => {
42+
return { name: value, value }
43+
}))
44+
}
45+
46+
async runInteraction(source: CommandInteraction): Promise<SendMessage | undefined> {
47+
return this.run(source, (source.options.getString("name") ?? "").split(/ +/g))
48+
49+
}
50+
async runMessage(source: Message, args: string[]): Promise<SendMessage | undefined> {
51+
return this.run(source, args)
52+
}
53+
54+
async run(source: CommandSource, args: string[]): Promise<SendMessage | undefined> {
55+
const { data } = client
56+
57+
const name = args.join(" ")
58+
if (name.length == 0) {
59+
const pages = this.getEnemiesPages()
60+
if (pages.length == 0) return sendMessage(source, "No enemy data loaded")
61+
62+
await simplePaginator(source, (relativePage, currentPage, maxPages) => this.getEnemiesPage(pages, relativePage, currentPage, maxPages), pages.length)
63+
return undefined
64+
}
65+
66+
const enemy = data.getEnemyByName(name)
67+
if (enemy == undefined)
68+
return sendMessage(source, "Unable to find enemy")
69+
70+
const pages: Bookmarkable[] = [{
71+
bookmarkEmoji: "📝",
72+
bookmarkName: "General",
73+
maxPages: 1,
74+
pages: (rp, cp, mp) => this.getMainEnemyPage(enemy, rp, cp, mp)
75+
}]
76+
if (enemy.desc)
77+
pages.push({
78+
bookmarkEmoji: "-",
79+
bookmarkName: "Lore",
80+
maxPages: 1,
81+
pages: (rp, cp, mp) => this.getLoreEnemyPage(enemy, rp, cp, mp),
82+
invisible: true
83+
})
84+
85+
await paginator(source, pages)
86+
return undefined
87+
}
88+
89+
90+
getEnemiesPages(): string[] {
91+
const { data } = client
92+
const enemies = Object.entries(data.enemies)
93+
.map(([name, info]) => `${data.emoji(name, true)}${info.placeholder ? " [Not yet available]" : ""}`)
94+
95+
const pages: string[] = []
96+
let paging = "", c = 0
97+
for (const enemy of enemies) {
98+
if (paging.length + enemy.length > 1800 || ++c > 15) {
99+
pages.push(paging.trim())
100+
paging = enemy
101+
c = 1
102+
} else
103+
paging += "\n" + enemy
104+
}
105+
if (paging.trim().length > 0) pages.push(paging)
106+
return pages
107+
}
108+
109+
getEnemiesPage(pages: string[], relativePage: number, currentPage: number, maxPages: number): MessageEmbed | undefined {
110+
if (relativePage >= pages.length)
111+
return undefined
112+
113+
const embed = new MessageEmbed()
114+
.setTitle("Enemies")
115+
.setDescription(pages[relativePage])
116+
.setFooter(`Page ${currentPage} / ${maxPages} - See '${config.prefix}help enemy' for more info about what you can do`)
117+
.setColor(Colors.GREEN)
118+
119+
return embed
120+
}
121+
122+
getMainEnemyPage(enemy: Enemy, relativePage: number, currentPage: number, maxPages: number): MessageEmbed | undefined {
123+
const embed = new MessageEmbed()
124+
.setTitle(`${enemy.name}: Basic info`)
125+
.setColor(Colors.AQUA)
126+
.setFooter(`Page ${currentPage} / ${maxPages}`)
127+
.setDescription(`**Type**: ${enemy.type ?? "Unknown"}${enemy.kind ? ` (${enemy.kind})` : ""}${enemy.notes ? `\n\n${enemy.notes}` : ""}`)
128+
129+
if (enemy.icon)
130+
embed.setThumbnail(enemy.icon)
131+
132+
if (enemy.resistance)
133+
embed.addField("Resistances", `\`\`\`\n${createTable(["Pyro", "Elec", "Cryo", "Hydro", "Anemo", "Geo", "Phys", "Notes"], enemy.resistance, [PAD_START, PAD_START, PAD_START, PAD_START, PAD_START, PAD_START, PAD_START, PAD_END])}\n\`\`\``)
134+
135+
return embed
136+
}
137+
138+
getLoreEnemyPage(enemy: Enemy, relativePage: number, currentPage: number, maxPages: number): MessageEmbed | undefined {
139+
const embed = new MessageEmbed()
140+
.setColor(Colors.AQUA)
141+
.setFooter(`Page ${currentPage} / ${maxPages}`)
142+
.setTitle(`${enemy.name}: Description`)
143+
.setDescription(enemy.desc ?? "Unavailable")
144+
145+
if (enemy.icon) embed.setThumbnail(enemy.icon)
146+
147+
return embed
148+
}
149+
}

src/commands/weapons/weapon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Note: this command supports fuzzy search.`,
105105
const name = args.join(" ")
106106
if (name.length == 0) {
107107
const pages = this.getWeaponsPages(weaponFilter, starFilter)
108-
if (pages.length == 0) return sendMessage(source, "No character data loaded")
108+
if (pages.length == 0) return sendMessage(source, "No weapon data loaded")
109109

110110
await simplePaginator(source, (relativePage, currentPage, maxPages) => this.getWeaponsPage(pages, relativePage, currentPage, maxPages), pages.length)
111111
return undefined

src/data/emojis.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,24 @@
254254
"Geo Specter": "<:Geo_Specter:927630031184871454>",
255255

256256
"Hilichurl": "<:Hilichurl:927630039258918972>",
257-
"Hilichurl Fighter": "<:Hilichurl_Fighter:927630039510548571>",
258-
"Hilichurl Berserker": "<:Hilichurl_Berserker:927630039460237322>",
259-
"Wooden Shield Hilichurl Guard": "<:Wooden_Shield_Hilichurl_Guard:927630533813493851>",
260-
"Ice Shield Hilichurl Guard": "<:Ice_Shield_Hilichurl_Guard:927630040504610897>",
261-
"Rock Shield Hilichurl Guard": "<:Rock_Shield_Hilichurl_Guard:927630040835948595>",
262-
"Hilichurl Shooter": "<:Hilichurl_Shooter:927630040202625084>",
263-
"Pyro Hilichurl Shooter": "<:Pyro_Hilichurl_Shooter:927630041691594813>",
264-
"Electro Hilichurl Shooter": "<:Electro_Hilichurl_Shooter:927627061659586580>",
265-
"Cryo Hilichurl Shooter": "<:Cryo_Hilichurl_Shooter:927627061122727996>",
266-
"Hilichurl Grenadier": "<:Hilichurl_Grenadier:927630040928256071>",
267-
"Electro Hilichurl Grenadier": "<:Electro_Hilichurl_Grenadier:927627061374378064>",
268-
"Cryo Hilichurl Grenadier": "<:Cryo_Hilichurl_Grenadier:927627061189836820>",
257+
"Hilichurl Fighter": "<:Hilichurl:927630039258918972>",
258+
"Hilichurl Berserker": "<:Pyro_Hilichurl:927630041691594813>",
259+
"Wooden Shield Hilichurl Guard": "<:Hilichurl:927630039258918972>",
260+
"Ice Shield Hilichurl Guard": "<:Hilichurl:927630039258918972>",
261+
"Rock Shield Hilichurl Guard": "<:Hilichurl:927630039258918972>",
262+
"Hilichurl Shooter": "<:Hilichurl:927630039258918972>",
263+
"Pyro Hilichurl Shooter": "<:Pyro_Hilichurl:927630041691594813>",
264+
"Electro Hilichurl Shooter": "<:Electro_Hilichurl:927627061659586580>",
265+
"Cryo Hilichurl Shooter": "<:Cryo_Hilichurl:927627061189836820>",
266+
"Hilichurl Grenadier": "<:Pyro_Hilichurl:927630041691594813>",
267+
"Electro Hilichurl Grenadier": "<:Electro_Hilichurl:927627061659586580>",
268+
"Cryo Hilichurl Grenadier": "<:Cryo_Hilichurl:927627061189836820>",
269269
"Unusual Hilichurl": "<:Unusual_Hilichurl:927630534262267955>",
270-
"Wooden Shieldwall Mitachurl": "<:Wooden_Shieldwall_Mitachurl:927630533792526407>",
271-
"Rock Shieldwall Mitachurl": "<:Rock_Shieldwall_Mitachurl:927630041947455578>",
272-
"Ice Shieldwall Mitachurl": "<:Ice_Shieldwall_Mitachurl:927630041326702662>",
273-
"Blazing Axe Mitachurl": "<:Blazing_Axe_Mitachurl:927627060212555837>",
274-
"Crackling Axe Mitachurl": "<:Crackling_Axe_Mitachurl:927627057654034555>",
270+
"Wooden Shieldwall Mitachurl": "<:Mitachurl:927627060212555837>",
271+
"Rock Shieldwall Mitachurl": "<:Mitachurl:927627060212555837>",
272+
"Ice Shieldwall Mitachurl": "<:Mitachurl:927627060212555837>",
273+
"Blazing Axe Mitachurl": "<:Mitachurl:927627060212555837>",
274+
"Crackling Axe Mitachurl": "<:Mitachurl:927627060212555837>",
275275
"Thunderhelm Lawachurl": "<:Thunderhelm_Lawachurl:927630534451028058>",
276276
"Frostarm Lawachurl": "<:Frostarm_Lawachurl:927627061965778984>",
277277
"Stonehide Lawachurl": "<:Stonehide_Lawachurl:927630534480396318>",
@@ -361,6 +361,7 @@
361361
"Maguu Kenki: Lone Gale": "<:Maguu_Kenki_Galloping_Frost:927641062170833030>",
362362
"Maguu Kenki: Galloping Frost": "<:Maguu_Kenki_Lone_Gale:927641062518968330>",
363363
"Maguu Kenki: Mask of Terror": "<:Maguu_Kenki_Mask_of_Terror:927641062602846208>",
364+
"The Rock": "<:The_Rock:927680089955663882>",
364365

365366
"Mora": "<:Mora:827985024745603111>",
366367

0 commit comments

Comments
 (0)