Make reaction-less panels work

This commit is contained in:
Isaac 2021-05-12 17:43:52 +01:00
parent 89f754b968
commit 6506a4e876
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
2 changed files with 82 additions and 2 deletions

View File

@ -1,3 +1,6 @@
const { MessageEmbed } = require('discord.js');
const { footer } = require('../utils/discord');
module.exports = { module.exports = {
event: 'message', event: 'message',
execute: async (client, message) => { execute: async (client, message) => {
@ -5,6 +8,7 @@ module.exports = {
let settings = await message.guild.settings; let settings = await message.guild.settings;
if (!settings) settings = await message.guild.createSettings(); if (!settings) settings = await message.guild.createSettings();
const i18n = client.i18n.getLocale(settings.locale);
let t_row = await client.db.models.Ticket.findOne({ let t_row = await client.db.models.Ticket.findOne({
where: { where: {
@ -30,8 +34,85 @@ module.exports = {
} }
}); });
if (p_row) { if (p_row && typeof p_row.categories === 'string') {
// handle reaction-less panel // 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);
}
} }
} }

View File

@ -1,5 +1,4 @@
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const { footer } = require('../utils/discord'); const { footer } = require('../utils/discord');
module.exports = { module.exports = {