Added close command, bug fixes and improvements

This commit is contained in:
Isaac 2021-05-15 23:06:31 +01:00
parent deef97286f
commit 8a99732d80
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
16 changed files with 498 additions and 239 deletions

View File

@ -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.

View File

@ -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",

View File

@ -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

View File

@ -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);
}
});
}
} }
}; };

View File

@ -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 () => {

View File

@ -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: [
...[ ...[
{ {

View File

@ -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,

View File

@ -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;

View File

@ -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 {

View File

@ -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 {

View File

@ -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"
}
} }
} }

View File

@ -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))

View File

@ -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 = {

View File

@ -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

View File

@ -21,23 +21,73 @@ module.exports = class TicketManager extends EventEmitter {
} }
/** /**
* Handle post-creation tasks * Create a new ticket
* @param {Model} t_row * @param {string} guild_id - ID of the guild to create the ticket in
* @param {Model} cat_row * @param {string} creator_id - ID of the ticket creator (user)
* @param {string} category_id - ID of the ticket category
* @param {string} [topic] - The ticket topic
*/ */
async postCreate(t_row, cat_row) { async create(guild_id, creator_id, category_id, topic) {
if (!topic) topic = '';
let guild = this.client.guilds.cache.get(cat_row.guild); let cat_row = await this.client.db.models.Category.findOne({
where: {
id: category_id
}
});
if (!cat_row)
throw new Error('Ticket category does not exist');
let cat_channel = await this.client.channels.fetch(category_id);
if (cat_channel.children.size >= 50)
throw new Error('Ticket category has reached child channel limit (50)');
let number = (await this.client.db.models.Ticket.count({
where: {
guild: guild_id
}
})) + 1;
let guild = this.client.guilds.cache.get(guild_id);
let member = await guild.members.fetch(creator_id);
let name = cat_row.name_format
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
.replace(/{+\s?num(ber)?\s?}+/gi, number);
let t_channel = await guild.channels.create(name, {
type: 'text',
topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`,
parent: category_id,
reason: `${member.user.tag} requested a new ticket channel`
});
t_channel.updateOverwrite(creator_id, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true
}, `Ticket channel created by ${member.user.tag}`);
let t_row = await this.client.db.models.Ticket.create({
id: t_channel.id,
number,
guild: guild_id,
category: category_id,
creator: creator_id,
topic: topic.length === 0 ? null : this.client.cryptr.encrypt(topic)
});
(async () => {
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 member = guild.members.cache.get(t_row.creator);
let t_channel = this.client.channels.cache.get(t_row.id);
let topic = t_row.topic topic = t_row.topic
? this.client.cryptr.decrypt(t_row.topic) ? this.client.cryptr.decrypt(t_row.topic)
: ''; : '';
if (cat_row.ping instanceof Array) { if (cat_row.ping instanceof Array && cat_row.ping.length > 0) {
let mentions = cat_row.ping.map(id => id === 'everyone' let mentions = cat_row.ping.map(id => id === 'everyone'
? '@everyone' ? '@everyone'
: id === 'here' : id === 'here'
@ -146,73 +196,12 @@ module.exports = class TicketManager extends EventEmitter {
); );
} }
} }
} })();
/**
* Create a new ticket
* @param {string} guild_id - ID of the guild to create the ticket in
* @param {string} creator_id - ID of the ticket creator (user)
* @param {string} category_id - ID of the ticket category
* @param {string} [topic] - The ticket topic
*/
async create(guild_id, creator_id, category_id, topic) {
if (!topic) topic = '';
let cat_row = await this.client.db.models.Category.findOne({
where: {
id: category_id
}
});
if (!cat_row)
throw new Error('Ticket category does not exist');
let cat_channel = await this.client.channels.fetch(category_id);
if (cat_channel.children.size >= 50)
throw new Error('Ticket category has reached child channel limit (50)');
let number = (await this.client.db.models.Ticket.count({
where: {
guild: guild_id
}
})) + 1;
let guild = this.client.guilds.cache.get(guild_id);
let member = await guild.members.fetch(creator_id);
let name = cat_row.name_format
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
.replace(/{+\s?num(ber)?\s?}+/gi, number);
let t_channel = await guild.channels.create(name, {
type: 'text',
topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`,
parent: category_id,
reason: `${member.user.tag} requested a new ticket channel`
});
t_channel.updateOverwrite(creator_id, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true
}, `Ticket channel created by ${member.user.tag}`);
let t_row = await this.client.db.models.Ticket.create({
id: t_channel.id,
number,
guild: guild_id,
category: category_id,
creator: creator_id,
topic: topic.length === 0 ? null : this.client.cryptr.encrypt(topic)
});
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,22 +297,22 @@ 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({
where: {
number: ticket_id,
guild_id
}
});
if (!t_row) return null;
ticket_id = t_row.id;
}
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: {
id: ticket_id id: ticket_id
} }
}); });
} else {
t_row = await this.client.db.models.Ticket.findOne({
where: {
number: ticket_id,
guild: guild_id
}
});
}
return t_row; return t_row;
} }

View File

@ -46,7 +46,7 @@ module.exports = {
type: 'PLAYING' type: 'PLAYING'
}, },
{ {
activity: 'for new tickets', activity: 'tickets',
type: 'WATCHING' type: 'WATCHING'
}, },
/* { // an example /* { // an example