Skip to content

Instantly share code, notes, and snippets.

@abcdan
Created September 21, 2018 20:12
Show Gist options
  • Select an option

  • Save abcdan/95074f181569b296602702feb0784ee6 to your computer and use it in GitHub Desktop.

Select an option

Save abcdan/95074f181569b296602702feb0784ee6 to your computer and use it in GitHub Desktop.
const main = require("../bot.js")
const config = require("../settings/config.json")
const catList = require("../settings/catList.json")
// Split function
function getSecondPart(str) {
return str.split('-')[1];
}
exports.run = async (message, args) => {
if (message.channel.name.startsWith(`ticket-commands`)) return message.channel.send(`You can't use the close command in this channel.`);
if (!message.channel.name.startsWith(`ticket-`)) return message.channel.send(`You can't use the close command outside of a ticket channel.`);
message.channel.send(`Are you sure? Once confirmed, you cannot reverse this action!\nTo confirm, type \`${config.prefix}confirm\`. This will time out in 30 seconds and be cancelled.`)
.then(() => {
var keys = {"/confirm": true, "p!confirm": true, "p!close":true, "/close":true}
var filter = m => {
if(m.author.id !== message.author.id || keys[m.content.toLowerCase()] === undefined || m.channel.id !== message.channel.id) return false;
return true
}
message.channel.awaitMessages(filter, {
maxMatches: 1,
time: 30000,
errors: ['time'],
})
.then((collected) => {
if(keys[collected.first().content.toLowerCase()]) {
var embed = new main.dc.RichEmbed()
.setColor('#DC143C')
.setDescription(`:x: A ticket was closed by <@${message.author.id}>`)
message.guild.channels.get("488757107508903937").send(embed)
var report = "Ticket Log\`\`\`";
message.channel.fetchMessages({ limit: 100 }).then(msgs => {
var chatLog = msgs.array().reverse().forEach(function (message) {
var timestamp = message.createdTimestamp;
var newDate = new Date(timestamp);
var formattedTime = newDate.getDate()+"/"+(newDate.getMonth()+1)+"/"+newDate.getFullYear()+" @ "+newDate.getUTCHours()+":"+newDate.getUTCMinutes()+":"+newDate.getUTCSeconds();
report += message.author.username+"#"+message.author.discriminator+' | '+formattedTime+'\n\t'+
message.content+'\n\n'
})
let user = main.bot.users.get(getSecondPart(message.channel.name))
user.send(chatLog)
.catch(console.error);
}
)} else {
message.channel.send(":x: Close canceled")
}
})
.catch(() => {
message.channel.send(':x: Close canceled');
});
});
}
exports.help = {
cat: catList.tickets,
perm: 1,
desc: "Close a ticket"
}
exports.isPublic = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment