This commit is contained in:
Isaac 2021-04-03 00:02:00 +01:00
parent c01f8c3b02
commit 01519df0cf
5 changed files with 81 additions and 10 deletions

View File

@ -167,6 +167,10 @@ module.exports = async (log) => {
open: { open: {
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
defaultValue: true defaultValue: true
},
closed_by: {
type: DataTypes.CHAR(18),
allowNull: true,
} }
}, { }, {
tableName: DB_TABLE_PREFIX + 'tickets' tableName: DB_TABLE_PREFIX + 'tickets'
@ -226,7 +230,7 @@ module.exports = async (log) => {
username: DataTypes.STRING, username: DataTypes.STRING,
discriminator: DataTypes.STRING, discriminator: DataTypes.STRING,
display_name: DataTypes.STRING, display_name: DataTypes.STRING,
colour: DataTypes.INTEGER, colour: DataTypes.CHAR(6),
bot: DataTypes.BOOLEAN bot: DataTypes.BOOLEAN
}, { }, {
tableName: DB_TABLE_PREFIX + 'user_entities' tableName: DB_TABLE_PREFIX + 'user_entities'

View File

@ -4,10 +4,8 @@ module.exports = {
let settings = await message.guild?.settings; let settings = await message.guild?.settings;
if (settings?.log_messages) { if (settings?.log_messages && !message.system)
if (message.system) return;
client.tickets.archives.addMessage(message); client.tickets.archives.addMessage(message);
}
client.commands.handle(message); client.commands.handle(message);
} }

View File

@ -12,6 +12,19 @@
"title": "`%s` command usage" "title": "`%s` command usage"
}, },
"commands": { "commands": {
"close": {
"aliases": {
"delete": "delete"
},
"description": "Close a ticket channel",
"name": "close",
"response": {
"closed": {
"title": "✅ Ticket closed",
"description": "This ticket has been closed by %s.\nThe channel will be deleted in 5 seconds."
}
}
},
"new": { "new": {
"aliases": { "aliases": {
"create": "create", "create": "create",
@ -31,6 +44,10 @@
"description": "Create a new ticket", "description": "Create a new ticket",
"name": "new", "name": "new",
"response": { "response": {
"created": {
"title": "✅ Ticket created",
"description": ""
},
"no_categories": { "no_categories": {
"title": "❌ Can't create ticket", "title": "❌ Can't create ticket",
"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."

View File

@ -2,6 +2,14 @@
* A command * A command
*/ */
module.exports = class Command { module.exports = class Command {
/**
*
* @typedef CommandArgument
* @property {string} name - The argument's name
* @property {string} description - The argument's description
* @property {string} example - An example value
* @property {boolean?} required - Is this arg required? Defaults to `false`
*/
/** /**
* Create a new Command * Create a new Command
* @param {Client} client - The Discord Client * @param {Client} client - The Discord Client
@ -69,7 +77,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) { for (let arg in this.args) {
if (!this.args[arg].example) if (!this.args[arg].example)

View File

@ -1,5 +1,7 @@
const EventEmitter = require('events'); const EventEmitter = require('events');
const TicketArchives = require('./archives'); const TicketArchives = require('./archives');
const { MessageEmbed } = require('discord.js');
const { int2hex } = require('../../utils');
/** Manages tickets */ /** Manages tickets */
module.exports = class TicketManager extends EventEmitter { module.exports = class TicketManager extends EventEmitter {
@ -47,13 +49,13 @@ module.exports = class TicketManager extends EventEmitter {
let member = await guild.members.fetch(creator_id); let member = await guild.members.fetch(creator_id);
let name = cat_row.name_format let name = cat_row.name_format
.replace(/{+\s?(user)?name\s?}+/gi, member.displayName) .replace(/{+\s?(user)?name\s?}+/gi, member.displayName)
.replace(/{+\s?number\s?}+/gi, number); .replace(/{+\s?num(ber)?\s?}+/gi, number);
let t_channel = await guild.channels.create(name, { let t_channel = await guild.channels.create(name, {
type: 'text', type: 'text',
topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`, topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`,
parent: category_id, parent: category_id,
reason: `${member.tag} requested a new ticket channel` reason: `${member.user.tag} requested a new ticket channel`
}); });
await t_channel.updateOverwrite(creator_id, { await t_channel.updateOverwrite(creator_id, {
@ -95,11 +97,53 @@ module.exports = class TicketManager extends EventEmitter {
if (!t_row) throw new Error(`Could not find a ticket with ID ${ticket_id}`); if (!t_row) throw new Error(`Could not find a ticket with ID ${ticket_id}`);
ticket_id = t_row.id; ticket_id = t_row.id;
this.emit('beforeClose', ticket_id, closer_id); this.emit('beforeClose', ticket_id);
// ... let u_model_data = {
user: closer_id,
ticket: ticket_id
};
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
where: u_model_data,
defaults: u_model_data
});
this.emit('close', ticket_id, closer_id); let guild = this.client.guilds.cache.get(t_row.guild);
let member = await guild.members.fetch(closer_id);
await u_row.update({
avatar: member.user.displayAvatarURL(),
username: member.user.username,
discriminator: member.user.discriminator,
display_name: member.displayName,
colour: member.displayColor === 0 ? null : int2hex(member.displayColor),
bot: member.user.bot
});
await t_row.update({
open: false,
closed_by: closer_id
});
let channel = await this.client.channels.fetch(t_row.channel);
if (channel) {
let settings = await guild.settings;
const i18n = this.client.i18n.get(settings.locale);
await channel.send(
new MessageEmbed()
.setColor(settings.success_colour)
.setTitle(i18n('commands.close.response.closed.title'))
.setDescription(i18n('commands.close.response.closed.description', member.user.toString()))
);
setTimeout(async () => {
await channel.delete(`Ticket channel closed by ${member.user.tag}`);
}, 5000);
}
this.emit('close', ticket_id);
} }
/** /**