Files
SupportBot/Events/ready.js
T

246 lines
7.2 KiB
JavaScript
Raw Normal View History

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");
2022-08-12 01:35:36 +01:00
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
);
2022-08-12 01:35:36 +01:00
const cmdconfig = yaml.load(
fs.readFileSync("./Configs/commands.yml", "utf8")
);
const msgconfig = yaml.load(
fs.readFileSync("./Configs/messages.yml", "utf8")
);
2021-10-24 22:47:42 +01:00
const Event = require("../Structures/Event.js");
2022-02-27 04:30:15 +00:00
module.exports = new Event("ready", async (client, interaction) => {
const { getRole, getChannel, getCategory } = client;
2022-07-23 07:50:12 +01:00
client.user.setActivity(supportbot.Activity.Status, {
type: supportbot.Activity.Type,
url: supportbot.Activity.StreamingURL,
2021-10-24 22:47:42 +01:00
});
2022-07-22 13:19:05 +01:00
console.log(`\u001b[32m`, `――――――――――――――――――――――――――――――――――――――――――――`);
console.log(` `);
console.log(`\u001b[31m`, `┏━━━┓╋╋╋╋╋╋╋╋╋╋╋╋╋┏┓┏━━┓╋╋╋┏┓`);
console.log(`\u001b[31m`, `┃┏━┓┃╋╋╋╋╋╋╋╋╋╋╋╋┏┛┗┫┏┓┃╋╋┏┛┗┓`);
console.log(`\u001b[31m`, `┃┗━━┳┓┏┳━━┳━━┳━━┳┻┓┏┫┗┛┗┳━┻┓┏┛`);
console.log(`\u001b[31m`, `┗━━┓┃┃┃┃┏┓┃┏┓┃┏┓┃┏┫┃┃┏━┓┃┏┓┃┃`);
console.log(`\u001b[31m`, `┃┗━┛┃┗┛┃┗┛┃┗┛┃┗┛┃┃┃┗┫┗━┛┃┗┛┃┗┓`);
console.log(`\u001b[31m`, `┗━━━┻━━┫┏━┫┏━┻━━┻┛┗━┻━━━┻━━┻━┛`);
console.log(`\u001b[31m`, `┗╋╋╋╋╋╋╋┃┃╋┃┃`);
console.log(`\u001b[31m`, `╋╋╋╋╋╋╋┗┛╋┗┛`);
2021-10-24 22:47:42 +01:00
console.log(` `);
2022-06-28 03:14:54 +01:00
console.log(`\u001b[32m`, `――――――――――――――――――――――――――――――――――――――――――――`);
2021-10-24 22:47:42 +01:00
console.log(` `);
console.log(
2022-07-22 13:19:05 +01:00
`\u001b[31m`,
`${supportbot.General.Name} | [${supportbot.SupportBot_Version}]`,
`\u001b[32m`,
`Connected to Discord`,
2021-10-24 22:47:42 +01:00
);
2022-07-22 13:19:05 +01:00
console.log(`\u001b[31m`, `SupportBot proudly created by Emerald Development`);
console.log(` `);
console.log(
2022-07-22 13:19:05 +01:00
`\u001b[31m`,
`Discord`,
`\u001b[32m`,
`https://dsc.gg/emerald-dev`,
);
2022-07-22 13:19:05 +01:00
2021-10-24 22:47:42 +01:00
console.log(
2022-07-22 13:19:05 +01:00
`\u001b[31m`,
`Resources`,
`\u001b[32m`,
`https://emeraldsrv.dev`,
2021-10-24 22:47:42 +01:00
);
2022-07-22 13:19:05 +01:00
2021-10-24 22:47:42 +01:00
console.log(
2022-07-22 13:19:05 +01:00
`\u001b[31m`,
`Documentation`,
`\u001b[32m`,
`https://emeraldsrv.dev/wiki`,
2021-10-24 22:47:42 +01:00
);
2022-07-22 13:19:05 +01:00
2021-10-24 22:47:42 +01:00
console.log(
2022-07-22 13:19:05 +01:00
`\u001b[31m`,
`Third-Party Documentation`,
`\u001b[32m`,
`https://emeraldsrv.dev/third-party`,
2021-10-24 22:47:42 +01:00
);
2022-07-22 13:19:05 +01:00
console.log(` `);
2021-10-24 22:47:42 +01:00
console.log(
2022-07-22 13:19:05 +01:00
`\u001b[31m`,
`Invite URL:`,
2021-10-24 22:47:42 +01:00
`\u001b[36m`,
2022-07-22 13:19:05 +01:00
`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
);
2022-06-16 22:12:14 +01:00
2022-07-22 13:19:05 +01:00
console.log(` `);
console.log(`\u001b[32m`, `――――――――――――――――――――――――――――――――――――――――――――`);
2022-06-16 22:12:14 +01:00
2021-11-17 19:04:20 -06:00
const roles = [
2022-08-12 01:35:36 +01:00
supportbot.Roles.StaffMember.Admin,
supportbot.Roles.StaffMember.Staff,
supportbot.Roles.ModRoles.Blacklisted,
supportbot.Roles.ModRoles.Muted
2021-11-17 19:04:20 -06:00
];
2022-06-23 00:05:08 +01:00
2022-02-11 23:34:38 -06:00
supportbot.Departments.forEach((department) => roles.push(department.role));
2022-06-23 00:05:08 +01:00
2022-08-12 01:35:36 +01:00
if (supportbot.Roles.AutoRole.Role) roles.push(supportbot.Roles.AutoRole.Role);
// const channels = [
// supportbot.Suggestions.Channel,
// supportbot.Ticket.Log.TicketLog,
// supportbot.Ticket.Log.TranscriptLog,
// panelconfig.Channel,
// supportbot.Welcome.Channel,
// supportbot.Leave.Channel,
// supportbot.Translate.Log
// ];
2022-06-22 23:30:59 +01:00
//const categories = [supportbot.TicketCategory];
2021-11-17 19:04:20 -06:00
const missingC = [];
const missingR = [];
const missingCat = [];
2022-07-23 07:50:12 +01:00
2022-08-12 01:35:36 +01:00
// for (let c of channels) {
// if ((c === supportbot.Suggestion.Channel && cmdconfig.Suggestion.Enabled) || c === supportbot.Ticket.Log.TicketLog && supportbot.Ticket.Log.DisableTicketLogChannel) {
// continue;
// }
// const find = await getChannel(c, client.guilds.cache.first());
// if (!find) missingC.push(c);
// }
2021-11-17 19:04:20 -06:00
for (let r of roles) {
const find = await getRole(r, client.guilds.cache.first());
2021-11-17 19:04:20 -06:00
if (!find) missingR.push(r);
}
2022-06-22 23:30:59 +01: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(
2022-07-22 13:19:05 +01:00
"\u001b[31m",
`[MISSING CONFIGURATION]`,
2021-11-17 19:04:20 -06:00
"\u001b[33m",
2022-07-22 13:19:05 +01:00
`The following Roles could not be found in your server.\n`, `\u001b[31m`, `[${missingR.join(
2021-11-17 19:04:20 -06:00
", "
2022-07-22 13:19:05 +01:00
)}]`, `\n `,
2021-11-17 19:04:20 -06:00
);
}
if (missingC.length > 0) {
console.log(
2022-07-22 13:19:05 +01:00
"\u001b[31m",
`[MISSING CONFIGURATION]`,
2021-11-17 19:04:20 -06:00
"\u001b[33m",
2022-07-22 13:19:05 +01:00
`The following Channels could not be found in your server.\n`, `\u001b[31m`, `[${missingC.join(
2021-11-17 19:04:20 -06:00
", "
2022-07-22 13:19:05 +01:00
)}]`, `\n `
2021-11-17 19:04:20 -06:00
);
}
if (missingCat.length > 0) {
console.log(
2022-07-22 13:19:05 +01:00
"\u001b[31m",
`[MISSING CONFIGURATION]`,
"\u001b[33m",
2022-07-22 13:19:05 +01:00
`The following Categories could not be found in your server.\n`, `\u001b[31m`, `[${missingCat.join(
", "
2022-07-22 13:19:05 +01:00
)}]`, `\n `,
);
}
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(
2022-07-22 13:19:05 +01:00
"\u001b[31m",
`[TICKET PANEL]`,
2021-10-24 22:47:42 +01:00
"\u001b[33m",
2022-07-22 13:19:05 +01:00
"Ticket Panel is not setup, You can set this in", `\u001b[31m`, '/Configs/Ticket-Panel.yml', `\n `,
2021-10-24 22:47:42 +01:00
);
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
);
2022-02-11 23:34:38 -06:00
chan1.messages.fetch(panelid.TicketPanelID).catch(async () => {
2022-07-22 13:19:05 +01:00
let embed = new Discord.EmbedBuilder()
2022-02-11 23:47:06 -06:00
.setTitle(panelconfig.PanelTitle)
2022-06-28 03:14:54 +01:00
.setColor(panelconfig.PanelColour)
2022-02-25 21:55:33 -06:00
.setFooter({
2022-08-12 01:35:36 +01:00
text: supportbot.Embed.Footer,
2022-02-25 21:55:33 -06:00
iconURL: interaction.user.displayAvatarURL(),
});
2021-10-24 22:47:42 +01:00
if (panelconfig.TicketPanel_Description) {
embed.setDescription(panelconfig.PanelMessage);
}
if (panelconfig.TicketPanel_Thumbnail) {
embed.setThumbnail(panelconfig.PanelThumbnail);
}
if (panelconfig.TicketPanel_Image) {
embed.setImage(panelconfig.PanelImage);
}
2022-02-11 23:34:38 -06:00
let button;
2022-06-23 00:05:08 +01:00
2022-02-11 23:34:38 -06:00
button = supportbot.Departments.map((x) =>
2022-07-22 13:19:05 +01:00
new Discord.ButtonBuilder()
2022-02-11 23:34:38 -06:00
.setCustomId("department-" + supportbot.Departments.indexOf(x))
.setLabel(x.title)
.setStyle(x.color)
.setEmoji(x.emoji)
);
2022-06-23 00:05:08 +01:00
2022-07-22 13:19:05 +01:00
let row = new Discord.ActionRowBuilder().addComponents(button);
2021-10-24 22:47:42 +01:00
await chan1
.send({
embeds: [embed],
components: [row],
})
.then((r) => {
let data = {
2021-12-18 22:18:05 -06:00
id: panelid.id,
2022-02-11 23:47:06 -06:00
TicketPanelID: r.id,
2021-10-24 22:47:42 +01:00
};
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) => {
2022-02-04 17:55:02 -06:00
console.log("Raw: " + e);
2021-10-24 22:47:42 +01:00
});
});
}
2022-06-23 00:05:08 +01:00
});