JaBa/helpers/extenders.js

59 lines
2.1 KiB
JavaScript
Raw Normal View History

const { Message, BaseInteraction, User } = require("discord.js");
User.prototype.getUsername = function () {
return this.discriminator === "0" ? this.username : this.tag;
};
2022-01-04 02:18:28 +05:00
2022-11-09 21:48:41 +05:00
BaseInteraction.prototype.translate = function (key, args) {
2022-11-14 17:57:20 +05:00
const language = this.client.translations.get(this.guild ? (this.guild.data ? this.guild.data.language : "ru-RU") : "ru-RU");
if (!language) throw "Interaction: Invalid language set in data.";
2022-01-04 02:18:28 +05:00
return language(key, args);
};
2022-11-09 21:48:41 +05:00
BaseInteraction.prototype.replyT = function (key, args, options = {}) {
2022-11-14 17:57:20 +05:00
let string = this.translate(key, args);
if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`;
2022-01-04 02:18:28 +05:00
if (options.edit) return this.editReply({ content: string, ephemeral: options.ephemeral || false });
else return this.reply({ content: string, ephemeral: options.ephemeral || false });
2022-01-04 02:18:28 +05:00
};
BaseInteraction.prototype.success = function (key, args, options = {}) {
options.prefixEmoji = "success";
2022-01-04 02:18:28 +05:00
return this.replyT(key, args, options);
2022-01-04 02:18:28 +05:00
};
BaseInteraction.prototype.error = function (key, args, options = {}) {
options.prefixEmoji = "error";
2022-01-04 02:18:28 +05:00
return this.replyT(key, args, options);
2022-01-04 02:18:28 +05:00
};
Message.prototype.translate = function (key, args) {
const language = this.client.translations.get(this.guild ? this.guild.data.language : "ru-RU");
if (!language) throw "Message: Invalid language set in data.";
2022-01-04 02:18:28 +05:00
return language(key, args);
2022-01-04 02:18:28 +05:00
};
Message.prototype.replyT = function (key, args, options = {}) {
let string = this.translate(key, args, this.guild ? this.guild.data.language : "ru-RU");
if (options.prefixEmoji) string = `${this.client.customEmojis[options.prefixEmoji]} | ${string}`;
2022-10-03 20:27:51 +05:00
if (options.edit) return this.edit({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } });
else return this.reply({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } });
2022-01-04 02:18:28 +05:00
};
Message.prototype.success = function (key, args, options = {}) {
options.prefixEmoji = "success";
return this.replyT(key, args, options);
2022-01-04 02:18:28 +05:00
};
Message.prototype.error = function (key, args, options = {}) {
options.prefixEmoji = "error";
return this.replyT(key, args, options);
2022-01-04 02:18:28 +05:00
};