import { CommandInteraction, CommandInteractionOptionResolver, TextChannel, SlashCommandBuilder, SlashCommandStringOption, PermissionFlagsBits, } from 'discord.js'; import {Command} from '../../classes/command'; import {logger} from '../../logger' import {getContest, updateProblem} from '../../functions/database'; function isTextChannel(data: unknown): data is TextChannel{ return (data as TextChannel).name !== undefined; } type CIOR = CommandInteractionOptionResolver; class Wa extends Command{ get name(){return "wa";} get description(){return "Add timestamp when you get wa";} async execute(interaction: CommandInteraction): Promise{ if(!isTextChannel(interaction.channel)){ await interaction.reply({ content: `Channel name doesn't exist!` }); logger.error(`Channel name doesn't exist`); return; } try{ // parse const user = interaction.user; let problemId = (interaction.options as CIOR).getString('problem'); const contestName = interaction.channel.name; const channelId = interaction.channel.id; const contest = await getContest(channelId); const time = new Date(); if(problemId === null){ logger.error('option error'); return; } problemId = problemId.toUpperCase(); if(contest === null){ await interaction.reply({ content: `The contest in this channel didn't start!` }); logger.error(`Contest ${contestName} didn't start`); return; } // update await updateProblem(user, problemId, channelId, 'wa', time.valueOf()); await interaction.reply({ content: `Problem ${problemId} has wa-ed.` }); logger.log(`Problem ${problemId} has wa-ed.`); }catch(error: unknown){ logger.error(`Error occur while wa-ing problem`); return; } } override build(): SlashCommandBuilder | Omit{ return new SlashCommandBuilder() .setName(this.name) .setDescription(this.description) .addStringOption((option: SlashCommandStringOption) => option .setName('problem') .setDescription('The id of the problem.') .setMinLength(1).setMaxLength(1) .setRequired(true)) .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages); } }; export const command = new Wa();