generated from nhcarrigan/template
Reviewed-on: https://codeberg.org/nhcarrigan/tingle-bot/pulls/1 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
37 lines
999 B
TypeScript
37 lines
999 B
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
import { commandList } from "../../commands/_commandList.js";
|
|
import type { WeatherCache } from "../../interfaces/weatherCache.js";
|
|
import type { Interaction } from "discord.js";
|
|
|
|
/**
|
|
* Handles the INTERACTION_CREATE event from Discord. Checks if the interaction is
|
|
* an application command, and if there is a matching command, and runs it.
|
|
* @param interaction - The interaction payload from Discord.
|
|
* @param cache - The cache of weather data.
|
|
*/
|
|
export const onInteraction = async(
|
|
interaction: Interaction,
|
|
cache: WeatherCache,
|
|
): Promise<void> => {
|
|
if (!interaction.isChatInputCommand()) {
|
|
return;
|
|
}
|
|
|
|
const target = commandList.find(
|
|
(command) => {
|
|
return command.data.name === interaction.commandName;
|
|
},
|
|
);
|
|
|
|
if (!target) {
|
|
await interaction.reply(`Command ${interaction.commandName} not found.`);
|
|
return;
|
|
}
|
|
|
|
await target.run(interaction, cache);
|
|
};
|