-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: slash command for certificate helper
- Loading branch information
1 parent
e8954a9
commit b90c52a
Showing
6 changed files
with
144 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll": true | ||
"source.fixAll": "explicit" | ||
}, | ||
"eslint.alwaysShowStatus": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Container for all FFXIV slash commands | ||
*/ | ||
|
||
/* | ||
* AetheBot - A Discord Chatbot | ||
* | ||
* Created by Tyrone Trevorrow on 04/01/24. | ||
* Copyright (c) 2024 Tyrone Trevorrow. All rights reserved. | ||
* | ||
* This source code is licensed under the permissive MIT license. | ||
*/ | ||
|
||
import * as Discord from "discord.js" | ||
import { DATA_CENTERS } from "../model/ffxiv-datacenters" | ||
import { stupidTitleCase } from "../util/string_stuff" | ||
import { GlobalFeature, SlashCommand } from "./feature" | ||
import { FFXIVCertificateFeature } from "./ffxiv_certificate_helper" | ||
|
||
export class FFXIVSlashCommandsFeature extends GlobalFeature { | ||
public static slashCommands?: SlashCommand[] | undefined = [ | ||
new Discord.SlashCommandBuilder() | ||
.setName("xiv") | ||
.setDescription("FFXIV-related subcommands") | ||
.addSubcommand(subcommand => | ||
subcommand.setName("certificates") | ||
.setDescription("Find the best market board items to trade for certificates (FFXIV)") | ||
.addStringOption(option => | ||
option.setName("datacentre") | ||
.setDescription("Data centre") | ||
.setRequired(true) | ||
.setChoices(...DATA_CENTERS.map(dc => ({ name: stupidTitleCase(dc), value: dc }))) | ||
), | ||
), | ||
] | ||
|
||
public async handleInteraction(interaction: Discord.Interaction<Discord.CacheType>): Promise<void> { | ||
if (interaction.isChatInputCommand() && interaction.options.getSubcommand() === "certificates") { | ||
const feature = this.bot.loadedFeatureForName<FFXIVCertificateFeature>("FFXIVCertificateFeature") | ||
if (!feature) { | ||
await interaction.reply({ | ||
content: "⚠️ FFXIVCertificates feature not loaded in this bot.", | ||
ephemeral: true, | ||
}) | ||
return | ||
} | ||
feature.handleInteraction(interaction) | ||
return | ||
} | ||
} | ||
|
||
public handleMessage(): boolean { | ||
// Doesn't handle any chat messages directly, only slash commands | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* FFXIV Data Centres | ||
*/ | ||
|
||
/* | ||
* AetheBot - A Discord Chatbot | ||
* | ||
* Created by Tyrone Trevorrow on 04/01/24. | ||
* Copyright (c) 2024 Tyrone Trevorrow. All rights reserved. | ||
* | ||
* This source code is licensed under the permissive MIT license. | ||
*/ | ||
|
||
export const DATA_CENTERS = [ | ||
"aether", | ||
"crystal", | ||
"dynamis", | ||
"primal", | ||
"chaos", | ||
"light", | ||
"elemental", | ||
"gaia", | ||
"mana", | ||
"meteor", | ||
"materia", | ||
] as const | ||
export type DataCenter = typeof DATA_CENTERS[number] | ||
|
||
export function isDataCenter(str: string): str is DataCenter { | ||
return (DATA_CENTERS as readonly string[]).includes(str) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Just some string stuff | ||
*/ | ||
|
||
/* | ||
* AetheBot - A Discord Chatbot | ||
* | ||
* Created by Tyrone Trevorrow on 04/01/24. | ||
* Copyright (c) 2024 Tyrone Trevorrow. All rights reserved. | ||
* | ||
* This source code is licensed under the permissive MIT license. | ||
*/ | ||
|
||
/** Extremely naïve title case: just upcases first char. No bounds checking. */ | ||
export function stupidTitleCase(str: string): string { | ||
return str[0].toUpperCase() + str.slice(1) | ||
} |