🌐 locale support for gift module
This commit is contained in:
parent
2f76c7c7a7
commit
3421732618
1 changed files with 117 additions and 91 deletions
|
@ -18,6 +18,7 @@ import saveUser from "@helpers/saveUser";
|
||||||
// Models
|
// Models
|
||||||
import fetchUser from "@helpers/fetchUser";
|
import fetchUser from "@helpers/fetchUser";
|
||||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
import i18next from "i18next";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default {
|
export default {
|
||||||
|
@ -42,38 +43,52 @@ export default {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
execute: async (interaction: CommandInteraction) => {
|
execute: async (interaction: CommandInteraction) => {
|
||||||
const { options, user, guild, client } = interaction;
|
const { options, user, guild, client, locale } = interaction;
|
||||||
|
|
||||||
const optionUser = options?.getUser("user");
|
const optionUser = options.getUser("user");
|
||||||
const optionAmount = options?.getInteger("amount");
|
const optionAmount = options.getInteger("amount");
|
||||||
const optionReason = options?.getString("reason");
|
const optionReason = options.getString("reason");
|
||||||
|
|
||||||
|
const embed = new MessageEmbed()
|
||||||
|
.setTitle(
|
||||||
|
i18next.t("credits:modules:gift: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 (Gift)")
|
.setDescription(
|
||||||
.setDescription(`We can not find your guild!`)
|
i18next.t("guildOnly", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "errors",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optionUser === null) {
|
if (optionUser === 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 (Gift)")
|
.setDescription(
|
||||||
.setDescription(`We can not find your requested user!`)
|
i18next.t("userNotFound", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "errors",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -85,119 +100,126 @@ export default {
|
||||||
const toUserDB = await fetchUser(optionUser, guild);
|
const toUserDB = await fetchUser(optionUser, guild);
|
||||||
|
|
||||||
if (fromUserDB === null) {
|
if (fromUserDB === 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 (Gift)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`We can not find your requested from user in our database!`
|
i18next.t("userNotFound", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "errors",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(errorColor),
|
||||||
.setColor(errorColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toUserDB === null) {
|
if (toUserDB === 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 (Gift)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`We can not find your requested to user in our database!`
|
i18next.t("userNotFound", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "errors",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(errorColor),
|
||||||
.setColor(errorColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// If receiver is same as sender
|
// If receiver is same as sender
|
||||||
if (optionUser?.id === user?.id) {
|
if (optionUser.id === user.id) {
|
||||||
logger?.verbose(`User is same as sender`);
|
logger.verbose(`User is same as sender`);
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Gift)")
|
.setDescription(
|
||||||
.setDescription(`You can not pay yourself!`)
|
i18next.t("credits:modules:gift:error01:description", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "plugins",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// If amount is null
|
// If amount is null
|
||||||
if (optionAmount === null) {
|
if (optionAmount === null) {
|
||||||
logger?.verbose(`Amount is null`);
|
logger.verbose(`Amount is null`);
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Gift)")
|
.setDescription(
|
||||||
.setDescription(`We could not read your requested amount!`)
|
i18next.t("amountNotFound", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "errors",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// If amount is zero or below
|
// If amount is zero or below
|
||||||
if (optionAmount <= 0) {
|
if (optionAmount <= 0) {
|
||||||
logger?.verbose(`Amount is zero or below`);
|
logger.verbose(`Amount is zero or below`);
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Gift)")
|
.setDescription(
|
||||||
.setDescription(`You can't gift zero or below!`)
|
i18next.t("credits:modules:gift:error02:description", {
|
||||||
.setTimestamp(new Date())
|
lng: locale,
|
||||||
.setColor(errorColor)
|
ns: "plugins",
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// If user has below gifting amount
|
// If user has below gifting amount
|
||||||
if (fromUserDB?.credits < optionAmount) {
|
if (fromUserDB.credits < optionAmount) {
|
||||||
logger?.verbose(`User has below gifting amount`);
|
logger.verbose(`User has below gifting amount`);
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Gift)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`You have insufficient credits. Your balance is ${fromUserDB?.credits}!`
|
i18next.t("credits:modules:gift:error03:description", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "plugins",
|
||||||
|
amount: fromUserDB.credits,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(errorColor),
|
||||||
.setColor(errorColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// If toUserDB has no credits
|
// If toUserDB has no credits
|
||||||
if (toUserDB === null) {
|
if (toUserDB === 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 (Gift)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`We can not find your requested to user in our database!`
|
i18next.t("userNotFound", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "errors",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(errorColor),
|
||||||
.setColor(errorColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -209,46 +231,50 @@ export default {
|
||||||
toUserDB.credits += optionAmount;
|
toUserDB.credits += optionAmount;
|
||||||
|
|
||||||
// Save users
|
// Save users
|
||||||
await saveUser(fromUserDB, toUserDB)?.then(async () => {
|
await saveUser(fromUserDB, toUserDB).then(async () => {
|
||||||
// Get DM user object
|
// Get DM user object
|
||||||
const dmUser = client?.users?.cache?.get(optionUser?.id);
|
const dmUser = client.users.cache.get(optionUser.id);
|
||||||
|
|
||||||
|
if (dmUser == null) return;
|
||||||
|
|
||||||
// Send DM to user
|
// Send DM to user
|
||||||
await dmUser
|
await dmUser
|
||||||
?.send({
|
.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Gift)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`You have received ${optionAmount} credits from ${
|
i18next.t("credits:modules:gift:error03:description", {
|
||||||
user?.tag
|
lng: locale,
|
||||||
} with reason ${
|
ns: "plugins",
|
||||||
optionReason ? ` with reason: ${optionReason}` : ""
|
user: user.tag,
|
||||||
}!`
|
amount: optionAmount,
|
||||||
|
reason: optionReason || "unspecified",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(successColor),
|
||||||
.setColor(successColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.catch(async (error) =>
|
.catch(async (error) =>
|
||||||
logger?.error(`[Gift] Error sending DM to user: ${error}`)
|
logger.error(`[Gift] Error sending DM to user: ${error}`)
|
||||||
);
|
);
|
||||||
|
|
||||||
logger?.verbose(
|
logger.verbose(
|
||||||
`[Gift] Successfully gifted ${optionAmount} credits to ${optionUser?.tag}`
|
`[Gift] Successfully gifted ${optionAmount} credits to ${optionUser.tag}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Gift)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`Successfully gifted ${optionAmount} credits to ${optionUser?.tag}!`
|
i18next.t("credits:modules:gift:success02:description", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "plugins",
|
||||||
|
user: user,
|
||||||
|
amount: optionAmount,
|
||||||
|
reason: optionReason || "unspecified",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(successColor),
|
||||||
.setColor(successColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue