Update backend, DB, Commands, Live Reloading
This commit is contained in:
43
discord-bot/commands/add-kickuser.js
Normal file
43
discord-bot/commands/add-kickuser.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
module.exports = {
|
||||
name: 'add-kickuser',
|
||||
description: 'Admin: add a Kick username to watch for this server (DISABLED)',
|
||||
enabled: false,
|
||||
dev: true,
|
||||
builder: new SlashCommandBuilder()
|
||||
.setName('add-kickuser')
|
||||
.setDescription('Add a Kick username to watch for live notifications')
|
||||
.addStringOption(opt => opt.setName('username').setDescription('Kick username').setRequired(true)),
|
||||
async execute(interaction) {
|
||||
if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) {
|
||||
await interaction.reply({ content: 'You must be an administrator to use this command.', flags: 64 });
|
||||
return;
|
||||
}
|
||||
const username = interaction.options.getString('username').toLowerCase().trim();
|
||||
try {
|
||||
const backendBase = process.env.BACKEND_BASE || `http://${process.env.HOST || '127.0.0.1'}:${process.env.PORT || 3002}`;
|
||||
const resp = await fetch(`${backendBase}/api/servers/${interaction.guildId}/kick-users`, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username })
|
||||
});
|
||||
if (resp.ok) {
|
||||
await interaction.reply({ content: `Added ${username} to Kick watch list.`, flags: 64 });
|
||||
// Refresh cached settings from backend so watcher sees new user immediately
|
||||
try {
|
||||
const settingsResp = await fetch(`${backendBase}/api/servers/${interaction.guildId}/settings`);
|
||||
if (settingsResp.ok) {
|
||||
const json = await settingsResp.json();
|
||||
const bot = require('..');
|
||||
if (bot && bot.setGuildSettings) bot.setGuildSettings(interaction.guildId, json);
|
||||
}
|
||||
} catch (_) {}
|
||||
} else {
|
||||
await interaction.reply({ content: 'Failed to add user via backend.', flags: 64 });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error adding kick user:', e);
|
||||
await interaction.reply({ content: 'Internal error adding kick user.', flags: 64 });
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user