Add ticket claiming

This commit is contained in:
Isaac 2021-05-10 16:28:47 +01:00
parent 86aa1837c7
commit 9ebdf557df
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
2 changed files with 47 additions and 11 deletions

View File

@ -1,3 +1,5 @@
const { MessageEmbed } = require('discord.js');
module.exports = {
event: 'messageReactionAdd',
execute: async (client, r, u) => {
@ -12,33 +14,63 @@ module.exports = {
let settings = await guild.settings;
if (!settings) settings = await guild.createSettings();
const i18n = client.i18n.getLocale(settings.locale);
let member = await guild.members.fetch(u.id);
const channel = r.message.channel;
const member = await guild.members.fetch(u.id);
if (settings.blacklist.includes(u.id)) {
return client.log.info(`Ignoring blacklisted member ${u.tag}`);
} else {
let member = await guild.members.fetch(u.id);
settings.blacklist.forEach(element => {
if (guild.roles.cache.has(element) && member.roles.cache.has(element)) {
return client.log.info(`Ignoring member ${u.tag} with blacklisted role`);
}
});
}
let t_row = await client.db.models.Ticket.findOne({
where: {
id: r.message.channel.id
id: channel.id
}
});
client.log.info('got t row')
if (t_row) {
if (
t_row.opening_message === r.message.id
&& r.emoji.name === '🙌'
&& await member.isStaff()
) {
if (t_row && t_row.opening_message === r.message.id) {
if (r.emoji.name === '🙌' && await member.isStaff()) {
// ticket claiming
client.log.info('claimed')
await t_row.update({
claimed_by: member.user.id
});
await channel.updateOverwrite(member.user.id, {
VIEW_CHANNEL: true,
}, `Ticket claimed by ${member.user.tag}`);
let cat_row = await client.db.models.Category.findOne({
where: {
id: t_row.category
}
});
for (let role of cat_row.roles) {
await channel.updateOverwrite(role, {
VIEW_CHANNEL: false,
}, `Ticket claimed by ${member.user.tag}`);
}
client.log.info(`${member.user.tag} has claimed "${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.claimed.title'))
.setDescription(i18n('commands.new.response.claimed.description', member.toString()))
.setFooter(settings.footer, guild.iconURL())
);
} else {
await r.users.remove(u.id);
}
}

View File

@ -113,6 +113,10 @@
},
"questions": "Please answer the following questions:\n\n%s",
"response": {
"claimed": {
"title":"✅ Ticket claimed",
"description": "%s has claimed this ticket."
},
"created": {
"title": "✅ Ticket created",
"description": "Your ticket has been created: %s."