2020-12-18 13:37:56 +00:00
// SupportBot, Created by Emerald Services
// Ticket Command
2020-12-11 21:41:36 +00:00
2020-06-15 23:58:37 +01:00
const Discord = require ( "discord.js" );
const bot = new Discord . Client ()
const fs = require ( "fs" )
const yaml = require ( 'js-yaml' );
const supportbot = yaml . load ( fs . readFileSync ( './supportbot-config.yml' , 'utf8' ));
const TicketNumberID = require ( '../utils/TicketNumber.js' );
2020-06-20 00:10:38 +01:00
const reacted = [];
2020-06-15 23:58:37 +01:00
module . exports = {
name : supportbot . NewTicket ,
2020-07-14 19:42:46 +01:00
description : supportbot . NewTicketDesc ,
2020-06-15 23:58:37 +01:00
execute ( message , args ) {
2021-02-02 13:50:53 +00:00
if ( ! message . channel . name === supportbot . ReactionChannel ) {
if ( supportbot . DeleteMessages == "true" ) message . delete ();
}
2021-04-17 22:15:59 +02:00
let reactionUser = message . guild . members . cache . get ( message . author . id )
if ( reactionUser . roles . cache . find ( role => role . name === supportbot . TicketBlackListRole ) || reactionUser . roles . cache . find ( role => role . id === supportbot . TicketBlackListRole )) {
return message . channel . send ( `<@ ${ message . author . id } > ${ supportbot . TicketBlackListMessage } ` ). then ( msg => {
msg . delete ({ timeout : 3500 })
})
}
2020-07-27 10:43:30 -04:00
2020-06-15 23:58:37 +01:00
console . log ( `\u001b[32m` , `[ ${ supportbot . Bot_Name } ]:` , `\u001b[32m` , ` ${ message . author . tag } has executed ${ supportbot . Prefix }${ supportbot . NewTicket } !` );
// Ticket ID
let ticketNumberID = TicketNumberID . pad ( message . guild . id );
// Ticket Subject
2021-02-02 13:50:53 +00:00
const TicketSubject = args || supportbot . NoTicketSubject ;
2020-06-15 23:58:37 +01:00
// Ticket Exists
const TicketExists = new Discord . MessageEmbed ()
. setTitle ( "Ticket Exists!" )
2020-07-14 19:42:46 +01:00
. setDescription ( ` ${ supportbot . TicketExists } ` )
2020-06-15 23:58:37 +01:00
. setColor ( supportbot . WarningColour )
if ( message . guild . channels . cache . find ( SupportTicket => SupportTicket . name === ` ${ supportbot . TicketChannel } - ${ ticketNumberID } ` ))
return message . channel . send ({ embed : TicketExists });
message . guild . channels . create ( ` ${ supportbot . TicketChannel } - ${ ticketNumberID } ` , {
type : "text" ,
}). then ( SupportTicket => {
let AllUsers = message . guild . roles . cache . find ( everyone => everyone . name === '@everyone' )
let SupportStaff = message . guild . roles . cache . find ( SupportTeam => SupportTeam . name === supportbot . Staff )
let Admins = message . guild . roles . cache . find ( AdminUser => AdminUser . name === supportbot . Admin )
let DeptRole1 = message . guild . roles . cache . find ( DepartmentRole => DepartmentRole . name === ` ${ supportbot . DepartmentRole_1 } ` )
let DeptRole2 = message . guild . roles . cache . find ( DepartmentRole => DepartmentRole . name === ` ${ supportbot . DepartmentRole_2 } ` )
let DeptRole3 = message . guild . roles . cache . find ( DepartmentRole => DepartmentRole . name === ` ${ supportbot . DepartmentRole_3 } ` )
2020-09-27 01:00:54 +01:00
2020-06-15 23:58:37 +01:00
SupportTicket . updateOverwrite ( AllUsers , {
VIEW_CHANNEL : false ,
2020-09-27 01:00:54 +01:00
READ_MESSAGES : false ,
SEND_MESSAGES : false ,
2020-06-15 23:58:37 +01:00
})
2020-09-27 01:00:54 +01:00
2020-06-15 23:58:37 +01:00
SupportTicket . updateOverwrite ( message . author , {
VIEW_CHANNEL : true ,
READ_MESSAGES : true ,
SEND_MESSAGES : true ,
})
SupportTicket . updateOverwrite ( SupportStaff , {
VIEW_CHANNEL : true ,
READ_MESSAGES : true ,
SEND_MESSAGES : true ,
})
SupportTicket . updateOverwrite ( Admins , {
VIEW_CHANNEL : true ,
READ_MESSAGES : true ,
SEND_MESSAGES : true ,
})
// Ticket Category
let TicketCategory = message . guild . channels . cache . find ( category => category . name === supportbot . TicketCategory )
if ( TicketCategory ) {
SupportTicket . setParent ( TicketCategory . id )
} else {
if ( message . guild . channels . cache . get ( supportbot . TicketCategory )) {
SupportTicket . setParent ( message . guild . channels . cache . get ( supportbot . TicketCategory ). id );
}
}
// Ticket Created, Message Sent
2021-02-02 17:15:24 +00:00
if ( supportbot . AllowTicketMentions === "true" ) {
SupportTicket . send ( `<@ ${ message . author . id } >` )
}
2020-06-15 23:58:37 +01:00
const TicketMessage = new Discord . MessageEmbed ()
2021-02-02 13:50:53 +00:00
. setTitle ( supportbot . Ticket_Title . replace ( /%ticketauthor%/g , message . author . id ). replace ( /%ticketid%/g , SupportTicket . id ). replace ( /%ticketusername%/g , message . author . username ))
. setDescription ( supportbot . TicketMessage . replace ( /%ticketauthor%/g , message . author . id ). replace ( /%ticketid%/g , SupportTicket . id ). replace ( /%ticketusername%/g , message . author . username ))
2020-06-15 23:58:37 +01:00
. setColor ( supportbot . EmbedColour )
if ( supportbot . TicketSubject === "embed" ) {
if ( TicketSubject != 'No Reason Provided.' ) {
TicketMessage . addFields ({ name : 'Reason' , value : TicketSubject })
}
}
if ( supportbot . TicketSubject === "description" ) {
if ( TicketSubject != 'No Reason Provided.' ) {
SupportTicket . setTopic ( `Reason: ${ TicketSubject } - User ID: ${ message . author . id } - Ticket: ${ SupportTicket . name } ` )
}
}
2020-07-04 00:54:34 +01:00
if ( supportbot . TicketDepartments === "true" ) {
2020-06-15 23:58:37 +01:00
TicketMessage . addFields ({ name : 'Departments' , value : ` ${ supportbot . DepartmentEmoji_1 } ** ${ supportbot . DepartmentTitle_1 } **\n ${ supportbot . DepartmentEmoji_2 } ** ${ supportbot . DepartmentTitle_2 } **\n ${ supportbot . DepartmentEmoji_3 } ** ${ supportbot . DepartmentTitle_3 } **` })
}
SupportTicket . send ({ embed : TicketMessage }). then ( async function ( msg ) {
const Emoji_1 = supportbot . DepartmentEmoji_1 ;
const Emoji_2 = supportbot . DepartmentEmoji_2 ;
const Emoji_3 = supportbot . DepartmentEmoji_3 ;
2020-06-20 00:10:38 +01:00
reacted [ ticketNumberID ] = false ;
2020-07-04 00:54:34 +01:00
if ( supportbot . TicketDepartments === "true" ) {
2020-06-20 00:10:38 +01:00
await msg . react ( Emoji_1 );
await msg . react ( Emoji_2 );
await msg . react ( Emoji_3 );
let filter = ( reaction , user ) => {
if ( user . id !== message . author . id ) return ;
if ( typeof reacted [ ticketNumberID ] !== "boolean" ) return ;
delete reacted [ ticketNumberID ];
if ( reaction . emoji . name === Emoji_1 ) {
SupportTicket . updateOverwrite ( message . author . id , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
SupportTicket . updateOverwrite ( Admins , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
SupportTicket . updateOverwrite ( DeptRole1 , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
2020-07-04 00:54:34 +01:00
if ( supportbot . AllowStaff === "true" ) {
2020-06-20 00:10:38 +01:00
SupportTicket . updateOverwrite ( SupportStaff , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
2020-06-15 23:58:37 +01:00
}
2020-06-20 00:10:38 +01:00
2020-07-04 00:54:34 +01:00
if ( supportbot . AllowStaff === "false" ) {
SupportTicket . updateOverwrite ( SupportStaff , { VIEW_CHANNEL : false , READ_MESSAGES : true , SEND_MESSAGES : true , })
}
2020-06-20 00:10:38 +01:00
const Department1 = new Discord . MessageEmbed ()
. setTitle ( `> Thank for reaching out to the ** ${ supportbot . DepartmentTitle_1 } Department**. Please provide us information regarding your query.` )
. setColor ( supportbot . EmbedColour )
SupportTicket . send ({ embed : Department1 });
2021-02-02 17:15:24 +00:00
if ( supportbot . AllowTicketMentions === "true" ) {
SupportTicket . send ( `@here` )
}
2020-06-20 00:10:38 +01:00
}
if ( reaction . emoji . name === Emoji_2 ) {
SupportTicket . updateOverwrite ( message . author . id , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
SupportTicket . updateOverwrite ( Admins , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
SupportTicket . updateOverwrite ( DeptRole2 , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
2020-07-04 00:54:34 +01:00
if ( supportbot . AllowStaff === "true" ) {
2020-06-20 00:10:38 +01:00
SupportTicket . updateOverwrite ( SupportStaff , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
2020-06-15 23:58:37 +01:00
}
2020-07-04 00:54:34 +01:00
if ( supportbot . AllowStaff === "false" ) {
SupportTicket . updateOverwrite ( SupportStaff , { VIEW_CHANNEL : false , READ_MESSAGES : true , SEND_MESSAGES : true , })
}
2020-06-20 00:10:38 +01:00
const Department2 = new Discord . MessageEmbed ()
2021-02-02 17:01:58 +00:00
. setTitle ( `> Thank for reaching out to the ** ${ supportbot . DepartmentTitle_2 } Department**. Please provide us information regarding your query.` )
2020-06-20 00:10:38 +01:00
. setColor ( supportbot . EmbedColour )
SupportTicket . send ({ embed : Department2 });
2021-02-02 17:15:24 +00:00
if ( supportbot . AllowTicketMentions === "true" ) {
SupportTicket . send ( `@here` )
}
2020-06-20 00:10:38 +01:00
}
if ( reaction . emoji . name === ` ${ Emoji_3 } ` ) {
SupportTicket . updateOverwrite ( message . author . id , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
SupportTicket . updateOverwrite ( Admins , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
SupportTicket . updateOverwrite ( DeptRole3 , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
2020-07-04 00:54:34 +01:00
SupportTicket . updateOverwrite ( SupportStaff , { VIEW_CHANNEL : false , READ_MESSAGES : true , SEND_MESSAGES : true , })
2020-06-20 00:10:38 +01:00
2020-07-04 00:54:34 +01:00
if ( supportbot . AllowStaff === "true" ) {
2020-06-20 00:10:38 +01:00
SupportTicket . updateOverwrite ( SupportStaff , { VIEW_CHANNEL : true , READ_MESSAGES : true , SEND_MESSAGES : true , })
2020-06-15 23:58:37 +01:00
}
2020-07-04 00:54:34 +01:00
if ( supportbot . AllowStaff === "false" ) {
SupportTicket . updateOverwrite ( SupportStaff , { VIEW_CHANNEL : false , READ_MESSAGES : true , SEND_MESSAGES : true , })
}
2020-06-20 00:10:38 +01:00
const Department3 = new Discord . MessageEmbed ()
. setTitle ( `> Thank for reaching out to the ** ${ supportbot . DepartmentTitle_3 } Department**. Please provide us information regarding your query.` )
. setColor ( supportbot . EmbedColour )
SupportTicket . send ({ embed : Department3 });
2021-02-02 17:15:24 +00:00
if ( supportbot . AllowTicketMentions === "true" ) {
SupportTicket . send ( `@here` )
}
2020-06-20 00:10:38 +01:00
}
return [ Emoji_1 , Emoji_2 , Emoji_3 ]. includes ( reaction . emoji . name ) && user . id !== message . author . id ;
}
msg . awaitReactions ( filter , {
max : 4 ,
time : 60000 ,
errors : [ 'time' ]
}). then ( async collected => {
});
setTimeout ( async function () {
if ( typeof reacted [ ticketNumberID ] == "boolean" ) {
delete reacted [ ticketNumberID ];
//delete channel because didn't react in a minute
}
}, 60000 );
2020-06-15 23:58:37 +01:00
}
});
2021-02-02 13:50:53 +00:00
if ( message . channel . name === supportbot . ReactionChannel ) {
const CreatedTicket = new Discord . MessageEmbed ()
. setDescription ( supportbot . TicketCreatedAlert . replace ( /%ticketauthor%/g , message . author . id ). replace ( /%ticketid%/g , SupportTicket . id ). replace ( /%ticketusername%/g , message . author . username ))
. setColor ( supportbot . EmbedColour )
message . channel . send ({ embed : CreatedTicket }). then (( r ) => {
r . delete ({ timeout : 5000 })
})
} else {
const CreatedTicket = new Discord . MessageEmbed ()
. setDescription ( supportbot . TicketCreatedAlert . replace ( /%ticketauthor%/g , message . author . id ). replace ( /%ticketid%/g , SupportTicket . id ). replace ( /%ticketusername%/g , message . author . username ))
. setColor ( supportbot . EmbedColour )
message . channel . send ({ embed : CreatedTicket });
}
2020-06-15 23:58:37 +01:00
fs . writeFileSync ( "./storage/SupportTickets.json" , '{\n "ticket": "' + SupportTicket . name + '", \n "id":' + message . author . id + "\n}" , ( err ) => {
if ( ! err ) return ;
console . error ( err )
})
// Ticket Logs
const errornochannel = new Discord . MessageEmbed ()
. setTitle ( "SupportBot Error!" )
. setDescription ( `:x: **Error!** Channel not Found, This command cannot be executed proberbly as their is no channel within this server.\nThis is configurable via **supportbot-config.yml**\n\nChannel Required: \` ${ supportbot . TicketLog } \`\n\nError Code: \`SB-03\`` )
. setColor ( supportbot . ErrorColour );
const TicketLogs = new Discord . MessageEmbed ()
. setTitle ( "Ticket Log" )
. setThumbnail ( supportbot . Ticket_Thumbnail )
. addFields (
{ name : 'Ticket' , value : `<# ${ SupportTicket . id } >` },
{ name : 'User' , value : `<@ ${ message . author . id } >` },
)
. setColor ( supportbot . EmbedColour )
. setFooter ( supportbot . EmbedFooter )
let locateChannel = message . guild . channels . cache . find ( LocateChannel => LocateChannel . name === supportbot . TicketLog )
if ( ! locateChannel ) return message . channel . send ({ embed : errornochannel });
locateChannel . send ({ embed : TicketLogs });
})
}
};