JaBa/helpers/fortniteShop.js

46 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Canvas = require("discord-canvas"),
CronJob = require("cron").CronJob,
Discord = require("discord.js");
async function init(client) {
2021-12-26 19:29:37 +05:00
new CronJob("0 0 12 * * *", async function () {
2021-12-10 21:39:54 +05:00
if (!client.config.apiKeys.fortniteFNBR || client.config.apiKeys.fortniteFNBR === "") return;
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
client.guilds.cache.forEach(async (guild) => {
2021-12-26 19:29:37 +05:00
const guildData = await client.findOrCreateGuild({
id: guild.id
});
2021-12-10 21:39:54 +05:00
if (guildData.plugins.fortniteshop) {
const fnChannel = client.channels.cache.get(guildData.plugins.fortniteshop);
if (fnChannel) {
const momentName = client.languages.find((language) => language.name === guildData.language || language.aliases.includes(guildData.language)).moment;
const image = await new Canvas.FortniteShop()
.setToken(client.config.apiKeys.fortniteFNBR)
.setText("header", client.translate("general/fortniteshop:HEADER").replace("{{date}}", "{date}"), null, guildData.language)
.setText("daily", client.translate("general/fortniteshop:DAILY"), null, guildData.language)
.setText("featured", client.translate("general/fortniteshop:FEATURED"), null, guildData.language)
.setText("date", client.translate("general/fortniteshop:DATE", {
skipInterpolation: true
}, null, guildData.language).replace("{{date}}", "{date}"))
.setText("footer", client.translate("general/fortniteshop:FOOTER"), null, guildData.language)
.lang(momentName)
.toAttachment();
const attachment = new Discord.MessageAttachment(image, "shop.png");
const embed = new Discord.MessageEmbed()
2022-01-03 23:20:33 +05:00
.setAuthor({ name: client.translate("general/fortniteshop:DATE", {
2021-12-10 21:39:54 +05:00
date: client.printDate(new Date(Date.now()), null, guildData.language)
2022-01-03 23:20:33 +05:00
}, guildData.language), iconURL: client.user.displayAvatarURL()})
2021-12-10 21:39:54 +05:00
.setImage("attachment://shop.png")
.setColor(client.config.embed.color)
2022-01-03 23:20:33 +05:00
.setFooter({ text: client.config.embed.footer });
const msg = await fnChannel.send({ embeds: [embed] });
2021-12-10 21:39:54 +05:00
await msg.react("😍");
await msg.react("😐");
await msg.react("😭");
};
};
});
}, null, true, "Europe/Moscow");
};
module.exports = { init };