2020-08-13 01:02:33 +03:00
|
|
|
/**
|
2020-10-03 17:08:10 +03:00
|
|
|
*
|
2020-08-13 01:02:33 +03:00
|
|
|
* @name DiscordTickets
|
|
|
|
* @author eartharoid <contact@eartharoid.me>
|
|
|
|
* @license GNU-GPLv3
|
2020-10-03 17:08:10 +03:00
|
|
|
*
|
2020-08-13 01:02:33 +03:00
|
|
|
*/
|
|
|
|
|
2020-08-18 00:07:05 +03:00
|
|
|
const { MessageEmbed } = require('discord.js');
|
2020-10-13 00:45:37 +03:00
|
|
|
const Logger = require('leekslazylogger');
|
|
|
|
const log = new Logger();
|
2020-08-13 01:02:33 +03:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'add',
|
|
|
|
description: 'Add a member to a ticket channel',
|
|
|
|
usage: '<@member> [... #channel]',
|
2020-08-18 00:07:05 +03:00
|
|
|
aliases: ['none'],
|
2020-08-13 01:02:33 +03:00
|
|
|
example: 'add @member to #ticket-23',
|
|
|
|
args: true,
|
2020-08-24 01:15:39 +03:00
|
|
|
async execute(client, message, args, {config, Ticket}) {
|
2020-08-17 16:46:23 +03:00
|
|
|
const guild = client.guilds.cache.get(config.guild);
|
|
|
|
|
2020-08-18 00:07:05 +03:00
|
|
|
const notTicket = new MessageEmbed()
|
2020-08-13 01:02:33 +03:00
|
|
|
.setColor(config.err_colour)
|
|
|
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
|
|
|
.setTitle(':x: **This isn\'t a ticket channel**')
|
|
|
|
.setDescription('Use this command in the ticket channel you want to add a user to, or mention the channel.')
|
|
|
|
.addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`)
|
|
|
|
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
|
2020-08-17 16:46:23 +03:00
|
|
|
.setFooter(guild.name, guild.iconURL());
|
2020-08-13 01:02:33 +03:00
|
|
|
|
|
|
|
let ticket;
|
|
|
|
|
|
|
|
let channel = message.mentions.channels.first();
|
|
|
|
|
2020-10-03 17:08:10 +03:00
|
|
|
if (!channel) {
|
2020-08-13 01:02:33 +03:00
|
|
|
channel = message.channel;
|
|
|
|
ticket = await Ticket.findOne({ where: { channel: message.channel.id } });
|
2020-10-03 19:18:07 +03:00
|
|
|
if (!ticket) return message.channel.send(notTicket);
|
2020-08-13 01:02:33 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
ticket = await Ticket.findOne({ where: { channel: channel.id } });
|
2020-10-03 17:08:10 +03:00
|
|
|
if (!ticket) {
|
2020-08-13 01:02:33 +03:00
|
|
|
notTicket
|
|
|
|
.setTitle(':x: **Channel is not a ticket**')
|
|
|
|
.setDescription(`${channel} is not a ticket channel.`);
|
|
|
|
return message.channel.send(notTicket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:18:07 +03:00
|
|
|
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) {
|
2020-08-13 01:02:33 +03:00
|
|
|
return message.channel.send(
|
2020-08-18 00:07:05 +03:00
|
|
|
new MessageEmbed()
|
2020-08-13 01:02:33 +03:00
|
|
|
.setColor(config.err_colour)
|
|
|
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
|
|
|
.setTitle(':x: **No permission**')
|
|
|
|
.setDescription(`You don't have permission to alter ${channel} as it does not belong to you and you are not staff.`)
|
|
|
|
.addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`)
|
|
|
|
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
|
2020-08-17 16:46:23 +03:00
|
|
|
.setFooter(guild.name, guild.iconURL())
|
2020-08-13 01:02:33 +03:00
|
|
|
);
|
2020-10-03 19:18:07 +03:00
|
|
|
}
|
2020-08-13 01:02:33 +03:00
|
|
|
|
2020-08-17 16:46:23 +03:00
|
|
|
let member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
|
2020-10-03 17:08:10 +03:00
|
|
|
|
2020-10-03 19:18:07 +03:00
|
|
|
if (!member) {
|
2020-08-13 01:02:33 +03:00
|
|
|
return message.channel.send(
|
2020-08-18 00:07:05 +03:00
|
|
|
new MessageEmbed()
|
2020-08-13 01:02:33 +03:00
|
|
|
.setColor(config.err_colour)
|
|
|
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
|
|
|
.setTitle(':x: **Unknown member**')
|
|
|
|
.setDescription('Please mention a valid member.')
|
|
|
|
.addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`)
|
|
|
|
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
|
2020-08-17 16:46:23 +03:00
|
|
|
.setFooter(guild.name, guild.iconURL())
|
2020-08-13 01:02:33 +03:00
|
|
|
);
|
2020-10-03 19:18:07 +03:00
|
|
|
}
|
2020-08-13 01:02:33 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
channel.updateOverwrite(member.user, {
|
|
|
|
VIEW_CHANNEL: true,
|
|
|
|
SEND_MESSAGES: true,
|
|
|
|
ATTACH_FILES: true,
|
|
|
|
READ_MESSAGE_HISTORY: true
|
|
|
|
});
|
|
|
|
|
2020-10-03 19:18:07 +03:00
|
|
|
if (channel.id !== message.channel.id) {
|
2020-08-13 01:02:33 +03:00
|
|
|
channel.send(
|
2020-08-18 00:07:05 +03:00
|
|
|
new MessageEmbed()
|
2020-08-13 01:02:33 +03:00
|
|
|
.setColor(config.colour)
|
|
|
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
|
|
|
.setTitle('**Member added**')
|
|
|
|
.setDescription(`${member} has been added by ${message.author}`)
|
2020-08-17 16:46:23 +03:00
|
|
|
.setFooter(guild.name, guild.iconURL())
|
2020-08-13 01:02:33 +03:00
|
|
|
);
|
2020-10-03 19:18:07 +03:00
|
|
|
}
|
2020-08-13 01:02:33 +03:00
|
|
|
|
|
|
|
message.channel.send(
|
2020-08-18 00:07:05 +03:00
|
|
|
new MessageEmbed()
|
2020-08-13 01:02:33 +03:00
|
|
|
.setColor(config.colour)
|
|
|
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
|
|
|
.setTitle(':white_check_mark: **Member added**')
|
2020-08-24 00:01:21 +03:00
|
|
|
.setDescription(`${member} has been added to <#${ticket.channel}>`)
|
2020-08-17 16:46:23 +03:00
|
|
|
.setFooter(guild.name, guild.iconURL())
|
2020-08-13 01:02:33 +03:00
|
|
|
);
|
2020-10-03 17:08:10 +03:00
|
|
|
|
2020-08-13 01:02:33 +03:00
|
|
|
log.info(`${message.author.tag} added a user to a ticket (#${message.channel.id})`);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
// command ends here
|
|
|
|
},
|
|
|
|
};
|