mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-09 14:23:08 +02:00
Make reaction panels work
This commit is contained in:
parent
349527d9f6
commit
89f754b968
@ -94,7 +94,7 @@ module.exports = class PanelCommand extends Command {
|
||||
let panel_channel,
|
||||
panel_message;
|
||||
|
||||
let emoji_map = args[arg_categories];
|
||||
let categories_map = args[arg_categories][0];
|
||||
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(settings.colour)
|
||||
@ -157,17 +157,18 @@ module.exports = class PanelCommand extends Command {
|
||||
|
||||
if (args[arg_emoji].length === 1) {
|
||||
// single category
|
||||
categories_map = {};
|
||||
categories_map[args[arg_emoji][0]] = args[arg_categories][0];
|
||||
embed.setDescription(args[arg_description]);
|
||||
panel_message = await panel_channel.send(embed);
|
||||
await panel_message.react(args[arg_emoji][0]);
|
||||
} else {
|
||||
// multi category
|
||||
let description = '';
|
||||
|
||||
emoji_map = {};
|
||||
categories_map = {};
|
||||
|
||||
for (let i in args[arg_emoji]) {
|
||||
emoji_map[args[arg_emoji][i]] = args[arg_categories][i];
|
||||
categories_map[args[arg_emoji][i]] = args[arg_categories][i];
|
||||
let cat_row = await this.client.db.models.Category.findOne({
|
||||
where: {
|
||||
id: args[arg_categories][i],
|
||||
@ -194,7 +195,7 @@ module.exports = class PanelCommand extends Command {
|
||||
message.channel.send(`✅ ${panel_channel}`);
|
||||
|
||||
await this.client.db.models.Panel.create({
|
||||
categories: emoji_map,
|
||||
categories: categories_map,
|
||||
channel: panel_channel.id,
|
||||
guild: message.guild.id,
|
||||
message: panel_message.id,
|
||||
|
@ -1,11 +1,13 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const { footer } = require('../utils/discord');
|
||||
|
||||
module.exports = {
|
||||
event: 'messageReactionAdd',
|
||||
execute: async (client, r, u) => {
|
||||
if (r.partial) {
|
||||
r = await r.fetch();
|
||||
}
|
||||
if (r.partial) r = await r.fetch();
|
||||
|
||||
if (u.partial) u = await u.fetch();
|
||||
|
||||
if (u.id === client.user.id) return;
|
||||
|
||||
@ -72,6 +74,95 @@ module.exports = {
|
||||
} else {
|
||||
await r.users.remove(u.id);
|
||||
}
|
||||
} else {
|
||||
let p_row = await client.db.models.Panel.findOne({
|
||||
where: {
|
||||
message: r.message.id
|
||||
}
|
||||
});
|
||||
|
||||
if (p_row && typeof p_row.categories !== 'string') {
|
||||
// panels
|
||||
await r.users.remove(u.id);
|
||||
|
||||
let category_id = p_row.categories[r.emoji.name];
|
||||
if (!category_id) return;
|
||||
|
||||
let cat_row = await client.db.models.Category.findOne({
|
||||
where: {
|
||||
id: category_id
|
||||
}
|
||||
});
|
||||
|
||||
let tickets = await client.db.models.Ticket.findAndCountAll({
|
||||
where: {
|
||||
category: cat_row.id,
|
||||
creator: u.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(u.username, u.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)), guild.iconURL());
|
||||
try {
|
||||
response = await u.send(embed);
|
||||
} catch {
|
||||
response = await 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(u.username, u.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)), u.iconURL());
|
||||
try {
|
||||
response = await u.send(embed);
|
||||
} catch {
|
||||
response = await channel.send(embed);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await client.tickets.create(guild.id, u.id, cat_row.id);
|
||||
} catch (error) {
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(settings.error_colour)
|
||||
.setAuthor(u.username, u.displayAvatarURL())
|
||||
.setTitle(i18n('commands.new.response.error.title'))
|
||||
.setDescription(error.message)
|
||||
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), guild.iconURL());
|
||||
try {
|
||||
response = await u.send(embed);
|
||||
} catch {
|
||||
response = await channel.send(embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (response) {
|
||||
setTimeout(async() => {
|
||||
await response.delete();
|
||||
}, 15000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user