2020-12-18 13:37:56 +00:00
// SupportBot, Created by Emerald Services
2020-12-11 21:39:09 +00:00
// Close Command
2019-11-15 20:27:10 +00:00
2020-01-26 22:35:45 +00:00
const Discord = require ( "discord.js" );
const fs = require ( "fs" );
2020-06-15 23:58:37 +01:00
const yaml = require ( 'js-yaml' );
const { execute } = require ( "./help" );
2020-01-26 22:35:45 +00:00
const supportbot = yaml . load ( fs . readFileSync ( './supportbot-config.yml' , 'utf8' ));
2019-06-09 23:52:41 +01:00
2020-06-15 23:58:37 +01:00
module . exports = {
2020-07-04 00:54:34 +01:00
name : supportbot . CloseTicket ,
2020-07-14 19:42:46 +01:00
description : supportbot . CloseTicketDesc ,
2020-01-26 22:35:45 +00:00
2020-06-15 23:58:37 +01:00
execute ( message , args ) {
2021-05-23 10:39:24 +02:00
if ( supportbot . DeleteMessages ) message . delete ();
2020-07-27 10:43:51 -04:00
2020-06-21 15:56:16 +01:00
console . log ( `\u001b[32m` , `[ ${ supportbot . Bot_Name } ]:` , `\u001b[32m` , ` ${ message . author . tag } has executed ${ supportbot . Prefix }${ supportbot . CloseTicket } !` );
2020-06-24 09:50:14 +01:00
2020-07-04 00:54:34 +01:00
if ( ! message . channel . name . startsWith ( ` ${ supportbot . TicketChannel } -` )) {
2020-06-24 09:50:14 +01:00
const Exists = new Discord . MessageEmbed ()
2020-07-14 19:42:46 +01:00
. setTitle ( "No Ticket Found!" )
. setDescription ( ` ${ supportbot . NoValidTicket } ` )
2020-06-24 09:50:14 +01:00
. setColor ( supportbot . WarningColour );
message . channel . send ({ embed : Exists });
return ;
2020-06-21 15:56:16 +01:00
}
2021-05-23 10:39:24 +02:00
if ( supportbot . CloseConfirmation ) {
2020-06-24 09:50:14 +01:00
const CloseTicketRequest = new Discord . MessageEmbed ()
2020-07-04 00:54:34 +01:00
. setTitle ( `** ${ supportbot . ClosingTicket } **` )
. setDescription ( `Please confirm by repeating the following word.. \` ${ supportbot . ClosingConfirmation_Word } \` ` )
. setColor ( supportbot . EmbedColour );
message . channel . send ( CloseTicketRequest ). then ( m => {
message . channel . awaitMessages ( response => response . content . toLowerCase () === supportbot . ClosingConfirmation_Word , {
max : 1 ,
time : 20000 ,
errors : [ 'time' ],
}). then ( collected => {
2021-05-23 10:39:24 +02:00
let logChannel = message . guild . channels . cache . find ( channel => channel . name === supportbot . TranscriptLog ) || message . guild . channels . cache . find ( channel => channel . id === supportbot . TranscriptLog )
2020-07-04 00:54:34 +01:00
let user = message . author ;
let reason = args . join ( " " ) || "No Reason Provided." ;
let name = message . channel . name ;
let ticketChannel = message . channel ;
message . channel . send ( `** ${ supportbot . ClosingTicket } **` )
. then (() => {
const logEmbed = new Discord . MessageEmbed ()
. setTitle ( supportbot . TranscriptTitle )
. setColor ( supportbot . EmbedColour )
. setFooter ( supportbot . EmbedFooter )
. addField ( "Closed By" , message . author . tag )
. addField ( "Reason" , reason );
message . channel . messages . fetch ({ limit : 100 }). then ( msgs => {
let txt = '' ;
msgs = msgs . sort ( ( a , b ) => a . createdTimestamp - b . createdTimestamp );
txt += ` ${ message . guild . name } \n` ;
txt += `# ${ ticketChannel . name } \n` ;
txt += ` ${ msgs . size } messages\n\n\n` ;
msgs . forEach ( msg => {
if ( msg . content ) {
txt += `----- ${ msg . author . tag } at ${ msg . createdAt } \n` ;
txt += ` ${ msg . content } \n` ;
txt += `-----\n\n` ;
}
});
logChannel . send ( logEmbed ). catch ( err => {
message . reply ( err )
})
logChannel . send ( new Discord . MessageAttachment ( Buffer . from ( txt ), ` ${ name } .txt` ) );
message . channel . delete ();
})
})
})
}). catch ( () => {
m . edit ( 'The request to close the ticket has timed out.' ). then ( m2 => m2 . delete ( 3000 ) );
});
2020-06-21 15:56:16 +01:00
}
2020-06-24 09:50:14 +01:00
2021-05-23 10:39:24 +02:00
if ( ! supportbot . CloseConfirmation ) {
2020-07-04 00:54:34 +01:00
2021-05-23 10:39:24 +02:00
let logChannel = message . guild . channels . cache . find ( channel => channel . name === supportbot . TranscriptLog ) || message . guild . channels . cache . find ( channel => channel . id === supportbot . TranscriptLog )
2020-07-04 00:54:34 +01:00
let user = message . author ;
let reason = args . join ( " " ) || "No Reason Provided." ;
let name = message . channel . name ;
let ticketChannel = message . channel ;
message . channel . send ( `** ${ supportbot . ClosingTicket } **` )
. then (() => {
const logEmbed = new Discord . MessageEmbed ()
. setTitle ( supportbot . TranscriptTitle )
. setColor ( supportbot . EmbedColour )
. setFooter ( supportbot . EmbedFooter )
. addField ( "Closed By" , message . author . tag )
. addField ( "Reason" , reason );
message . channel . messages . fetch ({ limit : 100 }). then ( msgs => {
let txt = '' ;
msgs = msgs . sort ( ( a , b ) => a . createdTimestamp - b . createdTimestamp );
txt += ` ${ message . guild . name } \n` ;
txt += `# ${ ticketChannel . name } \n` ;
txt += ` ${ msgs . size } messages\n\n\n` ;
msgs . forEach ( msg => {
if ( msg . content ) {
txt += `----- ${ msg . author . tag } at ${ msg . createdAt } \n` ;
txt += ` ${ msg . content } \n` ;
txt += `-----\n\n` ;
}
});
logChannel . send ( logEmbed ). catch ( err => {
message . reply ( err )
})
logChannel . send ( new Discord . MessageAttachment ( Buffer . from ( txt ), ` ${ name } .txt` ) );
message . channel . delete ();
})
}). catch ( () => {
m . edit ( 'The request to close the ticket has timed out.' ). then ( m2 => m2 . delete ( 3000 ) );
});
}
2020-06-24 09:50:14 +01:00
2019-11-17 21:27:13 +00:00
}
2020-07-27 10:43:51 -04:00
};