2024-04-30 11:40:52 +05:00
|
|
|
const { Message, BaseInteraction, User, GuildMember } = require("discord.js");
|
2023-07-03 14:25:25 +05:00
|
|
|
|
|
|
|
User.prototype.getUsername = function () {
|
|
|
|
return this.discriminator === "0" ? this.username : this.tag;
|
|
|
|
};
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2024-04-30 11:40:52 +05:00
|
|
|
GuildMember.prototype.getUsername = function () {
|
|
|
|
return this.user.discriminator === "0" ? this.user.username : this.user.tag;
|
|
|
|
};
|
|
|
|
|
2023-12-14 18:58:19 +05:00
|
|
|
BaseInteraction.prototype.getLocale = function () {
|
2024-04-30 11:40:52 +05:00
|
|
|
return this.data?.guild?.language;
|
2023-12-14 18:58:19 +05:00
|
|
|
};
|
|
|
|
|
2024-04-30 11:40:52 +05:00
|
|
|
BaseInteraction.prototype.translate = function (key, args, locale) {
|
|
|
|
const language = this.client.translations.get(this.getLocale() || locale || "en-US");
|
2023-11-04 23:06:51 +05:00
|
|
|
if (!language) throw "Interaction: Invalid language set in data.";
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2023-11-04 23:06:51 +05:00
|
|
|
return language(key, args);
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
|
|
|
|
2023-11-05 16:03:23 +05:00
|
|
|
BaseInteraction.prototype.replyT = async function (key, args, options = {}) {
|
2024-04-30 13:13:03 +05:00
|
|
|
const translated = this.translate(key, args, this.getLocale() || options.locale || "en-US");
|
2023-10-12 19:44:26 +05:00
|
|
|
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${translated}` : translated;
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2024-04-29 15:57:02 +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
|
|
|
};
|
|
|
|
|
2023-11-05 16:03:23 +05:00
|
|
|
BaseInteraction.prototype.success = async function (key, args, options = {}) {
|
2023-04-20 11:47:47 +05:00
|
|
|
options.prefixEmoji = "success";
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
return this.replyT(key, args, options);
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
|
|
|
|
2023-11-05 16:03:23 +05:00
|
|
|
BaseInteraction.prototype.error = async function (key, args, options = {}) {
|
2023-04-20 11:47:47 +05:00
|
|
|
options.prefixEmoji = "error";
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
return this.replyT(key, args, options);
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
Message.prototype.getLocale = function () {
|
2024-04-30 11:40:52 +05:00
|
|
|
return this.data?.guild?.language;
|
2024-02-09 23:26:57 +05:00
|
|
|
};
|
|
|
|
|
2024-04-30 11:40:52 +05:00
|
|
|
Message.prototype.translate = function (key, args, locale) {
|
|
|
|
const language = this.client.translations.get(this.getLocale() || locale || "en-US");
|
2023-11-04 23:06:51 +05:00
|
|
|
if (!language) throw "Message: Invalid language set in data.";
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2023-11-04 23:06:51 +05:00
|
|
|
return language(key, args);
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
|
|
|
|
2023-11-05 16:03:23 +05:00
|
|
|
Message.prototype.replyT = async function (key, args, options = {}) {
|
2024-04-30 13:13:03 +05:00
|
|
|
const translated = this.translate(key, args, this.getLocale() || options.locale || "en-US");
|
2023-10-12 19:44:26 +05:00
|
|
|
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${translated}` : translated;
|
2022-07-26 17:20:10 +05:00
|
|
|
|
2024-04-29 15:57:02 +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
|
|
|
};
|
|
|
|
|
2023-11-05 16:03:23 +05:00
|
|
|
Message.prototype.success = async function (key, args, options = {}) {
|
2023-04-20 11:47:47 +05:00
|
|
|
options.prefixEmoji = "success";
|
2022-07-26 17:20:10 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
return this.replyT(key, args, options);
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
|
|
|
|
2023-11-05 16:03:23 +05:00
|
|
|
Message.prototype.error = async function (key, args, options = {}) {
|
2023-04-20 11:47:47 +05:00
|
|
|
options.prefixEmoji = "error";
|
2022-07-26 17:20:10 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
return this.replyT(key, args, options);
|
2023-07-05 00:58:06 +05:00
|
|
|
};
|