Files
zkldi_Tachi/bot/src/interactionHandlers/handleIsSelectMenu.ts
T
zkldi fec9fe0ea8 refactor!: Tear out most bot functionality
These commands never get used and are generally ugly.

I'm trying to decrease the maintenance of this project, and this is
an unecessary expense imo.
2022-11-10 02:00:10 +00:00

55 lines
1.8 KiB
TypeScript

import { LoggerLayers } from "../data/data";
import { GetUserInfo } from "../utils/apiRequests";
import { CreateChartScoresEmbed } from "../utils/embeds";
import { CreateLayeredLogger } from "../utils/logger";
import type { DiscordUserMapDocument } from "../database/documents";
import type { SelectMenuInteraction } from "discord.js";
import type { Game, Playtype } from "tachi-common";
const logger = CreateLayeredLogger(LoggerLayers.slashCommands);
/**
* Handles incoming command requests by resolving the interaction to the command
* it refers to, and calling it.
*
* @param interaction - The interaction the user made. This contains things like what
* command they called and with what arguments.
* @param requestingUser - The user who interacted with this command.
*/
export async function handleIsSelectMenu(
interaction: SelectMenuInteraction,
requestingUser: DiscordUserMapDocument
) {
try {
if (interaction.user.id !== requestingUser.discordID) {
await interaction.reply({
ephemeral: true,
content: "You can't interact with other peoples select boxes, get your own!",
});
}
if (interaction.customId.startsWith("chart!")) {
// horrendous hackery, but we only have 100 chars to store selector metadata.
const [, game, playtype, userID] = /!(.*):(.*):(.*)$/u.exec(
interaction.customId
) as unknown as [string, Game, Playtype, string];
const userDoc = await GetUserInfo(userID);
const embed = await CreateChartScoresEmbed(
userDoc,
game,
playtype,
interaction.values[0]!,
null
);
await interaction.update({ embeds: [embed] });
} else {
logger.warn(`Unknown selector triggered: ${interaction.customId}.`);
}
} catch (e) {
logger.error("Failed to handle isSelectMenu interaction", { error: e });
}
}