2021-12-10 21:39:54 +05:00
|
|
|
const Command = require("../../base/Command.js"),
|
|
|
|
Canvas = require("discord-canvas"),
|
|
|
|
Discord = require("discord.js");
|
|
|
|
|
|
|
|
class Fortnite extends Command {
|
2021-12-26 19:29:37 +05:00
|
|
|
constructor(client) {
|
2021-12-10 21:39:54 +05:00
|
|
|
super(client, {
|
|
|
|
name: "fortnite",
|
|
|
|
dirname: __dirname,
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: false,
|
2021-12-26 19:29:37 +05:00
|
|
|
aliases: ["fn"],
|
2021-12-10 21:39:54 +05:00
|
|
|
memberPermissions: [],
|
2021-12-26 19:29:37 +05:00
|
|
|
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
|
2021-12-10 21:39:54 +05:00
|
|
|
nsfw: false,
|
|
|
|
ownerOnly: false,
|
2021-12-22 17:32:50 +05:00
|
|
|
cooldown: 3000
|
2021-12-10 21:39:54 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-26 19:29:37 +05:00
|
|
|
async run(message, args, data) {
|
2021-12-10 21:39:54 +05:00
|
|
|
if (!data.config.apiKeys.fortniteTRN || data.config.apiKeys.fortniteTRN.length === "") return message.success("misc:COMMAND_DISABLED");
|
|
|
|
|
|
|
|
const stats = new Canvas.FortniteStats();
|
|
|
|
|
2021-12-18 20:03:59 +05:00
|
|
|
const platform = args[0].toLowerCase();
|
|
|
|
if (!platform || (platform !== "pc" && platform !== "xbl" && platform !== "psn")) return message.error("general/fortnite:MISSING_PLATFORM");
|
2021-12-10 21:39:54 +05:00
|
|
|
|
|
|
|
const user = args.slice(1).join(" ");
|
|
|
|
if (!user) return message.error("general/fortnite:MISSING_USERNAME");
|
|
|
|
|
2021-12-26 19:29:37 +05:00
|
|
|
const m = await message.sendT("misc:PLEASE_WAIT", null, {
|
|
|
|
prefixEmoji: "loading"
|
|
|
|
});
|
2021-12-10 21:39:54 +05:00
|
|
|
|
|
|
|
const statsImage = await stats
|
|
|
|
.setToken(data.config.apiKeys.fortniteTRN)
|
|
|
|
.setUser(user)
|
|
|
|
.setPlatform(platform)
|
|
|
|
.setText("averageKills", message.translate("general/fortnite:AVERAGE_KILLS"))
|
|
|
|
.setText("averageKill", message.translate("general/fortnite:AVERAGE_KILL"))
|
|
|
|
.setText("wPercent", message.translate("general/fortnite:W_PERCENT"))
|
|
|
|
.setText("winPercent", message.translate("general/fortnite:WIN_PERCENT"))
|
|
|
|
.setText("kD", message.translate("general/fortnite:KD"))
|
|
|
|
.setText("wins", message.translate("general/fortnite:WINS"))
|
|
|
|
.setText("win", message.translate("general/fortnite:WIN"))
|
|
|
|
.setText("kills", message.translate("general/fortnite:KILLS"))
|
|
|
|
.setText("kill", message.translate("general/fortnite:KILL"))
|
|
|
|
.setText("matches", message.translate("general/fortnite:MATCHES"))
|
|
|
|
.setText("match", message.translate("general/fortnite:MATCH"))
|
|
|
|
.setText("footer", message.translate("general/fortnite:FOOTER"))
|
|
|
|
.toAttachment();
|
|
|
|
|
|
|
|
if (!statsImage) {
|
|
|
|
m.delete();
|
2021-12-26 19:29:37 +05:00
|
|
|
return message.error("general/fortnite:NOT_FOUND", {
|
|
|
|
platform,
|
|
|
|
search: user
|
|
|
|
});
|
2021-12-10 21:39:54 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Send embed
|
|
|
|
const attachment = new Discord.MessageAttachment(statsImage.toBuffer(), "fortnite-stats-image.png"),
|
|
|
|
embed = new Discord.MessageEmbed()
|
2021-12-26 19:29:37 +05:00
|
|
|
.setDescription(message.translate("general/fortnite:TITLE", {
|
|
|
|
username: `[${stats.data.username}](${stats.data.url.replace(new RegExp(" ", "g"), "%20")})`
|
|
|
|
}))
|
|
|
|
.attachFiles(attachment)
|
|
|
|
.setImage("attachment://fortnite-stats-image.png")
|
|
|
|
.setColor(data.config.embed.color)
|
|
|
|
.setFooter(data.config.embed.footer);
|
2021-12-10 21:39:54 +05:00
|
|
|
message.channel.send(embed);
|
|
|
|
m.delete();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Fortnite;
|