441 lines
17 KiB
JavaScript
441 lines
17 KiB
JavaScript
const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
|
|
|
|
class SlashCommands {
|
|
constructor(database) {
|
|
this.db = database;
|
|
this.commands = this.setupCommands();
|
|
}
|
|
|
|
setupCommands() {
|
|
return [
|
|
// Komenda informacyjna dla użytkowników
|
|
new SlashCommandBuilder()
|
|
.setName('skrzynka')
|
|
.setDescription('Informacje o bocie Skrzynka Impostora')
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('info')
|
|
.setDescription('Pokaż informacje o bocie')
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('help')
|
|
.setDescription('Pokaż dostępne komendy')
|
|
),
|
|
|
|
// Komendy administracyjne
|
|
new SlashCommandBuilder()
|
|
.setName('skrzynka-adm')
|
|
.setDescription('Komendy administracyjne dla bota Skrzynka Impostora')
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('set-welcome')
|
|
.setDescription('Ustaw kanał powitalny')
|
|
.addChannelOption(option =>
|
|
option
|
|
.setName('channel')
|
|
.setDescription('Kanał na którym będzie wyświetlana wiadomość powitalna')
|
|
.setRequired(true)
|
|
)
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('welcome')
|
|
.setDescription('Wyślij wiadomość powitalną')
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('welcome-update')
|
|
.setDescription('Zaktualizuj wiadomość powitalną z bazy danych')
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('status')
|
|
.setDescription('Pokaż status konfiguracji bota')
|
|
)
|
|
];
|
|
}
|
|
|
|
getCommandsData() {
|
|
return this.commands.map(command => command.toJSON());
|
|
}
|
|
|
|
async handleCommand(interaction) {
|
|
const { commandName, options } = interaction;
|
|
|
|
switch (commandName) {
|
|
case 'skrzynka':
|
|
await this.handleUserCommands(interaction, options);
|
|
break;
|
|
case 'skrzynka-adm':
|
|
await this.handleAdminCommands(interaction, options);
|
|
break;
|
|
default:
|
|
await interaction.reply({
|
|
content: '❌ Nieznana komenda.',
|
|
ephemeral: true
|
|
});
|
|
}
|
|
}
|
|
|
|
async handleUserCommands(interaction, options) {
|
|
const subcommand = options.getSubcommand();
|
|
|
|
switch (subcommand) {
|
|
case 'info':
|
|
await this.showBotInfo(interaction);
|
|
break;
|
|
case 'help':
|
|
await this.showHelp(interaction);
|
|
break;
|
|
}
|
|
}
|
|
|
|
async handleAdminCommands(interaction, options) {
|
|
const subcommand = options.getSubcommand();
|
|
|
|
// Sprawdź uprawnienia użytkownika
|
|
if (!interaction.member.permissions.has(PermissionFlagsBits.ManageChannels)) {
|
|
await interaction.reply({
|
|
content: '❌ Nie masz uprawnień do używania komend administracyjnych.',
|
|
ephemeral: true
|
|
});
|
|
return;
|
|
}
|
|
|
|
switch (subcommand) {
|
|
case 'set-welcome':
|
|
await this.setWelcomeChannel(interaction, options);
|
|
break;
|
|
case 'welcome':
|
|
await this.sendWelcomeMessage(interaction);
|
|
break;
|
|
case 'welcome-update':
|
|
await this.updateWelcomeMessage(interaction);
|
|
break;
|
|
case 'status':
|
|
await this.showStatus(interaction);
|
|
break;
|
|
}
|
|
}
|
|
|
|
async showBotInfo(interaction) {
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x00AE86)
|
|
.setTitle('🎭 Skrzynka Impostora Bot')
|
|
.setDescription('Bot do zarządzania wiadomościami powaitalnymi na serwerze Discord.')
|
|
.addFields(
|
|
{ name: '📝 Wersja', value: '1.0.0', inline: true },
|
|
{ name: '🔧 Panel Web', value: 'Dostępny dla administratorów', inline: true },
|
|
{ name: '⚡ Status', value: 'Online', inline: true },
|
|
{ name: '💻 Funkcje', value: '• Automatyczne wiadomości powitalne\n• Panel zarządzania web\n• Historia zmian\n• Konfiguracja kanałów', inline: false }
|
|
)
|
|
.setThumbnail(interaction.client.user.displayAvatarURL())
|
|
.setFooter({
|
|
text: 'Skrzynka Impostora Bot',
|
|
iconURL: interaction.client.user.displayAvatarURL()
|
|
})
|
|
.setTimestamp();
|
|
|
|
await interaction.reply({ embeds: [embed] });
|
|
}
|
|
|
|
async showHelp(interaction) {
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x0099FF)
|
|
.setTitle('📚 Pomoc - Dostępne komendy')
|
|
.addFields(
|
|
{
|
|
name: '👥 Komendy użytkownika',
|
|
value: '`/skrzynka info` - Informacje o bocie\n`/skrzynka help` - Ta pomoc',
|
|
inline: false
|
|
},
|
|
{
|
|
name: '🛠️ Komendy administracyjne',
|
|
value: '`/skrzynka-adm set-welcome` - Ustaw kanał powitalny\n`/skrzynka-adm welcome` - Wyślij wiadomość powitalną\n`/skrzynka-adm welcome-update` - Zaktualizuj wiadomość\n`/skrzynka-adm status` - Status konfiguracji',
|
|
inline: false
|
|
},
|
|
{
|
|
name: '🌐 Panel Web',
|
|
value: 'Zarządzanie treścią wiadomości dostępne przez panel web.',
|
|
inline: false
|
|
}
|
|
)
|
|
.setFooter({
|
|
text: 'Potrzebujesz pomocy? Skontaktuj się z administratorem serwera.',
|
|
iconURL: interaction.client.user.displayAvatarURL()
|
|
})
|
|
.setTimestamp();
|
|
|
|
await interaction.reply({ embeds: [embed], ephemeral: true });
|
|
}
|
|
|
|
async setWelcomeChannel(interaction, options) {
|
|
const channel = options.getChannel('channel');
|
|
const guildId = interaction.guild.id;
|
|
const guildName = interaction.guild.name;
|
|
|
|
try {
|
|
// Sprawdź czy bot ma uprawnienia do pisania na kanale
|
|
if (!channel.permissionsFor(interaction.client.user).has(PermissionFlagsBits.SendMessages)) {
|
|
await interaction.reply({
|
|
content: '❌ Bot nie ma uprawnień do pisania na wybranym kanale.',
|
|
ephemeral: true
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Dodaj/zaktualizuj serwer w bazie
|
|
await this.db.addGuild(guildId, guildName);
|
|
|
|
// Ustaw kanał powitalny
|
|
await this.db.setWelcomeChannel(guildId, channel.id, channel.name);
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x00FF00)
|
|
.setTitle('✅ Kanał powitalny ustawiony')
|
|
.setDescription(`Kanał ${channel} został ustawiony jako kanał powitalny.`)
|
|
.addFields(
|
|
{ name: 'Kanał', value: `${channel.name} (${channel.id})`, inline: false },
|
|
{ name: 'Następne kroki', value: 'Skonfiguruj treść wiadomości przez panel web lub użyj `/skrzynka-adm welcome` aby wysłać domyślną wiadomość.', inline: false }
|
|
)
|
|
.setTimestamp();
|
|
|
|
await interaction.reply({ embeds: [embed] });
|
|
|
|
} catch (error) {
|
|
console.error('Błąd podczas ustawiania kanału powitalnego:', error);
|
|
await interaction.reply({
|
|
content: '❌ Wystąpił błąd podczas ustawiania kanału powitalnego.',
|
|
ephemeral: true
|
|
});
|
|
}
|
|
}
|
|
|
|
async sendWelcomeMessage(interaction) {
|
|
const guildId = interaction.guild.id;
|
|
|
|
try {
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
// Pobierz konfigurację kanału
|
|
const welcomeChannelConfig = await this.db.getWelcomeChannel(guildId);
|
|
if (!welcomeChannelConfig) {
|
|
await interaction.editReply({
|
|
content: '❌ Kanał powitalny nie został skonfigurowany. Użyj `/skrzynka-adm set-welcome` aby go ustawić.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Pobierz kanał
|
|
const channel = interaction.guild.channels.cache.get(welcomeChannelConfig.channel_id);
|
|
if (!channel) {
|
|
await interaction.editReply({
|
|
content: '❌ Skonfigurowany kanał powitalny nie istnieje lub bot nie ma do niego dostępu.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Pobierz wiadomość z bazy lub użyj domyślnej
|
|
let welcomeMessage = await this.db.getWelcomeMessage(guildId);
|
|
let messageContent, embedData;
|
|
|
|
if (welcomeMessage) {
|
|
messageContent = welcomeMessage.content;
|
|
embedData = welcomeMessage.embed_data;
|
|
} else {
|
|
messageContent = this.getDefaultWelcomeMessage(interaction.guild);
|
|
embedData = null;
|
|
}
|
|
|
|
// Wyślij wiadomość
|
|
const messageOptions = { content: messageContent };
|
|
if (embedData) {
|
|
messageOptions.embeds = [new EmbedBuilder(embedData)];
|
|
}
|
|
|
|
const sentMessage = await channel.send(messageOptions);
|
|
|
|
// Zapisz lub zaktualizuj wiadomość w bazie
|
|
if (welcomeMessage) {
|
|
await this.db.updateWelcomeMessage(guildId, messageContent, embedData, sentMessage.id);
|
|
} else {
|
|
await this.db.saveWelcomeMessage(guildId, messageContent, embedData, sentMessage.id);
|
|
}
|
|
|
|
const successEmbed = new EmbedBuilder()
|
|
.setColor(0x00FF00)
|
|
.setTitle('✅ Wiadomość powitalna wysłana')
|
|
.setDescription(`Wiadomość została wysłana na kanał ${channel}.`)
|
|
.addFields(
|
|
{ name: 'Kanał', value: `${channel.name}`, inline: true },
|
|
{ name: 'ID wiadomości', value: `${sentMessage.id}`, inline: true }
|
|
)
|
|
.setTimestamp();
|
|
|
|
await interaction.editReply({ embeds: [successEmbed] });
|
|
|
|
} catch (error) {
|
|
console.error('Błąd podczas wysyłania wiadomości powitalnej:', error);
|
|
await interaction.editReply({
|
|
content: '❌ Wystąpił błąd podczas wysyłania wiadomości powitalnej.'
|
|
});
|
|
}
|
|
}
|
|
|
|
async updateWelcomeMessage(interaction) {
|
|
const guildId = interaction.guild.id;
|
|
|
|
try {
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
// Pobierz konfigurację i wiadomość
|
|
const welcomeChannelConfig = await this.db.getWelcomeChannel(guildId);
|
|
const welcomeMessage = await this.db.getWelcomeMessage(guildId);
|
|
|
|
if (!welcomeChannelConfig || !welcomeMessage) {
|
|
await interaction.editReply({
|
|
content: '❌ Kanał powitalny lub wiadomość nie zostały skonfigurowane.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
const channel = interaction.guild.channels.cache.get(welcomeChannelConfig.channel_id);
|
|
if (!channel) {
|
|
await interaction.editReply({
|
|
content: '❌ Skonfigurowany kanał powitalny nie istnieje.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Znajdź i zaktualizuj wiadomość
|
|
if (welcomeMessage.message_id) {
|
|
try {
|
|
const message = await channel.messages.fetch(welcomeMessage.message_id);
|
|
|
|
const messageOptions = { content: welcomeMessage.content };
|
|
if (welcomeMessage.embed_data) {
|
|
messageOptions.embeds = [new EmbedBuilder(welcomeMessage.embed_data)];
|
|
}
|
|
|
|
await message.edit(messageOptions);
|
|
|
|
const successEmbed = new EmbedBuilder()
|
|
.setColor(0x00FF00)
|
|
.setTitle('✅ Wiadomość zaktualizowana')
|
|
.setDescription(`Wiadomość powitalna została zaktualizowana na kanale ${channel}.`)
|
|
.setTimestamp();
|
|
|
|
await interaction.editReply({ embeds: [successEmbed] });
|
|
|
|
} catch (fetchError) {
|
|
// Jeśli nie można znaleźć wiadomości, wyślij nową
|
|
await this.sendWelcomeMessage(interaction);
|
|
}
|
|
} else {
|
|
// Jeśli nie ma ID wiadomości, wyślij nową
|
|
await this.sendWelcomeMessage(interaction);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Błąd podczas aktualizacji wiadomości powitalnej:', error);
|
|
await interaction.editReply({
|
|
content: '❌ Wystąpił błąd podczas aktualizacji wiadomości powitalnej.'
|
|
});
|
|
}
|
|
}
|
|
|
|
async showStatus(interaction) {
|
|
const guildId = interaction.guild.id;
|
|
|
|
try {
|
|
const welcomeChannelConfig = await this.db.getWelcomeChannel(guildId);
|
|
const welcomeMessage = await this.db.getWelcomeMessage(guildId);
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x0099FF)
|
|
.setTitle('📊 Status konfiguracji bota')
|
|
.setDescription(`Status dla serwera: **${interaction.guild.name}**`);
|
|
|
|
if (welcomeChannelConfig) {
|
|
const channel = interaction.guild.channels.cache.get(welcomeChannelConfig.channel_id);
|
|
embed.addFields({
|
|
name: '📍 Kanał powitalny',
|
|
value: channel ? `${channel.name} (${channel.id})` : `❌ Kanał niedostępny (${welcomeChannelConfig.channel_id})`,
|
|
inline: false
|
|
});
|
|
} else {
|
|
embed.addFields({
|
|
name: '📍 Kanał powitalny',
|
|
value: '❌ Nie skonfigurowany',
|
|
inline: false
|
|
});
|
|
}
|
|
|
|
if (welcomeMessage) {
|
|
embed.addFields(
|
|
{
|
|
name: '💬 Wiadomość powitalna',
|
|
value: '✅ Skonfigurowana w bazie danych',
|
|
inline: true
|
|
},
|
|
{
|
|
name: '🆔 ID wiadomości',
|
|
value: welcomeMessage.message_id || 'Brak',
|
|
inline: true
|
|
},
|
|
{
|
|
name: '📅 Ostatnia aktualizacja',
|
|
value: new Date(welcomeMessage.updated_at).toLocaleString('pl-PL'),
|
|
inline: true
|
|
}
|
|
);
|
|
} else {
|
|
embed.addFields({
|
|
name: '💬 Wiadomość powitalna',
|
|
value: '❌ Nie skonfigurowana (będzie użyta domyślna)',
|
|
inline: false
|
|
});
|
|
}
|
|
|
|
embed.setFooter({
|
|
text: 'Użyj panelu web aby zarządzać treścią wiadomości',
|
|
iconURL: interaction.client.user.displayAvatarURL()
|
|
})
|
|
.setTimestamp();
|
|
|
|
await interaction.reply({ embeds: [embed], ephemeral: true });
|
|
|
|
} catch (error) {
|
|
console.error('Błąd podczas pobierania statusu:', error);
|
|
await interaction.reply({
|
|
content: '❌ Wystąpił błąd podczas pobierania statusu.',
|
|
ephemeral: true
|
|
});
|
|
}
|
|
}
|
|
|
|
getDefaultWelcomeMessage(guild) {
|
|
return `# 🎭 Witamy na serwerze ${guild.name}!
|
|
|
|
Miło Cię tutaj widzieć! 👋
|
|
|
|
## 📋 Najważniejsze informacje:
|
|
• Przeczytaj regulamin serwera
|
|
• Przedstaw się w odpowiednim kanale
|
|
• Baw się dobrze i szanuj innych członków
|
|
|
|
## 🎮 Funkcje serwera:
|
|
• Kanały tematyczne
|
|
• System ról
|
|
• Eventy i konkursy
|
|
|
|
---
|
|
*Ta wiadomość została wygenerowana przez Skrzynka Impostora Bot*
|
|
*Administratorzy mogą edytować treść przez panel web*`;
|
|
}
|
|
}
|
|
|
|
module.exports = { SlashCommands };
|