DiscordTickets/commands/new.js

125 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-05-04 14:20:26 +03:00
const Discord = require('discord.js');
const config = require('../config.json');
2019-05-06 19:18:43 +03:00
const log = require(`leekslazylogger`);
2019-05-05 00:37:20 +03:00
// const randomString = require('random-string');
2019-05-04 00:09:48 +03:00
module.exports = {
name: 'new',
description: 'Create a new ticket',
2019-05-04 01:54:28 +03:00
usage: '<brief description>',
aliases: ['ticket'],
2019-05-04 14:20:26 +03:00
example: 'new I found an error',
2019-05-04 01:54:28 +03:00
args: true,
2019-05-04 14:20:26 +03:00
cooldown: config.cooldown,
2019-05-04 18:09:05 +03:00
guildOnly: true,
2019-10-23 00:29:30 +03:00
execute(message, args) {
2019-05-04 14:23:27 +03:00
const client = message.client;
2019-10-23 00:29:30 +03:00
// command starts here
message.delete();
2019-05-04 18:09:05 +03:00
let topic = args.join(" ");
2019-10-23 00:29:30 +03:00
// let num = randomString({
// length: 4,
// numeric: true,
// letters: false,
// special: false,
// });
let id = message.author.id.toString().substr(0, 4) + message.author.discriminator;
let chan = `ticket-${id}`;
2020-02-09 09:46:12 +02:00
if (message.guild.channels.find(channel => channel.name === chan)) {
2019-10-23 00:29:30 +03:00
if (config.useEmbeds) {
const err1 = new Discord.RichEmbed()
.setColor("#E74C3C")
.setDescription(`:x: You already have an open ticket.`)
return message.channel.send(err1)
} else {
message.channel.send(`:x: You already have an open ticket.`)
}
2019-05-04 22:16:48 +03:00
2019-10-23 00:29:30 +03:00
};
2019-05-05 00:37:20 +03:00
2019-10-23 00:29:30 +03:00
message.guild.createChannel(`ticket-${id}`, {
type: 'text'
}).then(async c => {
c.setParent(config.ticketsCat);
// let supportRole = message.guild.roles.find(`id`, config.supportRole)
2019-05-05 20:42:56 +03:00
let supportRole = message.guild.roles.get(config.supportRole)
2019-10-23 00:29:30 +03:00
if (!supportRole) return message.channel.send(":x: No **Support Team** role found.");
c.overwritePermissions(message.guild.defaultRole, {
VIEW_CHANNEL: false,
SEND_MESSAGES: false
})
c.overwritePermissions(message.member, {
VIEW_CHANNEL: true,
SEND_MESSAGES: true
})
c.overwritePermissions(supportRole, {
VIEW_CHANNEL: true,
SEND_MESSAGES: true
})
c.setTopic(`${message.author} | ${topic}`);
if (config.tagHereOnly) {
2019-05-05 20:42:56 +03:00
await c.send(`@here, a user has created a new ticket.\n`);
} else {
await c.send(`<@&${config.supportRole}>, a user has created a new ticket.\n`);
};
2019-10-23 00:29:30 +03:00
if (config.ticketImage) {
await c.send(`__**Here's your ticket channel, ${message.author}**__`, {
files: [`./image.png`]
})
2019-05-05 20:42:56 +03:00
} else {
await c.send(`__**Here's your ticket channel, ${message.author}**__`)
}
2019-10-23 00:29:30 +03:00
const created = new Discord.RichEmbed()
.setColor(config.colour)
.setDescription(`Your ticket (${c}) has been created.\nPlease read the information sent and follow any instructions given.`)
.setTimestamp();
2019-05-05 20:42:56 +03:00
const welcome = new Discord.RichEmbed()
2019-10-23 00:29:30 +03:00
.setColor(config.colour)
.setDescription(`**Ticket topic:** \`${topic}\`\n\n${config.ticketText}`)
2019-05-05 20:42:56 +03:00
2019-10-23 00:29:30 +03:00
if (config.useEmbeds) {
message.channel.send(created)
let w = await c.send(welcome)
await w.pin();
// c.fetchMessage(c.lastMessageID).delete()
2019-05-05 20:42:56 +03:00
} else {
message.channel.send(`Your ticket (${c}) has been created.\nPlease read the information sent and follow any instructions given.`)
let w = await c.send(`**Ticket topic:** \`${topic}\`\n\n${config.ticketText}`)
await w.pin()
2019-10-23 00:29:30 +03:00
// c.fetchMessage(c.lastMessageID).delete()
2019-05-05 20:42:56 +03:00
}
// log
2019-10-23 00:29:30 +03:00
if (config.useEmbeds) {
const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
.setTitle("New Ticket")
2019-05-05 20:42:56 +03:00
.setColor(config.colour)
.setDescription(`\`${topic}\``)
2019-10-23 00:29:30 +03:00
.addField("Username", message.author, true)
.addField("Channel", c, true)
.setFooter(`DiscordTickets`)
2019-05-05 20:42:56 +03:00
.setTimestamp();
2019-10-23 00:29:30 +03:00
client.channels.get(config.logChannel).send({
embed
})
} else {
client.channels.get(config.logChannel).send(`New ticket created by **${message.author.tag} (${message.author.id})**`);
}
2019-05-05 20:42:56 +03:00
log.info(`${message.author.tag} created a new ticket (#ticket-${id})`)
2019-10-23 00:29:30 +03:00
})
2019-05-04 00:09:48 +03:00
2019-05-05 20:42:56 +03:00
2019-05-04 00:09:48 +03:00
2019-10-23 00:29:30 +03:00
// command ends here
2019-05-04 00:09:48 +03:00
},
2020-02-09 09:46:12 +02:00
};