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

38 lines
1.2 KiB
TypeScript

import {CommandInteraction, TextChannel} from 'discord.js';
import {Command} from '../../classes/command';
import {logger} from '../../logger'
import {createContest} from '../../functions/database';
function isTextChannel(data: unknown): data is TextChannel{
return (data as TextChannel).name !== undefined;
}
class Virtual extends Command{
get name(){return "virtual";}
get description(){return "Start a virtual 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;
}
try{
const contestName = interaction.channel.name;
const channelId = interaction.channel.id;
const startTime = new Date();
await createContest(channelId, startTime.valueOf());
await interaction.reply({
content: `Contest archive ${contestName} created on ${startTime.toString()}.`
});
logger.log(`Contest archive ${contestName} created.`);
}catch(error: unknown){
logger.error(`Error occur while initializing contest`);
return;
}
}
};
export const command = new Virtual();