mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 08:13:09 +02:00
Added close command, bug fixes and improvements
This commit is contained in:
parent
deef97286f
commit
8a99732d80
@ -9,6 +9,7 @@
|
|||||||
[![License](https://img.shields.io/github/license/discord-tickets/bot?style=flat-square)](https://github.com/discord-tickets/bot/blob/master/LICENSE)
|
[![License](https://img.shields.io/github/license/discord-tickets/bot?style=flat-square)](https://github.com/discord-tickets/bot/blob/master/LICENSE)
|
||||||
![Codacy grade](https://img.shields.io/codacy/grade/14e6851c85444424b75b8bc3f93e93db?logo=codacy&style=flat-square)
|
![Codacy grade](https://img.shields.io/codacy/grade/14e6851c85444424b75b8bc3f93e93db?logo=codacy&style=flat-square)
|
||||||
[![Discord](https://img.shields.io/discord/451745464480432129?label=discord&color=7289DA&style=flat-square)](https://discord.gg/pXc9vyC)
|
[![Discord](https://img.shields.io/discord/451745464480432129?label=discord&color=7289DA&style=flat-square)](https://discord.gg/pXc9vyC)
|
||||||
|
[![Crowdin](https://badges.crowdin.net/discord-tickets/localized.svg)](https://i18n.discordtickets.app/project/discord-tickets)
|
||||||
|
|
||||||
An open-source ticket management bot for Discord - a free alternative to the premium and white-label plans of other popular ticketing bots.
|
An open-source ticket management bot for Discord - a free alternative to the premium and white-label plans of other popular ticketing bots.
|
||||||
|
|
||||||
|
@ -34,15 +34,15 @@
|
|||||||
"cryptr": "^6.0.2",
|
"cryptr": "^6.0.2",
|
||||||
"discord.js": "^12.5.1",
|
"discord.js": "^12.5.1",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"leeks.js": "^0.0.9",
|
"leeks.js": "^0.2.2",
|
||||||
"leekslazylogger": "^3.0.2",
|
"leekslazylogger-fastify": "^0.1.1",
|
||||||
"leekslazylogger-fastify": "^0.1.0",
|
|
||||||
"node-emoji": "^1.10.0",
|
"node-emoji": "^1.10.0",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"semver": "^7.3.4",
|
"semver": "^7.3.4",
|
||||||
"sequelize": "^6.5.0",
|
"sequelize": "^6.5.0",
|
||||||
"string-argv": "^0.3.1",
|
"string-argv": "^0.3.1",
|
||||||
"terminal-link": "^2.1.1"
|
"terminal-link": "^2.1.1",
|
||||||
|
"to-time-monthsfork": "^1.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.21.0",
|
"eslint": "^7.21.0",
|
||||||
|
@ -8,9 +8,8 @@ specifiers:
|
|||||||
discord.js: ^12.5.1
|
discord.js: ^12.5.1
|
||||||
dotenv: ^8.2.0
|
dotenv: ^8.2.0
|
||||||
eslint: ^7.21.0
|
eslint: ^7.21.0
|
||||||
leeks.js: ^0.0.9
|
leeks.js: ^0.2.2
|
||||||
leekslazylogger: ^3.0.2
|
leekslazylogger-fastify: ^0.1.1
|
||||||
leekslazylogger-fastify: ^0.1.0
|
|
||||||
mariadb: ^2.5.2
|
mariadb: ^2.5.2
|
||||||
mysql2: ^2.2.5
|
mysql2: ^2.2.5
|
||||||
node-emoji: ^1.10.0
|
node-emoji: ^1.10.0
|
||||||
@ -24,6 +23,7 @@ specifiers:
|
|||||||
string-argv: ^0.3.1
|
string-argv: ^0.3.1
|
||||||
tedious: ^11.0.3
|
tedious: ^11.0.3
|
||||||
terminal-link: ^2.1.1
|
terminal-link: ^2.1.1
|
||||||
|
to-time-monthsfork: ^1.1.4
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
'@eartharoid/i18n': 1.0.0
|
'@eartharoid/i18n': 1.0.0
|
||||||
@ -32,15 +32,15 @@ dependencies:
|
|||||||
cryptr: 6.0.2
|
cryptr: 6.0.2
|
||||||
discord.js: 12.5.1
|
discord.js: 12.5.1
|
||||||
dotenv: 8.2.0
|
dotenv: 8.2.0
|
||||||
leeks.js: 0.0.9
|
leeks.js: 0.2.2
|
||||||
leekslazylogger: 3.0.2
|
leekslazylogger-fastify: 0.1.1
|
||||||
leekslazylogger-fastify: 0.1.0
|
|
||||||
node-emoji: 1.10.0
|
node-emoji: 1.10.0
|
||||||
node-fetch: 2.6.1
|
node-fetch: 2.6.1
|
||||||
semver: 7.3.4
|
semver: 7.3.4
|
||||||
sequelize: 6.5.0_fb66e8c649bde1be622cc06164c9e22d
|
sequelize: 6.5.0_fb66e8c649bde1be622cc06164c9e22d
|
||||||
string-argv: 0.3.1
|
string-argv: 0.3.1
|
||||||
terminal-link: 2.1.1
|
terminal-link: 2.1.1
|
||||||
|
to-time-monthsfork: 1.1.4
|
||||||
|
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
sqlite3: 5.0.2
|
sqlite3: 5.0.2
|
||||||
@ -404,6 +404,10 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
tweetnacl: 0.14.5
|
tweetnacl: 0.14.5
|
||||||
|
|
||||||
|
/bignumber.js/2.4.0:
|
||||||
|
resolution: {integrity: sha1-g4qZLan51zfg9LLbC+YrsJ3Qxeg=}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/binary-extensions/2.2.0:
|
/binary-extensions/2.2.0:
|
||||||
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
@ -1449,34 +1453,18 @@ packages:
|
|||||||
package-json: 6.5.0
|
package-json: 6.5.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/leeks.js/0.0.9:
|
|
||||||
resolution: {integrity: sha512-e6UVJ1fj8f2clpHy+KpXVWVxjzB3XYFGyKRJHDlT8Gy/75BT+9bYUacpHSCoXp7RTtyMSr4eBjZrp0nHyyQVbg==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/leeks.js/0.1.1:
|
|
||||||
resolution: {integrity: sha512-axz4CyTYNcjmQc19S0I9HSC5ONGflLVm1N0uUz/MdYvuvC94yZUP/panEm9tLAj88DesBSo6D8cuyO/ctB9kYA==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/leeks.js/0.2.2:
|
/leeks.js/0.2.2:
|
||||||
resolution: {integrity: sha512-cXbDc4a0ft0pQwN2ubagjsT1xKBeW0CP6pPmbUo+KvKynFwaqtGaBjdtpwkBO5NdwSw2OcJ89BYe9mjeZEfzQQ==}
|
resolution: {integrity: sha512-cXbDc4a0ft0pQwN2ubagjsT1xKBeW0CP6pPmbUo+KvKynFwaqtGaBjdtpwkBO5NdwSw2OcJ89BYe9mjeZEfzQQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/leekslazylogger-fastify/0.1.0:
|
/leekslazylogger-fastify/0.1.1:
|
||||||
resolution: {integrity: sha512-i0sEvJbzR3gFBA7zf95cMF3CORXfC5Wv4Elv34ZAdjG5zi8S4tZY4Pw5jygG0iu0W1sMxwXR+IY+4Zi9s78zTA==}
|
resolution: {integrity: sha512-O/BFEYpsjCX3/6/GnhwajJ/CA/T9F4AwiRAPyN6y7ET0PgPfv+Q6uLktKiK/ZBcVH0f+VunSPdD0UyTXbzj7wQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
fastify-plugin: 3.0.0
|
fastify-plugin: 3.0.0
|
||||||
leekslazylogger: 3.0.1
|
leekslazylogger: 3.0.2
|
||||||
on-finished: 2.3.0
|
on-finished: 2.3.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/leekslazylogger/3.0.1:
|
|
||||||
resolution: {integrity: sha512-8o0iFuChUyjYYPFz64OfXEdQYn/H4DXyDHyuEP2hFwU/R2Bru4zP4NZbo64PzNwLBDmYZx+06xrsU4oE9WQaJg==}
|
|
||||||
dependencies:
|
|
||||||
'@eartharoid/deep-merge': 0.0.1
|
|
||||||
'@eartharoid/dtf': 1.0.8
|
|
||||||
leeks.js: 0.1.1
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/leekslazylogger/3.0.2:
|
/leekslazylogger/3.0.2:
|
||||||
resolution: {integrity: sha512-eXgQuEgoSIbtwJRQXy/DHFp1255C4br+x6CtOnrBb5j3GwmeARPMutPur1cMB5YonKBZxFXnvZLqQhr69qKg5A==}
|
resolution: {integrity: sha512-eXgQuEgoSIbtwJRQXy/DHFp1255C4br+x6CtOnrBb5j3GwmeARPMutPur1cMB5YonKBZxFXnvZLqQhr69qKg5A==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -2552,6 +2540,13 @@ packages:
|
|||||||
is-number: 7.0.0
|
is-number: 7.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/to-time-monthsfork/1.1.4:
|
||||||
|
resolution: {integrity: sha512-3bWuIwm9QeOAq/UClxFp86QMSJ4GVHmAT8X+pkM0mIMVrpJPLfSieY5qvSsfLJugLNWTVpYJ2ayKWXH3jcAdow==}
|
||||||
|
engines: {node: '>=4.6'}
|
||||||
|
dependencies:
|
||||||
|
bignumber.js: 2.4.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
/toposort-class/1.0.1:
|
/toposort-class/1.0.1:
|
||||||
resolution: {integrity: sha1-f/0feMi+KMO6Rc1OGj9e4ZO9mYg=}
|
resolution: {integrity: sha1-f/0feMi+KMO6Rc1OGj9e4ZO9mYg=}
|
||||||
dev: false
|
dev: false
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
const Command = require('../modules/commands/command');
|
const Command = require('../modules/commands/command');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed, MessageMentions } = require('discord.js');
|
||||||
|
const { Op } = require('sequelize');
|
||||||
|
const toTime = require('to-time-monthsfork');
|
||||||
const { footer } = require('../utils/discord');
|
const { footer } = require('../utils/discord');
|
||||||
|
|
||||||
module.exports = class CloseCommand extends Command {
|
module.exports = class CloseCommand extends Command {
|
||||||
@ -11,24 +13,232 @@ module.exports = class CloseCommand extends Command {
|
|||||||
description: i18n('commands.close.description'),
|
description: i18n('commands.close.description'),
|
||||||
aliases: [
|
aliases: [
|
||||||
i18n('commands.close.aliases.delete'),
|
i18n('commands.close.aliases.delete'),
|
||||||
|
i18n('commands.close.aliases.lock'),
|
||||||
],
|
],
|
||||||
process_args: false,
|
process_args: true,
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
name: i18n('commands.close.args.ticket.name'),
|
name: i18n('commands.close.args.ticket.name'),
|
||||||
description: i18n('commands.close.args.ticket.description'),
|
description: i18n('commands.close.args.ticket.description'),
|
||||||
example: i18n('commands.close.args.ticket.example'),
|
example: i18n('commands.close.args.ticket.example'),
|
||||||
required: false,
|
required: false,
|
||||||
|
// for arg parsing
|
||||||
|
alias: i18n('commands.close.args.ticket.alias'),
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n('commands.close.args.reason.name'),
|
||||||
|
description: i18n('commands.close.args.reason.description'),
|
||||||
|
example: i18n('commands.close.args.reason.example'),
|
||||||
|
required: false,
|
||||||
|
// for arg parsing
|
||||||
|
alias: i18n('commands.close.args.reason.alias'),
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n('commands.close.args.time.name'),
|
||||||
|
description: i18n('commands.close.args.time.description'),
|
||||||
|
example: i18n('commands.close.args.time.example'),
|
||||||
|
required: false,
|
||||||
|
// for arg parsing
|
||||||
|
alias: i18n('commands.close.args.time.alias'),
|
||||||
|
type: String
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(message, args) {
|
async execute(message, args) {
|
||||||
|
const arg_ticket = this.args[0].name;
|
||||||
|
const arg_reason = this.args[1].name;
|
||||||
|
const arg_time = this.args[2].name;
|
||||||
|
|
||||||
let settings = await message.guild.settings;
|
let settings = await message.guild.settings;
|
||||||
const i18n = this.client.i18n.getLocale(settings.locale);
|
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||||
|
|
||||||
this.client.log.info(args)
|
if (args[arg_time]) {
|
||||||
message.channel.send(args[0])
|
let period;
|
||||||
|
|
||||||
|
try {
|
||||||
|
period = toTime(args[arg_time]).ms();
|
||||||
|
} catch {
|
||||||
|
return await message.channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.error_colour)
|
||||||
|
.setTitle(i18n('commands.close.response.invalid_time.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.invalid_time.description'))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let tickets = await this.client.db.models.Ticket.findAndCountAll({
|
||||||
|
where: {
|
||||||
|
last_message: {
|
||||||
|
[Op.lte]: new Date(Date.now() - period)
|
||||||
|
},
|
||||||
|
guild: message.guild.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tickets.count === 0) {
|
||||||
|
return await message.channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.error_colour)
|
||||||
|
.setTitle(i18n('commands.close.response.no_tickets.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.no_tickets.description'))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let collector_message = await message.channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setTitle(i18n('commands.close.response.confirm_multiple.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.confirm_multiple.description', tickets.count, tickets.count))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
|
||||||
|
await collector_message.react('✅');
|
||||||
|
|
||||||
|
const collector_filter = (reaction, user) => {
|
||||||
|
return user.id === message.author.id && reaction.emoji.name === '✅';
|
||||||
|
};
|
||||||
|
|
||||||
|
let collector = collector_message.createReactionCollector(collector_filter, {
|
||||||
|
time: 30000
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('collect', async () => {
|
||||||
|
await collector_message.reactions.removeAll();
|
||||||
|
|
||||||
|
await message.channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.success_colour)
|
||||||
|
.setTitle(i18n('commands.close.response.closed_multiple.title', tickets.count, tickets.count))
|
||||||
|
.setDescription(i18n('commands.close.response.closed_multiple.description', tickets.count, tickets.count))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
|
||||||
|
for (let ticket of tickets.rows) {
|
||||||
|
await this.client.tickets.close(ticket.id, message.author.id, message.guild.id, args[arg_reason]);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('end', async (collected) => {
|
||||||
|
if (collected.size === 0) {
|
||||||
|
await collector_message.reactions.removeAll();
|
||||||
|
await collector_message.edit(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.error_colour)
|
||||||
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||||
|
.setTitle(i18n('commands.close.response.confirmation_timeout.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.confirmation_timeout.description'))
|
||||||
|
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
|
||||||
|
);
|
||||||
|
setTimeout(async () => {
|
||||||
|
await collector_message
|
||||||
|
.delete()
|
||||||
|
.catch(() => this.client.log.warn('Failed to delete response (collector) message'));
|
||||||
|
await message
|
||||||
|
.delete()
|
||||||
|
.catch(() => this.client.log.warn('Failed to delete original message'));
|
||||||
|
}, 15000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let t_row;
|
||||||
|
if (args[arg_ticket]) {
|
||||||
|
args[arg_ticket] = args[arg_ticket].replace(MessageMentions.CHANNELS_PATTERN, '$1');
|
||||||
|
t_row = await this.client.tickets.resolve(args[arg_ticket], message.guild.id);
|
||||||
|
|
||||||
|
if (!t_row) {
|
||||||
|
return await message.channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.error_colour)
|
||||||
|
.setTitle(i18n('commands.close.response.unresolvable.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.unresolvable.description', args[arg_ticket]))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t_row = await this.client.db.models.Ticket.findOne({
|
||||||
|
where: {
|
||||||
|
id: message.channel.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!t_row) {
|
||||||
|
return await message.channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.error_colour)
|
||||||
|
.setTitle(i18n('commands.close.response.not_a_ticket.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.not_a_ticket.description', settings.command_prefix))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let collector_message = await message.channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setTitle(i18n('commands.close.response.confirm.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.confirm.description', t_row.number))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
|
||||||
|
await collector_message.react('✅');
|
||||||
|
|
||||||
|
const collector_filter = (reaction, user) => {
|
||||||
|
return user.id === message.author.id && reaction.emoji.name === '✅';
|
||||||
|
};
|
||||||
|
|
||||||
|
let collector = collector_message.createReactionCollector(collector_filter, {
|
||||||
|
time: 30000
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('collect', async () => {
|
||||||
|
collector.stop();
|
||||||
|
|
||||||
|
if (message.channel.id === t_row.id) {
|
||||||
|
await collector_message.delete();
|
||||||
|
} else {
|
||||||
|
await collector_message.reactions.removeAll();
|
||||||
|
await collector_message.edit(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.success_colour)
|
||||||
|
.setTitle(i18n('commands.close.response.closed.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.closed.description', t_row.number))
|
||||||
|
.setFooter(settings.footer, message.guild.iconURL())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.client.tickets.close(t_row.id, message.author.id, message.guild.id, args[arg_reason]);
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('end', async (collected) => {
|
||||||
|
if (collected.size === 0) {
|
||||||
|
await collector_message.reactions.removeAll();
|
||||||
|
await collector_message.edit(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.error_colour)
|
||||||
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||||
|
.setTitle(i18n('commands.close.response.confirmation_timeout.title'))
|
||||||
|
.setDescription(i18n('commands.close.response.confirmation_timeout.description'))
|
||||||
|
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
|
||||||
|
);
|
||||||
|
setTimeout(async () => {
|
||||||
|
await collector_message
|
||||||
|
.delete()
|
||||||
|
.catch(() => this.client.log.warn('Failed to delete response (collector) message'));
|
||||||
|
await message
|
||||||
|
.delete()
|
||||||
|
.catch(() => this.client.log.warn('Failed to delete original message'));
|
||||||
|
}, 15000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -12,8 +12,9 @@ module.exports = class NewCommand extends Command {
|
|||||||
name: i18n('commands.new.name'),
|
name: i18n('commands.new.name'),
|
||||||
description: i18n('commands.new.description'),
|
description: i18n('commands.new.description'),
|
||||||
aliases: [
|
aliases: [
|
||||||
i18n('commands.new.aliases.open'),
|
|
||||||
i18n('commands.new.aliases.create'),
|
i18n('commands.new.aliases.create'),
|
||||||
|
i18n('commands.new.aliases.open'),
|
||||||
|
i18n('commands.new.aliases.ticket'),
|
||||||
],
|
],
|
||||||
process_args: false,
|
process_args: false,
|
||||||
args: [
|
args: [
|
||||||
@ -151,8 +152,11 @@ module.exports = class NewCommand extends Command {
|
|||||||
});
|
});
|
||||||
|
|
||||||
collector.on('collect', async (reaction) => {
|
collector.on('collect', async (reaction) => {
|
||||||
|
collector.stop();
|
||||||
let index = letters_array.findIndex(value => value === reaction.emoji.name); // find where the letter is in the alphabet
|
let index = letters_array.findIndex(value => value === reaction.emoji.name); // find where the letter is in the alphabet
|
||||||
if (index === -1) return await collector_message.delete({ timeout: 15000 });
|
if (index === -1) return setTimeout(async () => {
|
||||||
|
await collector_message.delete();
|
||||||
|
}, 15000);
|
||||||
await collector_message.reactions.removeAll();
|
await collector_message.reactions.removeAll();
|
||||||
create(categories.rows[index], collector_message); // create the ticket, passing the existing response message to be edited instead of creating a new one
|
create(categories.rows[index], collector_message); // create the ticket, passing the existing response message to be edited instead of creating a new one
|
||||||
});
|
});
|
||||||
@ -165,7 +169,7 @@ module.exports = class NewCommand extends Command {
|
|||||||
.setColor(settings.error_colour)
|
.setColor(settings.error_colour)
|
||||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||||
.setTitle(i18n('commands.new.response.select_category_timeout.title'))
|
.setTitle(i18n('commands.new.response.select_category_timeout.title'))
|
||||||
.setDescription(i18n('commands.new.response.select_category_timeout.description', category_list.join('\n')))
|
.setDescription(i18n('commands.new.response.select_category_timeout.description'))
|
||||||
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
|
.setFooter(footer(settings.footer, i18n('message_will_be_deleted_in', 15)), message.guild.iconURL())
|
||||||
);
|
);
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
@ -81,7 +81,7 @@ module.exports = class SettingsCommand extends Command {
|
|||||||
let cat_channel = await message.guild.channels.create(c.name, {
|
let cat_channel = await message.guild.channels.create(c.name, {
|
||||||
type: 'category',
|
type: 'category',
|
||||||
reason: `Tickets category created by ${message.member.user.tag}`,
|
reason: `Tickets category created by ${message.member.user.tag}`,
|
||||||
position: 0,
|
position: 1,
|
||||||
permissionOverwrites: [
|
permissionOverwrites: [
|
||||||
...[
|
...[
|
||||||
{
|
{
|
||||||
|
@ -44,6 +44,10 @@ module.exports = (client, sequelize) => {
|
|||||||
},
|
},
|
||||||
unique: 'number-guild'
|
unique: 'number-guild'
|
||||||
},
|
},
|
||||||
|
last_message: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
number: {
|
number: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
@ -24,16 +24,13 @@ module.exports = class MessageEventListener extends EventListener {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (t_row) {
|
if (t_row) {
|
||||||
if (settings.log_messages && !message.system) {
|
if (settings.log_messages && !message.system) this.client.tickets.archives.addMessage(message); // add the message to the archives (if it is in a ticket channel)
|
||||||
this.client.tickets.archives.addMessage(message); // add the message to the archives (if it is in a ticket channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
const ignore = [this.client.user.id, t_row.creator];
|
const ignore = [this.client.user.id, t_row.creator];
|
||||||
if (!t_row.first_response && !ignore.includes(message.author.id)) {
|
if (!t_row.first_response && !ignore.includes(message.author.id)) t_row.first_response = new Date();
|
||||||
t_row.update({
|
|
||||||
first_response: new Date()
|
t_row.last_message = new Date();
|
||||||
});
|
await t_row.save();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
|
|||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(settings.colour)
|
.setColor(settings.colour)
|
||||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||||
.setTitle(i18n('commands.new.response.claimed.title'))
|
.setTitle(i18n('ticket.claimed.title'))
|
||||||
.setDescription(i18n('commands.new.response.claimed.description', member.toString()))
|
.setDescription(i18n('ticket.claimed.description', member.toString()))
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const EventListener = require('../modules/listeners/listener');
|
const EventListener = require('../modules/listeners/listener');
|
||||||
|
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const { footer } = require('../utils/discord');
|
|
||||||
|
|
||||||
module.exports = class MessageReactionRemoveEventListener extends EventListener {
|
module.exports = class MessageReactionRemoveEventListener extends EventListener {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@ -76,8 +75,8 @@ module.exports = class MessageReactionRemoveEventListener extends EventListener
|
|||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(settings.colour)
|
.setColor(settings.colour)
|
||||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||||
.setTitle(i18n('commands.new.response.released.title'))
|
.setTitle(i18n('ticket.released.title'))
|
||||||
.setDescription(i18n('commands.new.response.released.description', member.toString()))
|
.setDescription(i18n('ticket.released.description', member.toString()))
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"bot": {
|
"bot": {
|
||||||
"missing_permissions": {
|
"missing_permissions": {
|
||||||
"title": "⚠️",
|
"description": "Discord Tickets requires the following permissions:\n%s",
|
||||||
"description": "Discord Tickets requires the following permissions:\n%s"
|
"title": "⚠️"
|
||||||
},
|
},
|
||||||
"version": "[Discord Tickets](%s) v%s by [eartharoid](%s)"
|
"version": "[Discord Tickets](%s) v%s by [eartharoid](%s)"
|
||||||
},
|
},
|
||||||
@ -66,40 +66,85 @@
|
|||||||
},
|
},
|
||||||
"close": {
|
"close": {
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"delete": "delete"
|
"delete": "delete",
|
||||||
|
"lock": "lock"
|
||||||
},
|
},
|
||||||
"args": {
|
"args": {
|
||||||
|
"reason": {
|
||||||
|
"alias": "r",
|
||||||
|
"description": "The reason for closing the ticket(s)",
|
||||||
|
"example": "",
|
||||||
|
"name": "reason"
|
||||||
|
},
|
||||||
"ticket": {
|
"ticket": {
|
||||||
"description": "The number or a channel mention of the ticket to close",
|
"alias": "t",
|
||||||
|
"description": "The ticket to close, either the number or the channel mention/ID",
|
||||||
"example": "217",
|
"example": "217",
|
||||||
"name": "ticket"
|
"name": "ticket"
|
||||||
|
},
|
||||||
|
"time": {
|
||||||
|
"alias": "T",
|
||||||
|
"description": "Close all tickets that have been inactive for the specified time",
|
||||||
|
"example": "1w",
|
||||||
|
"name": "time"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"description": "Close a ticket channel",
|
"description": "Close a ticket channel",
|
||||||
"name": "close",
|
"name": "close",
|
||||||
"response": {
|
"response": {
|
||||||
"closed": {
|
"closed": {
|
||||||
"description": "This ticket has been closed.\nThe channel will be deleted in 5 seconds.",
|
"description": "Ticket #%s has been closed.",
|
||||||
"title": "✅ Ticket closed"
|
"title": "✅ Ticket closed"
|
||||||
},
|
},
|
||||||
"closed_by_member": {
|
"closed_multiple": {
|
||||||
"description": "This ticket has been closed by %s.\nThe channel will be deleted in 5 seconds.",
|
"description": [
|
||||||
"title": "✅ Ticket closed"
|
"%d ticket has been closed.",
|
||||||
|
"%d tickets have been closed."
|
||||||
|
],
|
||||||
|
"title": [
|
||||||
|
"✅ Ticket closed",
|
||||||
|
"✅ Tickets closed"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"closed_by_member_with_reason": {
|
"confirm": {
|
||||||
"description": "This ticket has been closed by %s: `%s`\nThe channel will be deleted in 5 seconds.",
|
"description": "React with ✅ to close this ticket.",
|
||||||
"title": "✅ Ticket closed"
|
"description_with_archive": "You will be able to view an archived version of it after.\nReact with ✅ to close this ticket.",
|
||||||
|
"title": "❔ Are you sure?"
|
||||||
},
|
},
|
||||||
"closed_with_reason": {
|
"confirmation_timeout": {
|
||||||
"description": "This ticket has been closed: `%s`\nThe channel will be deleted in 5 seconds.",
|
"description": "You took too long to confirm.",
|
||||||
"title": "✅ Ticket closed"
|
"title": "❌ Reaction time expired"
|
||||||
|
},
|
||||||
|
"confirm_multiple": {
|
||||||
|
"description": [
|
||||||
|
"React with ✅ to close %d ticket.",
|
||||||
|
"React with ✅ to close %d tickets."
|
||||||
|
],
|
||||||
|
"title": "❔ Are you sure?"
|
||||||
|
},
|
||||||
|
"invalid_time": {
|
||||||
|
"description": "The time period provided could not be parsed.",
|
||||||
|
"title": "❌ Invalid input"
|
||||||
|
},
|
||||||
|
"not_a_ticket": {
|
||||||
|
"description": "Please use this command in a ticket channel or use the ticket flag.\nType `%shelp close` for more information.",
|
||||||
|
"title": "❌ This isn't a ticket channel"
|
||||||
|
},
|
||||||
|
"no_tickets": {
|
||||||
|
"description": "There are no tickets which have been inactive for this time period.",
|
||||||
|
"title": "❌ No tickets to close"
|
||||||
|
},
|
||||||
|
"unresolvable": {
|
||||||
|
"description": "`%s` could not be resolved to a ticket. Please provide the ticket ID/mention or number.",
|
||||||
|
"title": "❌ Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"new": {
|
"new": {
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"create": "create",
|
"create": "create",
|
||||||
"open": "open"
|
"open": "open",
|
||||||
|
"ticket": "ticket"
|
||||||
},
|
},
|
||||||
"args": {
|
"args": {
|
||||||
"topic": {
|
"topic": {
|
||||||
@ -117,10 +162,6 @@
|
|||||||
},
|
},
|
||||||
"questions": "Please answer the following questions:\n\n%s",
|
"questions": "Please answer the following questions:\n\n%s",
|
||||||
"response": {
|
"response": {
|
||||||
"claimed": {
|
|
||||||
"description": "%s has claimed this ticket.",
|
|
||||||
"title":"✅ Ticket claimed"
|
|
||||||
},
|
|
||||||
"created": {
|
"created": {
|
||||||
"description": "Your ticket has been created: %s.",
|
"description": "Your ticket has been created: %s.",
|
||||||
"title": "✅ Ticket created"
|
"title": "✅ Ticket created"
|
||||||
@ -140,10 +181,6 @@
|
|||||||
"description": "A server administrator must create at least one ticket category before a new ticket can be opened.",
|
"description": "A server administrator must create at least one ticket category before a new ticket can be opened.",
|
||||||
"title": "❌ Can't create ticket"
|
"title": "❌ Can't create ticket"
|
||||||
},
|
},
|
||||||
"released": {
|
|
||||||
"description": "%s has released this ticket.",
|
|
||||||
"title":"✅ Ticket released"
|
|
||||||
},
|
|
||||||
"select_category": {
|
"select_category": {
|
||||||
"description": "Select the category most relevant to your ticket's topic:\n\n%s",
|
"description": "Select the category most relevant to your ticket's topic:\n\n%s",
|
||||||
"title": "🔤 Please select the ticket category"
|
"title": "🔤 Please select the ticket category"
|
||||||
@ -222,5 +259,31 @@
|
|||||||
"staff_only": {
|
"staff_only": {
|
||||||
"description": "You must be a member of staff to use this command.",
|
"description": "You must be a member of staff to use this command.",
|
||||||
"title": "❌"
|
"title": "❌"
|
||||||
|
},
|
||||||
|
"ticket": {
|
||||||
|
"claimed": {
|
||||||
|
"description": "%s has claimed this ticket.",
|
||||||
|
"title": "✅ Ticket claimed"
|
||||||
|
},
|
||||||
|
"closed": {
|
||||||
|
"description": "This ticket has been closed.\nThe channel will be deleted in 5 seconds.",
|
||||||
|
"title": "✅ Ticket closed"
|
||||||
|
},
|
||||||
|
"closed_by_member": {
|
||||||
|
"description": "This ticket has been closed by %s.\nThe channel will be deleted in 5 seconds.",
|
||||||
|
"title": "✅ Ticket closed"
|
||||||
|
},
|
||||||
|
"closed_by_member_with_reason": {
|
||||||
|
"description": "This ticket has been closed by %s: `%s`\nThe channel will be deleted in 5 seconds.",
|
||||||
|
"title": "✅ Ticket closed"
|
||||||
|
},
|
||||||
|
"closed_with_reason": {
|
||||||
|
"description": "This ticket has been closed: `%s`\nThe channel will be deleted in 5 seconds.",
|
||||||
|
"title": "✅ Ticket closed"
|
||||||
|
},
|
||||||
|
"released": {
|
||||||
|
"description": "%s has released this ticket.",
|
||||||
|
"title": "✅ Ticket released"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -45,7 +45,7 @@ module.exports = class Command {
|
|||||||
* The command's aliases
|
* The command's aliases
|
||||||
* @type {string[]}
|
* @type {string[]}
|
||||||
*/
|
*/
|
||||||
this.aliases = data.aliases || [];
|
this.aliases = data.aliases ?? [];
|
||||||
|
|
||||||
if (!this.aliases.includes(this.name)) this.aliases.unshift(this.name);
|
if (!this.aliases.includes(this.name)) this.aliases.unshift(this.name);
|
||||||
|
|
||||||
@ -79,12 +79,7 @@ module.exports = class Command {
|
|||||||
* The command options
|
* The command options
|
||||||
* @type {CommandArgument[]}
|
* @type {CommandArgument[]}
|
||||||
*/
|
*/
|
||||||
this.args = data.args || [];
|
this.args = data.args ?? [];
|
||||||
|
|
||||||
for (let arg in this.args) {
|
|
||||||
if (!this.args[arg].example)
|
|
||||||
throw new Error(`The "${this.name}" command's "${this.args[arg].name}" argument does not have an example!`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if command is internal, false if it is from a plugin
|
* True if command is internal, false if it is from a plugin
|
||||||
@ -132,7 +127,9 @@ module.exports = class Command {
|
|||||||
|
|
||||||
const addArgs = (embed, arg) => {
|
const addArgs = (embed, arg) => {
|
||||||
let required = arg.required ? '`❗` ' : '';
|
let required = arg.required ? '`❗` ' : '';
|
||||||
embed.addField(required + arg.name, `» ${i18n('cmd_usage.args.description', arg.description)}\n» ${i18n('cmd_usage.args.example', arg.example)}`);
|
let description = `» ${i18n('cmd_usage.args.description', arg.description)}`;
|
||||||
|
if (arg.example) description += `\n» ${i18n('cmd_usage.args.example', arg.example)}`;
|
||||||
|
embed.addField(required + arg.name, description);
|
||||||
};
|
};
|
||||||
|
|
||||||
let usage,
|
let usage,
|
||||||
@ -141,14 +138,14 @@ module.exports = class Command {
|
|||||||
|
|
||||||
if (this.process_args) {
|
if (this.process_args) {
|
||||||
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
|
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
|
||||||
example = `${prefix + cmd_name} \n${this.args.map(arg => `--${arg.name} ${arg.example}`).join('\n')}`;
|
example = `${prefix + cmd_name} \n${this.args.map(arg => `--${arg.name} ${arg.example || ''}`).join('\n')}`;
|
||||||
embed = new MessageEmbed()
|
embed = new MessageEmbed()
|
||||||
.setColor(settings.error_colour)
|
.setColor(settings.error_colour)
|
||||||
.setTitle(i18n('cmd_usage.title', cmd_name))
|
.setTitle(i18n('cmd_usage.title', cmd_name))
|
||||||
.setDescription(i18n('cmd_usage.named_args') + i18n('cmd_usage.description', usage, example));
|
.setDescription(i18n('cmd_usage.named_args') + i18n('cmd_usage.description', usage, example));
|
||||||
} else {
|
} else {
|
||||||
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
|
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
|
||||||
example = `${prefix + cmd_name} ${this.args.map(arg => `${arg.example}`).join(' ')}`;
|
example = `${prefix + cmd_name} ${this.args.map(arg => `${arg.example || ''}`).join(' ')}`;
|
||||||
embed = new MessageEmbed()
|
embed = new MessageEmbed()
|
||||||
.setColor(settings.error_colour)
|
.setColor(settings.error_colour)
|
||||||
.setTitle(i18n('cmd_usage.title', cmd_name))
|
.setTitle(i18n('cmd_usage.title', cmd_name))
|
||||||
|
@ -49,7 +49,7 @@ module.exports = class PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof author === 'object') {
|
if (typeof author === 'object') {
|
||||||
author = author.name || 'unknown';
|
author = author.name ?? 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
let about = {
|
let about = {
|
||||||
|
@ -38,7 +38,7 @@ module.exports = class Plugin {
|
|||||||
* The human-friendly name of the plugin
|
* The human-friendly name of the plugin
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.name = options.name || id;
|
this.name = options.name ?? id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of commands from this plugin
|
* An array of commands from this plugin
|
||||||
|
@ -20,134 +20,6 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
this.archives = new TicketArchives(this.client);
|
this.archives = new TicketArchives(this.client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle post-creation tasks
|
|
||||||
* @param {Model} t_row
|
|
||||||
* @param {Model} cat_row
|
|
||||||
*/
|
|
||||||
async postCreate(t_row, cat_row) {
|
|
||||||
|
|
||||||
let guild = this.client.guilds.cache.get(cat_row.guild);
|
|
||||||
let settings = await guild.settings;
|
|
||||||
const i18n = this.client.i18n.getLocale(settings.locale);
|
|
||||||
let member = guild.members.cache.get(t_row.creator);
|
|
||||||
let t_channel = this.client.channels.cache.get(t_row.id);
|
|
||||||
|
|
||||||
let topic = t_row.topic
|
|
||||||
? this.client.cryptr.decrypt(t_row.topic)
|
|
||||||
: '';
|
|
||||||
|
|
||||||
if (cat_row.ping instanceof Array) {
|
|
||||||
let mentions = cat_row.ping.map(id => id === 'everyone'
|
|
||||||
? '@everyone'
|
|
||||||
: id === 'here'
|
|
||||||
? '@here'
|
|
||||||
: `<@&${id}>`);
|
|
||||||
|
|
||||||
await t_channel.send(mentions.join(', '));
|
|
||||||
}
|
|
||||||
|
|
||||||
await t_channel.send(member.user.toString());
|
|
||||||
|
|
||||||
if (cat_row.image) {
|
|
||||||
await t_channel.send(cat_row.image);
|
|
||||||
}
|
|
||||||
|
|
||||||
let description = cat_row.opening_message
|
|
||||||
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
|
|
||||||
.replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString());
|
|
||||||
let embed = new MessageEmbed()
|
|
||||||
.setColor(settings.colour)
|
|
||||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
|
||||||
.setDescription(description)
|
|
||||||
.setFooter(settings.footer, guild.iconURL());
|
|
||||||
|
|
||||||
if (topic) embed.addField(i18n('commands.new.opening_message.fields.topic'), topic);
|
|
||||||
|
|
||||||
let sent = await t_channel.send(embed);
|
|
||||||
await sent.pin({ reason: 'Ticket opening message' });
|
|
||||||
|
|
||||||
await t_row.update({
|
|
||||||
opening_message: sent.id
|
|
||||||
});
|
|
||||||
|
|
||||||
let pinned = t_channel.messages.cache.last();
|
|
||||||
|
|
||||||
if (pinned.system) {
|
|
||||||
pinned
|
|
||||||
.delete({ reason: 'Cleaning up system message' })
|
|
||||||
.catch(() => this.client.log.warn('Failed to delete system pin message'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cat_row.claiming) {
|
|
||||||
await sent.react('🙌');
|
|
||||||
}
|
|
||||||
|
|
||||||
let questions;
|
|
||||||
if (cat_row.opening_questions) {
|
|
||||||
questions = cat_row.opening_questions
|
|
||||||
.map((q, index) => `**${index + 1}.** ${q}`)
|
|
||||||
.join('\n\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cat_row.require_topic && topic.length === 0) {
|
|
||||||
let collector_message = await t_channel.send(
|
|
||||||
new MessageEmbed()
|
|
||||||
.setColor(settings.colour)
|
|
||||||
.setTitle('⚠️ ' + i18n('commands.new.request_topic.title'))
|
|
||||||
.setDescription(i18n('commands.new.request_topic.description'))
|
|
||||||
.setFooter(footer(settings.footer, i18n('collector_expires_in', 120)), guild.iconURL())
|
|
||||||
);
|
|
||||||
|
|
||||||
const collector_filter = (message) => message.author.id === t_row.creator;
|
|
||||||
|
|
||||||
let collector = t_channel.createMessageCollector(collector_filter, {
|
|
||||||
time: 120000
|
|
||||||
});
|
|
||||||
|
|
||||||
collector.on('collect', async (message) => {
|
|
||||||
topic = message.content;
|
|
||||||
await t_row.update({
|
|
||||||
topic: this.client.cryptr.encrypt(topic)
|
|
||||||
});
|
|
||||||
await t_channel.setTopic(`${member} | ${topic}`, { reason: 'User updated ticket topic' });
|
|
||||||
await sent.edit(
|
|
||||||
new MessageEmbed()
|
|
||||||
.setColor(settings.colour)
|
|
||||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
|
||||||
.setDescription(description)
|
|
||||||
.addField(i18n('commands.new.opening_message.fields.topic'), topic)
|
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
|
||||||
);
|
|
||||||
await message.react('✅');
|
|
||||||
collector.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
collector.on('end', async () => {
|
|
||||||
collector_message
|
|
||||||
.delete()
|
|
||||||
.catch(() => this.client.log.warn('Failed to delete topic collector message'));
|
|
||||||
if (cat_row.opening_questions) {
|
|
||||||
await t_channel.send(
|
|
||||||
new MessageEmbed()
|
|
||||||
.setColor(settings.colour)
|
|
||||||
.setDescription(i18n('commands.new.questions', questions))
|
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (cat_row.opening_questions) {
|
|
||||||
await t_channel.send(
|
|
||||||
new MessageEmbed()
|
|
||||||
.setColor(settings.colour)
|
|
||||||
.setDescription(i18n('commands.new.questions', questions))
|
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ticket
|
* Create a new ticket
|
||||||
* @param {string} guild_id - ID of the guild to create the ticket in
|
* @param {string} guild_id - ID of the guild to create the ticket in
|
||||||
@ -207,12 +79,129 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
topic: topic.length === 0 ? null : this.client.cryptr.encrypt(topic)
|
topic: topic.length === 0 ? null : this.client.cryptr.encrypt(topic)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
let settings = await guild.settings;
|
||||||
|
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||||
|
|
||||||
|
topic = t_row.topic
|
||||||
|
? this.client.cryptr.decrypt(t_row.topic)
|
||||||
|
: '';
|
||||||
|
|
||||||
|
if (cat_row.ping instanceof Array && cat_row.ping.length > 0) {
|
||||||
|
let mentions = cat_row.ping.map(id => id === 'everyone'
|
||||||
|
? '@everyone'
|
||||||
|
: id === 'here'
|
||||||
|
? '@here'
|
||||||
|
: `<@&${id}>`);
|
||||||
|
|
||||||
|
await t_channel.send(mentions.join(', '));
|
||||||
|
}
|
||||||
|
|
||||||
|
await t_channel.send(member.user.toString());
|
||||||
|
|
||||||
|
if (cat_row.image) {
|
||||||
|
await t_channel.send(cat_row.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
let description = cat_row.opening_message
|
||||||
|
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
|
||||||
|
.replace(/{+\s?(tag|ping|mention)?\s?}+/gi, member.user.toString());
|
||||||
|
let embed = new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||||
|
.setDescription(description)
|
||||||
|
.setFooter(settings.footer, guild.iconURL());
|
||||||
|
|
||||||
|
if (topic) embed.addField(i18n('commands.new.opening_message.fields.topic'), topic);
|
||||||
|
|
||||||
|
let sent = await t_channel.send(embed);
|
||||||
|
await sent.pin({ reason: 'Ticket opening message' });
|
||||||
|
|
||||||
|
await t_row.update({
|
||||||
|
opening_message: sent.id
|
||||||
|
});
|
||||||
|
|
||||||
|
let pinned = t_channel.messages.cache.last();
|
||||||
|
|
||||||
|
if (pinned.system) {
|
||||||
|
pinned
|
||||||
|
.delete({ reason: 'Cleaning up system message' })
|
||||||
|
.catch(() => this.client.log.warn('Failed to delete system pin message'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cat_row.claiming) {
|
||||||
|
await sent.react('🙌');
|
||||||
|
}
|
||||||
|
|
||||||
|
let questions;
|
||||||
|
if (cat_row.opening_questions) {
|
||||||
|
questions = cat_row.opening_questions
|
||||||
|
.map((q, index) => `**${index + 1}.** ${q}`)
|
||||||
|
.join('\n\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cat_row.require_topic && topic.length === 0) {
|
||||||
|
let collector_message = await t_channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setTitle('⚠️ ' + i18n('commands.new.request_topic.title'))
|
||||||
|
.setDescription(i18n('commands.new.request_topic.description'))
|
||||||
|
.setFooter(footer(settings.footer, i18n('collector_expires_in', 120)), guild.iconURL())
|
||||||
|
);
|
||||||
|
|
||||||
|
const collector_filter = (message) => message.author.id === t_row.creator;
|
||||||
|
|
||||||
|
let collector = t_channel.createMessageCollector(collector_filter, {
|
||||||
|
time: 120000
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('collect', async (message) => {
|
||||||
|
topic = message.content;
|
||||||
|
await t_row.update({
|
||||||
|
topic: this.client.cryptr.encrypt(topic)
|
||||||
|
});
|
||||||
|
await t_channel.setTopic(`${member} | ${topic}`, { reason: 'User updated ticket topic' });
|
||||||
|
await sent.edit(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||||
|
.setDescription(description)
|
||||||
|
.addField(i18n('commands.new.opening_message.fields.topic'), topic)
|
||||||
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
|
);
|
||||||
|
await message.react('✅');
|
||||||
|
collector.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('end', async () => {
|
||||||
|
collector_message
|
||||||
|
.delete()
|
||||||
|
.catch(() => this.client.log.warn('Failed to delete topic collector message'));
|
||||||
|
if (cat_row.opening_questions) {
|
||||||
|
await t_channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setDescription(i18n('commands.new.questions', questions))
|
||||||
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (cat_row.opening_questions) {
|
||||||
|
await t_channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setDescription(i18n('commands.new.questions', questions))
|
||||||
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
this.client.log.info(`${member.user.tag} created a new ticket in "${guild.name}"`);
|
this.client.log.info(`${member.user.tag} created a new ticket in "${guild.name}"`);
|
||||||
|
|
||||||
this.emit('create', t_row.id, creator_id);
|
this.emit('create', t_row.id, creator_id);
|
||||||
|
|
||||||
this.postCreate(t_row, cat_row);
|
|
||||||
|
|
||||||
return t_row;
|
return t_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +223,7 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
async close(ticket_id, closer_id, guild_id, reason) {
|
async close(ticket_id, closer_id, guild_id, reason) {
|
||||||
let t_row = await this.resolve(ticket_id, guild_id);
|
let t_row = await this.resolve(ticket_id, guild_id);
|
||||||
if (!t_row) throw new Error(`Could not find a ticket with ID ${ticket_id}`);
|
if (!t_row) throw new Error(`A ticket with the ID or number "${ticket_id}" could not be resolved`);
|
||||||
ticket_id = t_row.id;
|
ticket_id = t_row.id;
|
||||||
|
|
||||||
this.emit('beforeClose', ticket_id);
|
this.emit('beforeClose', ticket_id);
|
||||||
@ -242,7 +231,7 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
let guild = this.client.guilds.cache.get(t_row.guild);
|
let guild = this.client.guilds.cache.get(t_row.guild);
|
||||||
let settings = await guild.settings;
|
let settings = await guild.settings;
|
||||||
const i18n = this.client.i18n.getLocale(settings.locale);
|
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||||
let channel = await this.client.channels.fetch(t_row.channel);
|
let channel = await this.client.channels.fetch(t_row.id);
|
||||||
|
|
||||||
if (closer_id) {
|
if (closer_id) {
|
||||||
let member = await guild.members.fetch(closer_id);
|
let member = await guild.members.fetch(closer_id);
|
||||||
@ -251,13 +240,13 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
let description = reason
|
let description = reason
|
||||||
? i18n('commands.close.response.closed_by_member_with_reason.description', member.user.toString(), reason)
|
? i18n('ticket.closed_by_member_with_reason.description', member.user.toString(), reason)
|
||||||
: i18n('commands.close.response.closed_by_member.description', member.user.toString());
|
: i18n('ticket.closed_by_member.description', member.user.toString());
|
||||||
await channel.send(
|
await channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(settings.success_colour)
|
.setColor(settings.success_colour)
|
||||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||||
.setTitle(i18n('commands.close.response.closed.title'))
|
.setTitle(i18n('ticket.closed.title'))
|
||||||
.setDescription(description)
|
.setDescription(description)
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
);
|
);
|
||||||
@ -271,12 +260,12 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
} else {
|
} else {
|
||||||
if (channel) {
|
if (channel) {
|
||||||
let description = reason
|
let description = reason
|
||||||
? i18n('commands.close.response.closed_with_reason.description')
|
? i18n('ticket.closed_with_reason.description')
|
||||||
: i18n('commands.close.response.closed.description');
|
: i18n('ticket.closed.description');
|
||||||
await channel.send(
|
await channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(settings.success_colour)
|
.setColor(settings.success_colour)
|
||||||
.setTitle(i18n('commands.close.response.closed.title'))
|
.setTitle(i18n('ticket.closed.title'))
|
||||||
.setDescription(description)
|
.setDescription(description)
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
);
|
);
|
||||||
@ -294,8 +283,8 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
await t_row.update({
|
await t_row.update({
|
||||||
open: false,
|
open: false,
|
||||||
closed_by: closer_id || null,
|
closed_by: closer_id || null,
|
||||||
closed_reason: reason || null,
|
closed_reason: reason ? this.client.cryptr.encrypt(reason) : null,
|
||||||
pinned: [ ...pinned.keys() ]
|
pinned_messages: [...pinned.keys()]
|
||||||
});
|
});
|
||||||
|
|
||||||
this.emit('close', ticket_id);
|
this.emit('close', ticket_id);
|
||||||
@ -308,23 +297,23 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
* @param {string} [guild_id] - The ID of the ticket's guild (used if a ticket number is provided instead of ID)
|
* @param {string} [guild_id] - The ID of the ticket's guild (used if a ticket number is provided instead of ID)
|
||||||
*/
|
*/
|
||||||
async resolve(ticket_id, guild_id) {
|
async resolve(ticket_id, guild_id) {
|
||||||
if (!this.client.channels.resolve(ticket_id)) {
|
let t_row;
|
||||||
let t_row = await this.client.db.models.Ticket.findOne({
|
|
||||||
|
if (this.client.channels.resolve(ticket_id)) {
|
||||||
|
t_row = await this.client.db.models.Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
number: ticket_id,
|
id: ticket_id
|
||||||
guild_id
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
t_row = await this.client.db.models.Ticket.findOne({
|
||||||
|
where: {
|
||||||
|
number: ticket_id,
|
||||||
|
guild: guild_id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!t_row) return null;
|
|
||||||
ticket_id = t_row.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let t_row = await this.client.db.models.Ticket.findOne({
|
|
||||||
where: {
|
|
||||||
id: ticket_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return t_row;
|
return t_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ module.exports = {
|
|||||||
type: 'PLAYING'
|
type: 'PLAYING'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
activity: 'for new tickets',
|
activity: 'tickets',
|
||||||
type: 'WATCHING'
|
type: 'WATCHING'
|
||||||
},
|
},
|
||||||
/* { // an example
|
/* { // an example
|
||||||
|
Loading…
Reference in New Issue
Block a user