2019-07-24 16:45:29 -06:00
// ____ _ ____ _
// / ___| _ _ _ __ _ __ ___ _ __| |_| __ ) ___ | |_
// \___ \| | | | '_ \| '_ \ / _ \| '__| __| _ \ / _ \| __|
// ___) | |_| | |_) | |_) | (_) | | | |_| |_) | (_) | |_
// |____/ \__,_| .__/| .__/ \___/|_| \__|____/ \___/ \__|
// |_| |_|
2020-01-25 13:42:44 +00:00
// © 2020 Created by Emerald Services
// Licnese: MIT
2020-04-16 16:43:16 +01:00
// SupportBot v5.2
2019-06-09 23:52:41 +01:00
const Discord = require ( "discord.js" );
const fs = require ( "fs" );
const bot = new Discord . Client ();
bot . commands = new Discord . Collection ();
2020-01-25 13:48:02 +00:00
const yaml = require ( 'js-yaml' );
2020-01-25 13:55:33 +00:00
const supportbot = yaml . load ( fs . readFileSync ( './supportbot-config.yml' , 'utf8' ));
2020-01-25 13:48:02 +00:00
2019-06-09 23:52:41 +01:00
fs . readdir ( "./commands/" , ( err , files ) => {
if ( err ) console . log ( err );
let jsfile = files . filter ( f => f . split ( "." ). pop () === "js" )
2020-01-25 13:55:33 +00:00
if ( jsfile . length <= 0 ) return console . log ( ` ${ supportbot . Bot_Name } No commands found. Try to Re-download the resource` );
2019-06-09 23:52:41 +01:00
jsfile . forEach (( f , i ) =>{
let props = require ( `./commands/ ${ f } ` );
2020-01-25 13:55:33 +00:00
console . log ( `[ ${ supportbot . Bot_Name } ] > Command Loaded > ${ f } ` );
2019-06-09 23:52:41 +01:00
bot . commands . set ( props . help . name , props );
});
});
bot . addons = new Discord . Collection ();
fs . readdir ( "./sb-addons/" , ( err , files ) => {
if ( err ) console . log ( err );
let jsfile = files . filter ( f => f . split ( "." ). pop () === "js" )
2020-04-16 16:43:16 +01:00
if ( jsfile . length <= 0 ) return console . log ( ` ${ supportbot . Bot_Name } No addons detected nor default! Either download addons from https://emeraldservices.xyz/` );
2019-06-09 23:52:41 +01:00
jsfile . forEach (( f , i ) =>{
let props = require ( `./sb-addons/ ${ f } ` );
2020-01-25 13:55:33 +00:00
console . log ( `[ ${ supportbot . Bot_Name } ] > Addons Loaded > ${ f } ` );
2019-06-09 23:52:41 +01:00
bot . addons . set ( props . help . name , props );
});
});
bot . on ( "ready" , async () => {
2020-01-25 13:55:33 +00:00
bot . user . setActivity ( supportbot . BotActivity , { type : supportbot . ActvityType });
2019-11-18 15:53:02 +00:00
console . log ( `\u001b[32m` , `―――――――――――――――――― SupportBot ――――――――――――――――――` )
2020-04-16 16:43:16 +01:00
console . log ( `\u001b[37m` , ` ${ supportbot . Bot_Name } has successfully connected to discord` )
console . log ( `\u001b[37m` , `You can download additional features from our marketplace https://emeraldservices.xyz/` )
2020-03-31 09:57:39 +01:00
console . log ( `\u001b[37m` , `Invite your bot with https://discordapp.com/api/oauth2/authorize?client_id= ${ bot . user . id } &permissions=8&scope=bot` )
2020-04-16 16:43:16 +01:00
console . log ( `\u001b[37m` , `© SupportBot created by Emerald Services` )
2019-11-18 15:53:02 +00:00
console . log ( `\u001b[32m` , `―――――――――――――――――― SupportBot ――――――――――――――――――` )
2019-07-24 16:45:29 -06:00
2019-06-09 23:52:41 +01:00
});
bot . on ( "message" , async message => {
2020-01-26 22:35:45 +00:00
if ( message . author . bot ) return ;
if ( message . channel . type === "dm" ) return ;
if ( message . content . indexOf ( supportbot . Prefix ) !== 0 ) return ;
2019-06-09 23:52:41 +01:00
2020-01-26 22:35:45 +00:00
let messageArray = message . content . split ( " " );
const args = message . content . slice ( supportbot . Prefix . length ). trim (). split ( / +/g );
const command = args . shift (). toLowerCase ();
2019-06-09 23:52:41 +01:00
2020-04-16 16:43:16 +01:00
let staffGroup = message . guild . roles . cache . find ( staffRole => staffRole . name === ` ${ supportbot . StaffRole } ` )
let autoGroup = message . guild . roles . cache . find ( autoRole => autoRole . name === ` ${ supportbot . AutoRole } ` )
let deptGroup1 = message . guild . roles . cache . find ( deptRole1 => deptRole1 . name === ` ${ supportbot . Department_Role_1 } ` )
let deptGroup2 = message . guild . roles . cache . find ( deptRole2 => deptRole2 . name === ` ${ supportbot . Department_Role_2 } ` )
let deptGroup3 = message . guild . roles . cache . find ( deptRole3 => deptRole3 . name === ` ${ supportbot . Department_Role_3 } ` )
const rolemissing = new Discord . MessageEmbed ()
. setTitle ( "SupportBot Error!" )
. setDescription ( `:x: **Error!** Staff role missing, You cannot execute any commands as the following role does not exist with this server.\nThis role is configurable via **supportbot-config.yml**\n\nPlease create the role: \` ${ supportbot . StaffRole } \`\n\nError Code: \`SB-01\`` )
. setColor ( supportbot . ErrorColour )
if ( ! staffGroup ) return message . reply ( rolemissing ). catch ( err =>{ console . error ( err )})
const rolemissing1 = new Discord . MessageEmbed ()
. setTitle ( "SupportBot Error!" )
. setDescription ( `:x: **Error!** Auto Role missing, You cannot execute any commands as the following role does not exist with this server.\nThis role is configurable via **supportbot-config.yml**\n\nPlease create the role: \` ${ supportbot . AutoRole } \`\n\nError Code: \`SB-01\`` )
. setColor ( supportbot . ErrorColour )
if ( ! autoGroup ) return message . reply ( rolemissing1 ). catch ( err =>{ console . error ( err )})
const rolemissing2 = new Discord . MessageEmbed ()
. setTitle ( "SupportBot Error!" )
. setDescription ( `:x: **Error!** Department Role missing, You cannot execute any commands as the following role does not exist with this server.\nThis role is configurable via **supportbot-config.yml**\n\nPlease create the role: \` ${ supportbot . Department_Role_1 } \`\n\nError Code: \`SB-01\`` )
. setColor ( supportbot . ErrorColour )
if ( ! deptGroup1 ) return message . reply ( rolemissing2 ). catch ( err =>{ console . error ( err )})
const rolemissing3 = new Discord . MessageEmbed ()
. setTitle ( "SupportBot Error!" )
. setDescription ( `:x: **Error!** Department Role missing, You cannot execute any commands as the following role does not exist with this server.\nThis role is configurable via **supportbot-config.yml**\n\nPlease create the role: \` ${ supportbot . Department_Role_2 } \`\n\nError Code: \`SB-01\`` )
. setColor ( supportbot . ErrorColour )
if ( ! deptGroup2 ) return message . reply ( rolemissing3 ). catch ( err =>{ console . error ( err )})
const rolemissing4 = new Discord . MessageEmbed ()
. setTitle ( "SupportBot Error!" )
. setDescription ( `:x: **Error!** Department Role missing, You cannot execute any commands as the following role does not exist with this server.\nThis role is configurable via **supportbot-config.yml**\n\nPlease create the role: \` ${ supportbot . Department_Role_3 } \`\n\nError Code: \`SB-01\` ` )
. setColor ( supportbot . ErrorColour )
if ( ! deptGroup3 ) return message . reply ( rolemissing4 ). catch ( err =>{ console . error ( err )})
2020-01-26 22:35:45 +00:00
const cmd = bot . commands . get ( command );
if ( ! cmd ) return ;
cmd . run ( bot , message , args );
message . delete ();
2019-06-09 23:52:41 +01:00
});
bot . on ( "message" , async message => {
2020-01-26 22:35:45 +00:00
if ( message . author . bot ) return ;
if ( message . channel . type === "dm" ) return ;
if ( message . content . indexOf ( supportbot . Prefix ) !== 0 ) return ;
2019-06-09 23:52:41 +01:00
2020-01-26 22:35:45 +00:00
let messageArray = message . content . split ( " " );
const args = message . content . slice ( supportbot . Prefix . length ). trim (). split ( / +/g );
const addon = args . shift (). toLowerCase ();
2019-06-09 23:52:41 +01:00
2020-01-26 22:35:45 +00:00
const cmd = bot . addons . get ( addon );
if ( ! cmd ) return ;
cmd . run ( bot , message , args );
message . delete ();
2019-06-09 23:52:41 +01:00
});
2019-06-18 16:13:38 +01:00
// [SupportBot] Welcome Message && Auto Join Role
2019-06-09 23:52:41 +01:00
bot . on ( "guildMemberAdd" , ( member ) => {
2020-01-25 13:55:33 +00:00
let channel = member . guild . channels . find ( channel => channel . name === ` ${ supportbot . WelcomeChannel } ` )
let autorole = member . guild . roles . find ( autorole => autorole . name === ` ${ supportbot . AutoRole } ` )
2019-06-18 16:13:38 +01:00
2020-04-06 18:10:32 -04:00
const WelcomeMsg = new Discord . MessageEmbed ()
2020-01-25 13:55:33 +00:00
. setColor ( supportbot . EmbedColour )
. setThumbnail ( member . user . avatarURL )
. setDescription ( `:wave: ${ member . user . username } \n ${ supportbot . WelcomeMessage } ` )
2019-06-09 23:52:41 +01:00
channel . send ( WelcomeMsg );
2019-06-19 12:21:41 -06:00
member . addRole ( autorole ). catch ( console . error );
2019-06-18 16:13:38 +01:00
2019-06-09 23:52:41 +01:00
});
// [SupportBot] Leave Message
bot . on ( "guildMemberRemove" , ( member ) => {
2020-01-25 13:55:33 +00:00
let channel = member . guild . channels . find ( channel => channel . name === ` ${ supportbot . LeaveChannel } ` )
2019-06-09 23:52:41 +01:00
2020-04-06 18:10:32 -04:00
const LeaveMsg = new Discord . MessageEmbed ()
2020-01-25 13:55:33 +00:00
. setColor ( supportbot . EmbedColour )
. setThumbnail ( member . user . avatarURL )
. setDescription ( `:wave: ${ member . user . username } \n ${ supportbot . LeaveMessage } ` )
2019-06-09 23:52:41 +01:00
channel . send ( LeaveMsg );
});
2020-01-25 13:55:33 +00:00
bot . login ( supportbot . Token );