This commit is contained in:
40
commands/contests/clear.ts
Normal file
40
commands/contests/clear.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user