2021-10-24 22:47:42 +01:00
|
|
|
// SupportBot | Emerald Services
|
|
|
|
|
// Ready Event
|
|
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
|
|
|
|
|
const Discord = require("discord.js");
|
|
|
|
|
const yaml = require("js-yaml");
|
2021-10-27 19:30:10 -05:00
|
|
|
const supportbot = yaml.load(
|
|
|
|
|
fs.readFileSync("./Configs/supportbot.yml", "utf8")
|
|
|
|
|
);
|
2021-10-24 22:47:42 +01:00
|
|
|
const panelconfig = yaml.load(
|
2021-10-27 19:30:10 -05:00
|
|
|
fs.readFileSync("./Configs/ticket-panel.yml", "utf8")
|
2021-10-24 22:47:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const Event = require("../Structures/Event.js");
|
|
|
|
|
|
2021-11-17 19:04:20 -06:00
|
|
|
module.exports = new Event("ready", async (client) => {
|
2021-12-15 00:19:40 -06:00
|
|
|
const { getRole, getChannel, getCategory } = client;
|
2021-10-24 22:47:42 +01:00
|
|
|
client.user.setActivity(supportbot.BotActivity, {
|
|
|
|
|
type: supportbot.ActivityType,
|
|
|
|
|
url: supportbot.StreamingURL,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log(`\u001b[32m`, `┏━━━┓╋╋╋╋╋╋╋╋╋╋╋╋╋┏┓┏━━┓╋╋╋┏┓`);
|
|
|
|
|
console.log(`\u001b[32m`, `┃┏━┓┃╋╋╋╋╋╋╋╋╋╋╋╋┏┛┗┫┏┓┃╋╋┏┛┗┓`);
|
|
|
|
|
console.log(`\u001b[32m`, `┃┗━━┳┓┏┳━━┳━━┳━━┳┻┓┏┫┗┛┗┳━┻┓┏┛`);
|
|
|
|
|
console.log(`\u001b[32m`, `┗━━┓┃┃┃┃┏┓┃┏┓┃┏┓┃┏┫┃┃┏━┓┃┏┓┃┃`);
|
|
|
|
|
console.log(`\u001b[32m`, `┃┗━┛┃┗┛┃┗┛┃┗┛┃┗┛┃┃┃┗┫┗━┛┃┗┛┃┗┓`);
|
|
|
|
|
console.log(`\u001b[32m`, `┗━━━┻━━┫┏━┫┏━┻━━┻┛┗━┻━━━┻━━┻━┛`);
|
|
|
|
|
console.log(`\u001b[32m`, `┗╋╋╋╋╋╋╋┃┃╋┃┃`);
|
|
|
|
|
console.log(`\u001b[32m`, `╋╋╋╋╋╋╋┗┛╋┗┛`);
|
|
|
|
|
console.log(` `);
|
|
|
|
|
console.log(`\u001b[31m`, `――――――――――――――――――――――――――――――――――――――――――――`);
|
|
|
|
|
console.log(` `);
|
|
|
|
|
console.log(
|
|
|
|
|
`\u001b[33m`,
|
|
|
|
|
`${supportbot.Name} v${supportbot.SupportBot_Version}`,
|
|
|
|
|
`\u001b[36m`,
|
|
|
|
|
`Connected to Discord`
|
|
|
|
|
);
|
2021-12-23 11:36:14 +00:00
|
|
|
console.log(
|
|
|
|
|
`\u001b[33m`,
|
|
|
|
|
`Invite to your server:`,
|
|
|
|
|
`\u001b[36m`,
|
|
|
|
|
`https://discord.com/api/oauth2/authorize?client_id=` + client.user.id + `&permissions=8&scope=bot%20applications.commands`
|
|
|
|
|
);
|
2021-10-24 22:47:42 +01:00
|
|
|
console.log(
|
|
|
|
|
`\u001b[33m`,
|
|
|
|
|
`Resources:`,
|
|
|
|
|
`\u001b[36m`,
|
|
|
|
|
`https://emeraldsrv.dev/resources`
|
|
|
|
|
);
|
|
|
|
|
console.log(
|
|
|
|
|
`\u001b[33m`,
|
|
|
|
|
`Documentation:`,
|
|
|
|
|
`\u001b[36m`,
|
2021-12-23 11:36:14 +00:00
|
|
|
`https://emeraldsrv.dev/wiki/supportbot`
|
2021-10-24 22:47:42 +01:00
|
|
|
);
|
|
|
|
|
console.log(
|
|
|
|
|
`\u001b[33m`,
|
|
|
|
|
`Discord:`,
|
|
|
|
|
`\u001b[36m`,
|
|
|
|
|
`https://emeraldsrv.dev/discord`
|
|
|
|
|
);
|
|
|
|
|
console.log(
|
|
|
|
|
`\u001b[33m`,
|
|
|
|
|
`Hosting:`,
|
|
|
|
|
`\u001b[36m`,
|
|
|
|
|
`https://emeraldsrv.dev/hosting`
|
|
|
|
|
);
|
|
|
|
|
console.log(` `);
|
|
|
|
|
console.log(`\u001b[37m`, `SupportBot proudly created by Emerald Services`);
|
|
|
|
|
console.log(` `);
|
|
|
|
|
console.log(`\u001b[31m`, `――――――――――――――――――――――――――――――――――――――――――――`);
|
2021-11-17 19:04:20 -06:00
|
|
|
if (
|
|
|
|
|
!supportbot.Guild ||
|
|
|
|
|
(await client.guilds.cache.size) !== 1 ||
|
|
|
|
|
(await client.guilds.cache.first().id) !== supportbot.Guild
|
|
|
|
|
) {
|
|
|
|
|
console.log(
|
|
|
|
|
`\u001b[31m`,
|
|
|
|
|
`${client.user.username} is not in the correct server set in your config. Please join the server and restart the bot.`
|
|
|
|
|
);
|
|
|
|
|
console.log(`\u001b[31m`, `${client.user.username} will now exit.`);
|
|
|
|
|
return process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
const roles = [
|
|
|
|
|
supportbot.Admin,
|
|
|
|
|
supportbot.Staff,
|
|
|
|
|
supportbot.TicketBlackListRole,
|
|
|
|
|
supportbot.DepartmentRole_1,
|
|
|
|
|
supportbot.DepartmentRole_2,
|
|
|
|
|
supportbot.DepartmentRole_3,
|
|
|
|
|
];
|
|
|
|
|
if (supportbot.AutoRole) roles.push(supportbot.AutoRole_Role);
|
|
|
|
|
const channels = [
|
|
|
|
|
supportbot.SuggestionChannel,
|
|
|
|
|
supportbot.TicketLog,
|
|
|
|
|
supportbot.TranscriptLog,
|
|
|
|
|
panelconfig.Channel,
|
|
|
|
|
];
|
2021-12-15 00:19:40 -06:00
|
|
|
const categories = [supportbot.TicketCategory];
|
2021-11-17 19:04:20 -06:00
|
|
|
|
2021-12-15 00:19:40 -06:00
|
|
|
const missingC = [];
|
|
|
|
|
const missingR = [];
|
|
|
|
|
const missingCat = [];
|
2021-11-17 19:04:20 -06:00
|
|
|
for (let c of channels) {
|
2021-12-15 00:19:40 -06:00
|
|
|
const find = await getChannel(c, client.guilds.cache.first());
|
2021-11-17 19:04:20 -06:00
|
|
|
if (!find) missingC.push(c);
|
|
|
|
|
}
|
|
|
|
|
for (let r of roles) {
|
2021-12-15 00:19:40 -06:00
|
|
|
const find = await getRole(r, client.guilds.cache.first());
|
2021-11-17 19:04:20 -06:00
|
|
|
if (!find) missingR.push(r);
|
|
|
|
|
}
|
2021-12-15 00:19:40 -06:00
|
|
|
for (let cat of categories) {
|
|
|
|
|
const find = await getCategory(cat, client.guilds.cache.first());
|
|
|
|
|
if (!find) missingCat.push(cat);
|
|
|
|
|
}
|
2021-10-24 22:47:42 +01:00
|
|
|
|
2021-11-17 19:04:20 -06:00
|
|
|
if (missingR.length > 0) {
|
|
|
|
|
console.log(
|
|
|
|
|
"\u001b[33m",
|
|
|
|
|
`[WARN] The following Roles could not be found! Please check your configs!\n${missingR.join(
|
|
|
|
|
", "
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (missingC.length > 0) {
|
|
|
|
|
console.log(
|
|
|
|
|
"\u001b[33m",
|
|
|
|
|
`[WARN] The following Channels could not be found! Please check your configs!\n${missingC.join(
|
|
|
|
|
", "
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-12-15 00:19:40 -06:00
|
|
|
if (missingCat.length > 0) {
|
|
|
|
|
console.log(
|
|
|
|
|
"\u001b[33m",
|
|
|
|
|
`[WARN] The following Categories could not be found! Please check your configs!\n${missingCat.join(
|
|
|
|
|
", "
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-10-24 22:47:42 +01:00
|
|
|
if (panelconfig.TicketPanel) {
|
2021-12-19 13:03:33 -06:00
|
|
|
let chan1 = await client.getChannel(
|
|
|
|
|
panelconfig.Channel,
|
|
|
|
|
client.guilds.cache.first()
|
2021-10-24 22:47:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!chan1) {
|
|
|
|
|
console.log(
|
|
|
|
|
"\u001b[33m",
|
|
|
|
|
"[WARN] Ticket reaction panel is not setup, You can do so via the configuration file!"
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 19:30:10 -05:00
|
|
|
const panelid = JSON.parse(
|
|
|
|
|
fs.readFileSync("./Data/ticket-panel-id.json", "utf8")
|
2021-10-24 22:47:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
chan1.messages.fetch(panelid.TicketPanelID).catch(async (r) => {
|
|
|
|
|
let embed = new Discord.MessageEmbed()
|
|
|
|
|
.setTitle(`${panelconfig.PanelTitle}`)
|
|
|
|
|
.setColor(supportbot.SuccessColour)
|
|
|
|
|
.setFooter(supportbot.EmbedFooter);
|
|
|
|
|
|
|
|
|
|
if (panelconfig.TicketPanel_Description) {
|
|
|
|
|
embed.setDescription(panelconfig.PanelMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (panelconfig.TicketPanel_Thumbnail) {
|
|
|
|
|
embed.setThumbnail(panelconfig.PanelThumbnail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (panelconfig.TicketPanel_Image) {
|
|
|
|
|
embed.setImage(panelconfig.PanelImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let button = new Discord.MessageButton()
|
|
|
|
|
.setLabel(panelconfig.ButtonLabel)
|
|
|
|
|
.setCustomId("openticket")
|
2021-11-10 21:18:49 -06:00
|
|
|
.setStyle(panelconfig.ButtonColour)
|
|
|
|
|
.setEmoji(panelconfig.ButtonEmoji);
|
2021-10-24 22:47:42 +01:00
|
|
|
|
|
|
|
|
let row = new Discord.MessageActionRow().addComponents(button);
|
|
|
|
|
|
|
|
|
|
await chan1
|
|
|
|
|
.send({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
components: [row],
|
|
|
|
|
})
|
|
|
|
|
.then((r) => {
|
|
|
|
|
let data = {
|
2021-12-18 22:18:05 -06:00
|
|
|
id: panelid.id,
|
2021-10-24 22:47:42 +01:00
|
|
|
TicketPanelID: `${r.id}`,
|
|
|
|
|
};
|
2021-10-27 20:19:27 -05:00
|
|
|
fs.writeFileSync(
|
|
|
|
|
"./Data/ticket-panel-id.json",
|
|
|
|
|
JSON.stringify(data),
|
|
|
|
|
"utf8"
|
|
|
|
|
);
|
2021-10-24 22:47:42 +01:00
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
console.log("Raw" + e);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|