diff --git a/commands/mod/settings/help.js b/commands/mod/settings/help.js new file mode 100644 index 0000000..b6ad1aa --- /dev/null +++ b/commands/mod/settings/help.js @@ -0,0 +1,33 @@ +import { SlashCommandSubcommandBuilder } from 'discord.js'; +import { errorEmbed, successEmbed } from '../../../utils/embeds.js'; +import ServerSettings from '../../../models/ServerSettings.js'; + +export default { + ...new SlashCommandSubcommandBuilder() + .setName('help_category') + .setDescription('Pozwala na ustawienie kategorii pomocy') + .addChannelOption(string => + string.setName('category') + .setDescription('Wybierz kategorię pomocy') + .addChannelTypes(4) + .setRequired(true), + ) + .toJSON(), + async execute(interaction) { + const category = interaction.options.getChannel('help_category'); + + let serverSettings = await ServerSettings.findOne({ server_id: interaction.guild?.id }); + + if (!serverSettings) { + serverSettings = new ServerSettings({ server_id: interaction.guild?.id, help_category: category.id }); + } else { + serverSettings.help_category = category.id; + } + + await serverSettings.save((e) => { + if (!e) return interaction.reply({ embeds: [successEmbed('Pomyślnie zmodyfikowano kategorię z kanałami pomocy.')] }).catch(console.error); + return interaction.reply({ embeds: [errorEmbed('Wystąpił nieznany błąd podczas modyfikacji kategorii z kanałami pomocy')] }).catch(console.error); + }); + + }, +}; diff --git a/commands/standard/redirecthelp.js b/commands/standard/redirecthelp.js new file mode 100644 index 0000000..83cda9b --- /dev/null +++ b/commands/standard/redirecthelp.js @@ -0,0 +1,97 @@ +import { + ActionRowBuilder, + ContextMenuCommandBuilder, + StringSelectMenuBuilder, +} from 'discord.js'; +import { ChannelType } from 'discord-api-types/v9'; +import ServerSettings from '../../models/ServerSettings.js'; + +export default { + ...new ContextMenuCommandBuilder() + .setName('Utwórz wątek na kanałach pomocy') + .setType(3) + .setDMPermission(false) + .toJSON(), + async execute(interaction) { + const message = interaction.options?.get('message')?.message; + + if (interaction.channel.isThread()) { + return interaction.reply({ + content: 'Ta komenda może być użyta tylko na kanale', + ephemeral: true, + }); + } + + if (message.author.id === interaction.user.id) { + return interaction.reply({ + content: 'Nie możesz utworzyć prywatnego wątku dla siebie', + ephemeral: true, + }); + } + + if (message.author.bot) { + return interaction.reply({ + content: 'Nie możesz utworzyć prywatnego wątku dla bota', + ephemeral: true, + }); + } + + const settings = await ServerSettings.find({ server_id: interaction.guild.id }).exec(); + + const supportChannels = interaction.guild.channels.cache.get(settings.help_category).parent.children.filter(channel => channel.type === ChannelType.GuildForum); + + if (!supportChannels.size) { + return interaction.reply({ + content: 'Nie znaleziono kanałów pomocy', + ephemeral: true, + }); + } + + const channelActionRow = new ActionRowBuilder() + .addComponents( + new StringSelectMenuBuilder() + .setCustomId('channel') + .setPlaceholder('Wybierz kanał') + .addOptions( + supportChannels.map(channel => ({ + label: channel.name, + value: channel.id, + })), + ), + ); + + const reply = await interaction.reply({ + content: 'Wybierz kanał na który chcesz przekierować osobę', + components: [channelActionRow], + ephemeral: true, + }); + + const collector = reply.createMessageComponentCollector({ time: 60000 }); + + collector.on('collect', async (int) => { + const channel = int.guild.channels.cache.get(int.values[0]); + + const thread = await channel.threads.create({ + name: `${message.author.username}`, + autoArchiveDuration: channel.defaultAutoArchiveDuration, + reason: `${interaction.user.username} przekierował ${message.author.username} na kanał ${channel.name}`, + }); + + await thread.members.add(message.author.id); + await thread.members.add(interaction.user.id); + + await interaction.reply({ + content: `Pomyślnie utworzono wątek dla ${message.author.username} na kanale ${channel.name}`, + ephemeral: true, + }); + }); + + collector.on('end', () => { + reply.edit({ + content: 'Czas na wybór kanału minął', + components: [], + }); + }); + + }, +}; diff --git a/models/ServerSettings.js b/models/ServerSettings.js index 691e72b..6cad352 100644 --- a/models/ServerSettings.js +++ b/models/ServerSettings.js @@ -7,6 +7,10 @@ const ServerSettingsSchema = Schema({ type: String, require: true, }, + help_category: { + type: String, + require: true, + }, anty_invite_enabled: { type: Boolean, require: true, @@ -31,4 +35,4 @@ const ServerSettingsSchema = Schema({ const ServerSettings = model('ServerSettings', ServerSettingsSchema); -export default ServerSettings; \ No newline at end of file +export default ServerSettings;