Files
konchin 2d7361e937
Some checks failed
release-tag / release-image (push) Failing after 1m14s
initial commit
2024-10-11 19:49:58 +08:00

41 lines
1.2 KiB
TypeScript

import {
CommandInteraction,
TextChannel,
} from 'discord.js';
import {Command} from '../../classes/command';
import {logger} from '../../logger'
import {getContest, clearContest} from '../../functions/database';
function isTextChannel(data: unknown): data is TextChannel{
return (data as TextChannel).name !== undefined;
}
class Clear extends Command{
get name(){return "clear";}
get description(){return "clear contest.";}
async execute(interaction: CommandInteraction): Promise<void>{
if(!isTextChannel(interaction.channel)){
await interaction.reply({
content: `Channel name doesn't exist!`
});
logger.error(`Channel name doesn't exist`);
return;
}
const contestName = interaction.channel.name;
const channelId = interaction.channel.id;
const contest = await getContest(contestName);
if(contest === null){
await interaction.reply({
content: `The contest in this channel didn't start!`
});
logger.error(`Contest ${contestName} didn't start`);
return;
}
await clearContest(channelId);
await interaction.reply({content: `Clear ${contestName} complete.`});
logger.log(`Command: clear ${contestName}/${channelId}`);
}
};
export const command = new Clear();