JaBa/helpers/extenders.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const { Guild, Message, MessageEmbed } = require("discord.js");
const config = require("../config");
2021-12-26 19:29:37 +05:00
Guild.prototype.translate = function (key, args) {
2021-12-10 21:39:54 +05:00
const language = this.client.translations.get(this.data.language);
if (!language) throw "Message: Invalid language set in data.";
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
return language(key, args);
};
2021-12-26 19:29:37 +05:00
Message.prototype.translate = function (key, args) {
2021-12-16 23:42:58 +05:00
const language = this.client.translations.get(this.guild ? this.guild.data.language : "ru-RU");
2021-12-10 21:39:54 +05:00
if (!language) throw "Message: Invalid language set in data.";
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
return language(key, args);
};
// Wrapper for sendT with error emoji
2021-12-26 19:29:37 +05:00
Message.prototype.error = function (key, args, options = {}) {
2021-12-10 21:39:54 +05:00
options.prefixEmoji = "error";
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
return this.sendT(key, args, options);
};
// Wrapper for sendT with success emoji
2021-12-26 19:29:37 +05:00
Message.prototype.success = function (key, args, options = {}) {
2021-12-10 21:39:54 +05:00
options.prefixEmoji = "success";
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
return this.sendT(key, args, options);
};
// Translate and send the message
2021-12-26 19:29:37 +05:00
Message.prototype.sendT = function (key, args, options = {}) {
2021-12-10 21:39:54 +05:00
let string = this.translate(key, args);
if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`;
2021-12-16 23:42:58 +05:00
if (options.edit) return this.edit(string);
else return this.channel.send(string);
2021-12-10 21:39:54 +05:00
};
// Format a date
2021-12-26 19:29:37 +05:00
Message.prototype.printDate = function (date, format) {
2021-12-10 21:39:54 +05:00
return this.client.printDate(date, format, this.guild.data.language);
};
// Convert time
2021-12-26 19:29:37 +05:00
Message.prototype.convertTime = function (time, type, noPrefix) {
2021-12-10 21:39:54 +05:00
return this.client.convertTime(time, type, noPrefix, (this.guild && this.guild.data) ? this.guild.data.language : null);
};
2021-12-26 19:29:37 +05:00
MessageEmbed.prototype.errorColor = function () {
2021-12-10 21:39:54 +05:00
this.setColor("#FF0000");
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
return this;
};
2021-12-26 19:29:37 +05:00
MessageEmbed.prototype.successColor = function () {
2021-12-10 21:39:54 +05:00
this.setColor("#32CD32");
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
return this;
};
2021-12-26 19:29:37 +05:00
MessageEmbed.prototype.defaultColor = function () {
2021-12-10 21:39:54 +05:00
this.setColor(config.color);
2021-12-16 23:42:58 +05:00
2021-12-10 21:39:54 +05:00
return this;
};