38 lines
1.2 KiB
TypeScript
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();
|