jillo-bot/src/commands/createcounter.ts

68 lines
2.0 KiB
TypeScript

import { Interaction, SlashCommandBuilder } from 'discord.js';
import { Counter, db } from '../lib/db';
import { updateCounter } from '../lib/counter';
module.exports = {
data: new SlashCommandBuilder()
.setName('createcounter')
.setDescription('[ADMIN] Create a counter in this channel')
.addStringOption(option =>
option
.setName('key')
.setDescription('The codename. Best to leave descriptive for later')
.setRequired(true)
)
.addStringOption(option =>
option
.setName('name')
.setDescription('The name, anything goes')
.setRequired(true)
)
.addStringOption(option =>
option
.setName('emoji')
.setDescription('An emoji or symbol or something to represent the counter')
.setMaxLength(10)
.setRequired(true)
)
.addNumberOption(option =>
option
.setName('value')
.setDescription('Initial value to start with')
)
.setDefaultMemberPermissions('0')
.setDMPermission(false),
execute: async (interaction: Interaction) => {
if (!interaction.isChatInputCommand()) return;
await interaction.deferReply({ephemeral: true});
const key = interaction.options.getString('key')!;
const name = interaction.options.getString('name')!;
const emoji = interaction.options.getString('emoji')!;
const value = interaction.options.getNumber('value') || 0;
const channel = interaction.channelId;
const guild = interaction.guildId!;
await db<Counter>('counters')
.insert({
'key': key,
'name': name,
'emoji': emoji,
'value': value,
'channel': channel,
'guild': guild
});
const counter = await db<Counter>('counters')
.where('key', key)
.first();
await updateCounter(interaction.client, counter!, value);
await interaction.followUp({
content: `<#${interaction.channelId}> has been **enriched** with your new counter. Congratulations!`
});
}
};