🌐 locale support for balance module
This commit is contained in:
parent
3421732618
commit
9963438e31
1 changed files with 67 additions and 58 deletions
|
@ -1,10 +1,3 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
|
||||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
|
||||||
|
|
||||||
import logger from "@logger";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import {
|
import {
|
||||||
errorColor,
|
errorColor,
|
||||||
successColor,
|
successColor,
|
||||||
|
@ -12,41 +5,52 @@ import {
|
||||||
footerIcon,
|
footerIcon,
|
||||||
} from "@config/embed";
|
} from "@config/embed";
|
||||||
|
|
||||||
// Helpers
|
import i18next from "i18next";
|
||||||
import pluralize from "@helpers/pluralize";
|
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
import logger from "@logger";
|
||||||
|
|
||||||
import fetchUser from "@helpers/fetchUser";
|
import fetchUser from "@helpers/fetchUser";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: (command: SlashCommandSubcommandBuilder) => {
|
data: (command: SlashCommandSubcommandBuilder) => {
|
||||||
return (
|
return command
|
||||||
command
|
|
||||||
.setName("balance")
|
.setName("balance")
|
||||||
.setDescription(`View a user's balance`)
|
.setDescription(`View a user's balance`)
|
||||||
|
|
||||||
// User
|
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("user")
|
.setName("user")
|
||||||
.setDescription(`The user whose balance you want to view`)
|
.setDescription(`The user whose balance you want to view`)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
execute: async (interaction: CommandInteraction) => {
|
execute: async (interaction: CommandInteraction) => {
|
||||||
const { options, user, guild } = interaction;
|
const { options, user, guild, locale } = interaction;
|
||||||
|
|
||||||
const discordUser = options?.getUser("user");
|
const discordUser = options.getUser("user");
|
||||||
|
|
||||||
|
const embed = new MessageEmbed()
|
||||||
|
.setTitle(
|
||||||
|
i18next.t("credits:modules:balance:general:title", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "plugins",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||||
|
|
||||||
if (guild === null) {
|
if (guild === null) {
|
||||||
logger?.verbose(`Guild is null`);
|
logger.verbose(`Guild is null`);
|
||||||
|
|
||||||
return interaction?.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Balance)")
|
.setDescription(
|
||||||
.setDescription(`You can only use this command in a guild!`)
|
i18next.t("guildOnly", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "errors",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -54,50 +58,55 @@ export default {
|
||||||
const userObj = await fetchUser(discordUser || user, guild);
|
const userObj = await fetchUser(discordUser || user, guild);
|
||||||
|
|
||||||
if (userObj === null) {
|
if (userObj === null) {
|
||||||
logger?.verbose(`User not found`);
|
logger.verbose(`User not found`);
|
||||||
|
|
||||||
return interaction?.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Balance)")
|
.setDescription(
|
||||||
.setDescription(`Could not find user ${discordUser || user}`)
|
i18next.t("userNotFound", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "errors",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
user: discordUser || user,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userObj.credits === null) {
|
if (userObj.credits === null) {
|
||||||
logger?.verbose(`User has no credits`);
|
logger.verbose(`User has no credits`);
|
||||||
|
|
||||||
return interaction?.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Balance)")
|
.setDescription(
|
||||||
.setDescription(`${discordUser || user} has no credits!`)
|
i18next.t("credits:modules:balance:error01:description", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "plugins",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
user: discordUser || user,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger?.verbose(`Found user ${discordUser || user}`);
|
logger.verbose(`Found user ${discordUser || user}`);
|
||||||
|
|
||||||
return interaction?.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Balance)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${discordUser || user} has ${pluralize(
|
i18next.t("credits:modules:balance:success01:description", {
|
||||||
userObj.credits,
|
lng: locale,
|
||||||
`credit`
|
ns: "plugins",
|
||||||
)}!`
|
user: discordUser || user,
|
||||||
|
amount: userObj.credits,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(successColor),
|
||||||
.setColor(successColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue