🌐 locale support for top module
This commit is contained in:
parent
4fb241bc97
commit
2f76c7c7a7
1 changed files with 57 additions and 21 deletions
|
@ -1,48 +1,84 @@
|
||||||
// Dependencies
|
import {
|
||||||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
successColor,
|
||||||
|
errorColor,
|
||||||
|
footerText,
|
||||||
|
footerIcon,
|
||||||
|
} from "@config/embed";
|
||||||
|
|
||||||
|
import i18next from "i18next";
|
||||||
import { CommandInteraction, MessageEmbed } from "discord.js";
|
import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
import logger from "@logger";
|
||||||
|
|
||||||
import userSchema from "@schemas/user";
|
import userSchema, { IUser } from "@schemas/user";
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
import pluralize from "@helpers/pluralize";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: (command: SlashCommandSubcommandBuilder) => {
|
data: (command: SlashCommandSubcommandBuilder) => {
|
||||||
return command.setName("top").setDescription(`View the top users`);
|
return command.setName("top").setDescription(`View the top users`);
|
||||||
},
|
},
|
||||||
execute: async (interaction: CommandInteraction) => {
|
execute: async (interaction: CommandInteraction) => {
|
||||||
// Get all users in the guild
|
const { locale, guild } = interaction;
|
||||||
|
|
||||||
const usersDB = await userSchema.find({ guildId: interaction?.guild?.id });
|
const embed = new MessageEmbed()
|
||||||
|
.setTitle(
|
||||||
|
i18next.t("credits:modules:top:general:title", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "plugins",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setFooter({ text: footerText, iconURL: footerIcon });
|
||||||
|
|
||||||
|
if (guild === null) {
|
||||||
|
logger.verbose(`Guild is null`);
|
||||||
|
|
||||||
|
return interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
embed
|
||||||
|
.setDescription(
|
||||||
|
i18next.t("guildOnly", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "errors",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.setColor(errorColor),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const usersDB = await userSchema.find({ guildId: guild.id });
|
||||||
|
|
||||||
const topTen = usersDB
|
const topTen = usersDB
|
||||||
|
|
||||||
// Sort them after credits amount (ascending)
|
// Sort them after credits amount (ascending)
|
||||||
.sort((a, b) => (a?.credits > b?.credits ? -1 : 1))
|
.sort((a, b) => (a.credits > b.credits ? -1 : 1))
|
||||||
|
|
||||||
// Return the top 10
|
// Return the top 10
|
||||||
.slice(0, 10);
|
.slice(0, 10);
|
||||||
|
|
||||||
// Create entry object
|
// Create entry object
|
||||||
const entry = (x: any, index: number) =>
|
const entry = (x: IUser, index: number) =>
|
||||||
`${index + 1}. <@${x?.userId}> - ${pluralize(x?.credits, "credit")}`;
|
i18next.t("credits:modules:top:entry", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "plugins",
|
||||||
|
index: index + 1,
|
||||||
|
user: x.userId,
|
||||||
|
amount: x.credits,
|
||||||
|
});
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setTitle("[:dollar:] Credits (Top)")
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`Top 10 users with the most credits.
|
` ${i18next.t("credits:modules:top:success01:description", {
|
||||||
|
lng: locale,
|
||||||
|
ns: "plugins",
|
||||||
|
})}
|
||||||
|
|
||||||
${topTen.map(entry).join("\n")}`
|
${topTen.map(entry).join("\n")}
|
||||||
|
`
|
||||||
)
|
)
|
||||||
.setTimestamp(new Date())
|
.setColor(successColor),
|
||||||
.setColor(successColor)
|
|
||||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue