62 lines
2.6 KiB
JavaScript
62 lines
2.6 KiB
JavaScript
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
|
|
|
module.exports = {
|
|
category: 'utility',
|
|
global: true,
|
|
data: new SlashCommandBuilder()
|
|
.setName('budget')
|
|
.setDescription('The thing')
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('set')
|
|
.setDescription('Set weekly budget')
|
|
.addIntegerOption(option =>
|
|
option.setName('amount')
|
|
.setRequired(true)
|
|
.setDescription('Amount as int'))
|
|
.addBooleanOption(option =>
|
|
option.setName('override')
|
|
.setRequired(false)
|
|
.setDescription('Override budget of current period'))
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('spendings')
|
|
.setDescription('View your grocery spendings for the current or previous week')
|
|
.addBooleanOption(option =>
|
|
option
|
|
.setName('lastweek')
|
|
.setDescription('Show spendings from the previous budget cycle instead of the current one')
|
|
.setRequired(false)
|
|
)
|
|
),
|
|
async execute(interaction) {
|
|
console.log('budget command entrypoint');
|
|
let db = await interaction.client.localDB;
|
|
let discordId = interaction.member.id;
|
|
console.log(db, discordId);
|
|
let allowed = ['372115788498468864', '222457277708369928'].includes(discordId);
|
|
console.log(allowed);
|
|
if (!allowed) {
|
|
console.log('budget command denied');
|
|
await interaction.reply('This command may only be invoked by Miffy!');
|
|
return;
|
|
}
|
|
console.log(`Switcching on sub ${interaction.options.getSubcommand()}`);
|
|
switch (interaction.options.getSubcommand()) {
|
|
case 'set':
|
|
console.log('budget command set');
|
|
let budget = interaction.options.get('amount').value
|
|
db.prepare(`INSERT OR REPLACE INTO bot_config (id, weekly_budget) VALUES (1, ?)`).run(budget);
|
|
await interaction.reply(`Budget set to ${budget}`);
|
|
break;
|
|
case 'spendings':
|
|
console.log('budget command show');
|
|
await interaction.reply('Not implemented');
|
|
break
|
|
default:
|
|
await interaction.reply(`Sub mismatch. Switching on ${interaction.options.getSubcommand()}`);
|
|
break;
|
|
}
|
|
},
|
|
}; |