bugly.js
Version:
Bugly.js helps beginners and time-pressed people!
78 lines (62 loc) • 2.44 kB
JavaScript
const { EmbedBuilder } = require("discord.js");
const { Log } = require("./log.js");
const lg = new Log();
const colorMap = {
"green": 0x008000,
"red": 0xFF0000,
"blue": 0x0000FF,
"yellow": 0xFFFF00,
"purple": 0x800080,
"orange": 0xFFA500,
"pink": 0xFFC0CB,
"black": 0x000000,
"white": 0xFFFFFF
};
class Embed {
constructor() {
this.interaction = null;
this.description = '';
this.color = '#FFFFFF';
}
setInteraction(interaction) {
if (typeof (interaction) !== "object") {
return lg.error("Please enter a valid interaction object in your embedded message.");
};
this.interaction = interaction;
return this;
}
setDescription(description) {
if (typeof (description) !== "string") {
return lg.error("Please enter a description in a valid font in your embedded message.")
};
this.description = description;
return this;
}
setColor(color) {
if (typeof color === 'string') {
if (colorMap[color.toLowerCase()]) {
this.color = colorMap[color.toLowerCase()];
} else {
this.color = 0xFFFFFF;
lg.warning("The color code you wrote in your embedded message is invalid, so white is selected by default.");
};
} else {
this.color = color;
};
return this;
}
build() {
if (!this.interaction) return lg.error("You have to give your embedded message an interaction!");
if (!this.description) return lg.error("You have to give an explanation for your embedded message!");
if (!this.color) return lg.error("You have to give a color to your embedded message!");
const date = new Date();
const year = date.getUTCFullYear().toString();
const embed = new EmbedBuilder()
.setAuthor({ name: `@${this.interaction.user.username}`, iconURL: this.interaction.user.displayAvatarURL() })
.setDescription(this.description.toString())
.setColor(this.color)
.setFooter({ text: `Telif Hakkı ${this.interaction.client.username} © ${year} | Tüm hakları saklıdır.`, iconURL: this.interaction.client.displayAvatarURL() });
return embed;
}
}
module.exports = { Embed }