34 lines
1.5 KiB
JavaScript
34 lines
1.5 KiB
JavaScript
const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
|
|
const api = require('../api');
|
|
|
|
module.exports = {
|
|
name: 'setup-live',
|
|
description: 'Admin: enable or disable Twitch live notifications for this server',
|
|
enabled: true,
|
|
builder: new SlashCommandBuilder()
|
|
.setName('setup-live')
|
|
.setDescription('Enable or disable Twitch live notifications for this server')
|
|
.addBooleanOption(opt => opt.setName('enabled').setDescription('Enable/disable notifications').setRequired(true)),
|
|
|
|
async execute(interaction) {
|
|
if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) {
|
|
await interaction.reply({ content: 'You must be a server administrator to configure live notifications.', flags: 64 });
|
|
return;
|
|
}
|
|
|
|
const enabled = interaction.options.getBoolean('enabled');
|
|
|
|
try {
|
|
const api = require('../api');
|
|
const existing = (await api.getServerSettings(interaction.guildId)) || {};
|
|
const currentLn = existing.liveNotifications || {};
|
|
existing.liveNotifications = { ...currentLn, enabled: !!enabled };
|
|
await api.upsertServerSettings(interaction.guildId, existing);
|
|
await interaction.reply({ content: `Live notifications ${enabled ? 'enabled' : 'disabled'} for this server.`, flags: 64 });
|
|
} catch (e) {
|
|
console.error('Error saving live notifications to backend:', e);
|
|
await interaction.reply({ content: 'Failed to update live notifications.', flags: 64 });
|
|
}
|
|
}
|
|
};
|