Ticket releasing

This commit is contained in:
Isaac 2021-05-13 16:01:09 +01:00
parent c9d55e6feb
commit 7cf039b8eb
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
6 changed files with 111 additions and 46 deletions

View File

@ -27,5 +27,8 @@ module.exports = class CloseCommand extends Command {
async execute(message, args) { async execute(message, args) {
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)
message.channel.send(args[0])
} }
}; };

View File

@ -1,30 +0,0 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
const { footer } = require('../utils/discord');
module.exports = class TransferCommand extends Command {
constructor(client) {
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.transfer.name'),
description: i18n('commands.transfer.description'),
aliases: [],
process_args: false,
args: [
{
name: i18n('commands.transfer.args.member.name'),
description: i18n('commands.transfer.args.member.description'),
example: i18n('commands.transfer.args.member.example'),
required: false,
}
],
staff_only: true
});
}
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);
}
};

View File

@ -111,8 +111,8 @@ class Bot extends Client {
constructor() { constructor() {
super({ super({
partials: [ partials: [
'MESSAGE',
'CHANNEL', 'CHANNEL',
'MESSAGE',
'REACTION' 'REACTION'
], ],
presence: selectPresence(), presence: selectPresence(),

View File

@ -11,9 +11,22 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
} }
async execute(r, u) { async execute(r, u) {
if (r.partial) r = await r.fetch();
if (u.partial) u = await u.fetch(); if (r.partial) {
try {
await r.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.partial) {
try {
await u.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.id === this.client.user.id) return; if (u.id === this.client.user.id) return;

View File

@ -0,0 +1,88 @@
const EventListener = require('../modules/listeners/listener');
const { MessageEmbed } = require('discord.js');
const { footer } = require('../utils/discord');
module.exports = class MessageReactionRemoveEventListener extends EventListener {
constructor(client) {
super(client, {
event: 'messageReactionRemove'
});
}
async execute(r, u) {
// release (unclaim) ticket
if (r.partial) {
try {
await r.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.partial) {
try {
await u.fetch();
} catch (err) {
return this.client.log.error(err);
}
}
if (u.id === this.client.user.id) return;
const guild = r.message.guild;
if (!guild) return;
let settings = await guild.settings;
if (!settings) settings = await guild.createSettings();
const i18n = this.client.i18n.getLocale(settings.locale);
const channel = r.message.channel;
const member = await guild.members.fetch(u.id);
let t_row = await this.client.db.models.Ticket.findOne({
where: {
id: channel.id
}
});
if (t_row && t_row.opening_message === r.message.id) {
if (r.emoji.name === '🙌' && await member.isStaff()) {
// ticket claiming
await t_row.update({
claimed_by: null
});
await channel.permissionOverwrites
.get(member.user.id)
.delete(`Ticket released by ${member.user.tag}`);
let cat_row = await this.client.db.models.Category.findOne({
where: {
id: t_row.category
}
});
for (let role of cat_row.roles) {
await channel.updateOverwrite(role, {
VIEW_CHANNEL: true,
}, `Ticket released by ${member.user.tag}`);
}
this.client.log.info(`${member.user.tag} has released "${channel.name}" in "${guild.name}"`);
await channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('commands.new.response.released.title'))
.setDescription(i18n('commands.new.response.released.description', member.toString()))
.setFooter(settings.footer, guild.iconURL())
);
} else {
await r.users.remove(u.id);
}
}
}
};

View File

@ -140,6 +140,10 @@
"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"
@ -204,19 +208,6 @@
"response": { "response": {
"updated": "✅ Settings have been updated." "updated": "✅ Settings have been updated."
} }
},
"transfer": {
"aliases": {},
"args": {
"member": {
"description": "A member mention or the ID of the member to transfer the ticket to",
"example": "@StaffMember",
"name": "member"
}
},
"description": "Transfer a ticket to another staff member",
"name": "transfer",
"response": {}
} }
}, },
"command_execution_error": { "command_execution_error": {