From 6aa2f22294cb7eaf25155fb97ddc4d22dda42c35 Mon Sep 17 00:00:00 2001 From: Xiled Emerald Date: Sun, 24 Oct 2021 22:47:42 +0100 Subject: [PATCH] Create ready.js --- Events/ready.js | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Events/ready.js diff --git a/Events/ready.js b/Events/ready.js new file mode 100644 index 0000000..872e412 --- /dev/null +++ b/Events/ready.js @@ -0,0 +1,126 @@ +// SupportBot | Emerald Services +// Ready Event + +const fs = require("fs"); + +const Discord = require("discord.js"); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const panelconfig = yaml.load( + fs.readFileSync("./Data/ticket-panel.yml", "utf8") +); + +const Event = require("../Structures/Event.js"); + +module.exports = new Event("ready", (client) => { + 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` + ); + console.log( + `\u001b[33m`, + `Resources:`, + `\u001b[36m`, + `https://emeraldsrv.dev/resources` + ); + console.log( + `\u001b[33m`, + `Documentation:`, + `\u001b[36m`, + `https://supportbot.emeraldsrv.dev` + ); + 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`, `――――――――――――――――――――――――――――――――――――――――――――`); + + if (panelconfig.TicketPanel) { + let chan1 = client.channels.cache.find( + (channel) => channel.name === panelconfig.Channel + ); + + if (!chan1) { + console.log( + "\u001b[33m", + "[WARN] Ticket reaction panel is not setup, You can do so via the configuration file!" + ); + return false; + } + + const panelid = yaml.load( + fs.readFileSync("./Data/ticket-panel-id.yml", "utf8") + ); + + 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") + .setStyle(panelconfig.ButtonColour); + + let row = new Discord.MessageActionRow().addComponents(button); + + await chan1 + .send({ + embeds: [embed], + components: [row], + }) + .then((r) => { + let data = { + TicketPanelID: `${r.id}`, + }; + let yamlStr = yaml.dump(data); + fs.writeFileSync("./Data/ticket-panel-id.yml", yamlStr, "utf8"); + }) + .catch((e) => { + console.log("Raw" + e); + }); + }); + } +});