mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 08:13:09 +02:00
Make reaction-less panels work
This commit is contained in:
parent
89f754b968
commit
6506a4e876
@ -1,3 +1,6 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { footer } = require('../utils/discord');
|
||||
|
||||
module.exports = {
|
||||
event: 'message',
|
||||
execute: async (client, message) => {
|
||||
@ -5,6 +8,7 @@ module.exports = {
|
||||
|
||||
let settings = await message.guild.settings;
|
||||
if (!settings) settings = await message.guild.createSettings();
|
||||
const i18n = client.i18n.getLocale(settings.locale);
|
||||
|
||||
let t_row = await client.db.models.Ticket.findOne({
|
||||
where: {
|
||||
@ -30,8 +34,85 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
if (p_row) {
|
||||
if (p_row && typeof p_row.categories === 'string') {
|
||||
// handle reaction-less panel
|
||||
|
||||
await message.delete();
|
||||
|
||||
let cat_row = await client.db.models.Category.findOne({
|
||||
where: {
|
||||
id: p_row.categories
|
||||
}
|
||||
});
|
||||
|
||||
let tickets = await client.db.models.Ticket.findAndCountAll({
|
||||
where: {
|
||||
category: cat_row.id,
|
||||
creator: message.author.id,
|
||||
open: true
|
||||
}
|
||||
});
|
||||
|
||||
let response;
|
||||
|
||||
if (tickets.count >= cat_row.max_per_member) {
|
||||
if (cat_row.max_per_member === 1) {
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(settings.error_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(i18n('commands.new.response.has_a_ticket.title'))
|
||||
.setDescription(i18n('commands.new.response.has_a_ticket.description', tickets.rows[0].id))
|
||||
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL());
|
||||
try {
|
||||
response = await message.author.send(embed);
|
||||
} catch {
|
||||
response = await message.channel.send(embed);
|
||||
}
|
||||
} else {
|
||||
let list = tickets.rows.map(row => {
|
||||
if (row.topic) {
|
||||
let description = row.topic.substring(0, 30);
|
||||
let ellipses = row.topic.length > 30 ? '...' : '';
|
||||
return `<#${row.id}>: \`${description}${ellipses}\``;
|
||||
} else {
|
||||
return `<#${row.id}>`;
|
||||
}
|
||||
});
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(settings.error_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(i18n('commands.new.response.max_tickets.title', tickets.count))
|
||||
.setDescription(i18n('commands.new.response.max_tickets.description', settings.command_prefix, list.join('\n')))
|
||||
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.author.iconURL());
|
||||
try {
|
||||
response = await message.author.send(embed);
|
||||
} catch {
|
||||
response = await message.channel.send(embed);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await client.tickets.create(message.guild.id, message.author.id, cat_row.id, message.cleanContent);
|
||||
} catch (error) {
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(settings.error_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(i18n('commands.new.response.error.title'))
|
||||
.setDescription(error.message)
|
||||
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL());
|
||||
try {
|
||||
response = await message.author.send(embed);
|
||||
} catch {
|
||||
response = await message.channel.send(embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (response) {
|
||||
setTimeout(async () => {
|
||||
await response.delete();
|
||||
}, 15000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const { footer } = require('../utils/discord');
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
Reference in New Issue
Block a user