Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions commands/mod/settings/help.js
Original file line number Diff line number Diff line change
@@ -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);
});

},
};
90 changes: 90 additions & 0 deletions commands/standard/redirecthelp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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 colletor = reply.createMessageComponentCollector({ time: 60000 });

colletor.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: 1440,
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,
});
});

},
};
6 changes: 5 additions & 1 deletion models/ServerSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const ServerSettingsSchema = Schema({
type: String,
require: true,
},
help_category: {
type: String,
require: true,
},
anty_invite_enabled: {
type: Boolean,
require: true,
Expand All @@ -31,4 +35,4 @@ const ServerSettingsSchema = Schema({

const ServerSettings = model('ServerSettings', ServerSettingsSchema);

export default ServerSettings;
export default ServerSettings;