mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-09 14:23:08 +02:00
tickets
This commit is contained in:
parent
c01f8c3b02
commit
01519df0cf
@ -167,6 +167,10 @@ module.exports = async (log) => {
|
||||
open: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
closed_by: {
|
||||
type: DataTypes.CHAR(18),
|
||||
allowNull: true,
|
||||
}
|
||||
}, {
|
||||
tableName: DB_TABLE_PREFIX + 'tickets'
|
||||
@ -226,7 +230,7 @@ module.exports = async (log) => {
|
||||
username: DataTypes.STRING,
|
||||
discriminator: DataTypes.STRING,
|
||||
display_name: DataTypes.STRING,
|
||||
colour: DataTypes.INTEGER,
|
||||
colour: DataTypes.CHAR(6),
|
||||
bot: DataTypes.BOOLEAN
|
||||
}, {
|
||||
tableName: DB_TABLE_PREFIX + 'user_entities'
|
||||
|
@ -4,10 +4,8 @@ module.exports = {
|
||||
|
||||
let settings = await message.guild?.settings;
|
||||
|
||||
if (settings?.log_messages) {
|
||||
if (message.system) return;
|
||||
if (settings?.log_messages && !message.system)
|
||||
client.tickets.archives.addMessage(message);
|
||||
}
|
||||
|
||||
client.commands.handle(message);
|
||||
}
|
||||
|
@ -12,6 +12,19 @@
|
||||
"title": "`%s` command usage"
|
||||
},
|
||||
"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": {
|
||||
"aliases": {
|
||||
"create": "create",
|
||||
@ -31,6 +44,10 @@
|
||||
"description": "Create a new ticket",
|
||||
"name": "new",
|
||||
"response": {
|
||||
"created": {
|
||||
"title": "✅ Ticket created",
|
||||
"description": ""
|
||||
},
|
||||
"no_categories": {
|
||||
"title": "❌ Can't create ticket",
|
||||
"description": "A server administrator must create at least one ticket category before a new ticket can be opened."
|
||||
|
@ -2,6 +2,14 @@
|
||||
* A 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
|
||||
* @param {Client} client - The Discord Client
|
||||
@ -69,7 +77,7 @@ module.exports = class Command {
|
||||
* The command options
|
||||
* @type {CommandArgument[]}
|
||||
*/
|
||||
this.args = data.args;
|
||||
this.args = data.args || [];
|
||||
|
||||
for (let arg in this.args) {
|
||||
if (!this.args[arg].example)
|
||||
|
@ -1,5 +1,7 @@
|
||||
const EventEmitter = require('events');
|
||||
const TicketArchives = require('./archives');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { int2hex } = require('../../utils');
|
||||
|
||||
/** Manages tickets */
|
||||
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 name = cat_row.name_format
|
||||
.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, {
|
||||
type: 'text',
|
||||
topic: `${member}${topic.length > 0 ? ` | ${topic}` : ''}`,
|
||||
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, {
|
||||
@ -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}`);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user