🌐 counters & credits & manage localization

This commit is contained in:
Axel Olausson Holtenäs 2022-04-22 19:07:08 +02:00
parent 112def7c53
commit a8af4582ad
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA
5 changed files with 148 additions and 62 deletions

View file

@ -22,12 +22,17 @@ export default async (interaction: CommandInteraction) => {
let meta;
const subcommand =
interaction.options.getSubcommand() === "delete"
? "delete_"
: interaction.options.getSubcommand();
if (!interaction.options.getSubcommandGroup(false)) {
meta = currentCommand.modules[interaction.options.getSubcommand()].meta;
meta = currentCommand.modules[subcommand].meta;
} else {
meta =
currentCommand.groups[interaction.options.getSubcommandGroup()].modules[
interaction.options.getSubcommand()
subcommand
].meta;
}
@ -100,7 +105,7 @@ export default async (interaction: CommandInteraction) => {
);
})
.catch(async (error: any) => {
logger?.error(error);
logger?.error(`${error}`);
return interaction.editReply({
embeds: [

View file

@ -10,6 +10,7 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { ChannelType } from "discord-api-types/v10";
import counterSchema from "@schemas/counter";
import i18next from "i18next";
export default {
meta: { guildOnly: true, ephemeral: false },
@ -30,10 +31,23 @@ export default {
},
execute: async (interaction: CommandInteraction) => {
const { options, guild } = interaction;
const { options, guild, locale } = interaction;
const discordChannel = options?.getChannel("channel");
const embed = new MessageEmbed()
.setTitle(
i18next.t("counters:modules:view:general:title", {
lng: locale,
ns: "plugins",
})
)
.setTimestamp(new Date())
.setFooter({
text: footerText,
iconURL: footerIcon,
});
const counter = await counterSchema?.findOne({
guildId: guild?.id,
channelId: discordChannel?.id,
@ -42,32 +56,31 @@ export default {
if (counter === null) {
return interaction?.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:1234:] Counters (View)")
.setDescription(`No counter found for channel ${discordChannel}!`)
.setTimestamp(new Date())
.setColor(errorColor)
.setFooter({
text: footerText,
iconURL: footerIcon,
}),
embed
.setDescription(
i18next.t("counters:modules:view:error01:description", {
lng: locale,
ns: "plugins",
channel: discordChannel,
})
)
.setColor(errorColor),
],
});
}
return interaction?.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:1234:] Counters (View)")
embed
.setDescription(
`Viewing counter for channel ${discordChannel} with count ${counter.counter}.`
i18next.t("counters:modules:view:success01:description", {
lng: locale,
ns: "plugins",
channel: discordChannel,
amount: counter.counter,
})
)
.setTimestamp(new Date())
.setColor(successColor)
.setFooter({
text: footerText,
iconURL: footerIcon,
}),
.setColor(successColor),
],
});
},

View file

@ -4,7 +4,12 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import Chance from "chance";
// Configurations
import { successColor, footerText, footerIcon } from "@config/embed";
import {
successColor,
errorColor,
footerText,
footerIcon,
} from "@config/embed";
// Handlers
import logger from "@logger";
@ -15,6 +20,7 @@ import timeoutSchema from "@schemas/timeout";
// Helpers
import fetchUser from "@helpers/fetchUser";
import fetchGuild from "@helpers/fetchGuild";
import i18next from "i18next";
export default {
meta: { guildOnly: true, ephemeral: true },
@ -24,7 +30,20 @@ export default {
},
execute: async (interaction: CommandInteraction) => {
// Destructure member
const { guild, user } = interaction;
const { guild, user, locale } = interaction;
const embed = new MessageEmbed()
.setTitle(
i18next.t("credits:modules:work:general:title", {
lng: locale,
ns: "plugins",
})
)
.setTimestamp(new Date())
.setFooter({
text: footerText,
iconURL: footerIcon,
});
// Chance module
const chance = new Chance();
@ -48,14 +67,15 @@ export default {
return interaction.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:dollar:] Credits (Work)")
embed
.setDescription(
`You can not work while on timeout, please wait ${guildDB?.credits.workTimeout} seconds.`
i18next.t("credits:modules:work:error01:description", {
lng: locale,
ns: "plugins",
time: guildDB?.credits.workTimeout,
})
)
.setTimestamp(new Date())
.setColor(successColor)
.setFooter({ text: footerText, iconURL: footerIcon }),
.setColor(errorColor),
],
});
}
@ -80,12 +100,16 @@ export default {
return interaction.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:dollar:] Credits (Work)")
.setDescription(`You worked and earned ${creditsEarned} credits`)
.setTimestamp(new Date())
.setColor(successColor)
.setFooter({ text: footerText, iconURL: footerIcon }),
embed
.setDescription(
i18next.t("credits:modules:work:success01:description", {
lng: locale,
ns: "plugins",
time: guildDB?.credits.workTimeout,
amount: creditsEarned,
})
)
.setColor(successColor),
],
});
});

View file

@ -16,6 +16,7 @@ import logger from "@logger";
// Models
import counterSchema from "@schemas/counter";
import i18next from "i18next";
// Function
export default {
@ -49,12 +50,22 @@ export default {
);
},
execute: async (interaction: CommandInteraction) => {
const { options, guild } = interaction;
const { options, guild, locale } = interaction;
const discordChannel = options?.getChannel("channel");
const countingWord = options?.getString("word");
const startValue = options?.getNumber("start");
const embed = new MessageEmbed()
.setTitle(
i18next.t("manage:groups:counters:modules:create:general:title", {
lng: locale,
ns: "plugins",
})
)
.setTimestamp(new Date())
.setFooter({ text: footerText, iconURL: footerIcon });
const counter = await counterSchema?.findOne({
guildId: guild?.id,
channelId: discordChannel?.id,
@ -63,12 +74,18 @@ export default {
if (counter) {
return interaction?.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:toolbox:] Manage - Counters (Create)")
.setDescription(`A counter already exists for this channel.`)
.setTimestamp(new Date())
.setColor(errorColor)
.setFooter({ text: footerText, iconURL: footerIcon }),
embed
.setDescription(
i18next.t(
"manage:groups:counters:modules:create:error01:description",
{
lng: locale,
ns: "plugins",
channel: discordChannel,
}
)
)
.setColor(errorColor),
],
});
}
@ -85,12 +102,18 @@ export default {
return interaction?.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:toolbox:] Manage - Counters (Create)")
.setDescription(`Created counter for ${discordChannel}`)
.setTimestamp(new Date())
.setColor(successColor)
.setFooter({ text: footerText, iconURL: footerIcon }),
embed
.setDescription(
i18next.t(
"manage:groups:counters:modules:create:success01:description",
{
lng: locale,
ns: "plugins",
channel: discordChannel,
}
)
)
.setColor(successColor),
],
});
});

View file

@ -16,6 +16,7 @@ import logger from "@logger";
import counterSchema from "@schemas/counter";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { ChannelType } from "discord-api-types/v10";
import i18next from "i18next";
// Function
export default {
@ -38,10 +39,20 @@ export default {
);
},
execute: async (interaction: CommandInteraction) => {
const { options, guild } = interaction;
const { options, guild, locale } = interaction;
const discordChannel = options?.getChannel("channel");
const embed = new MessageEmbed()
.setTitle(
i18next.t("manage:groups:counters:modules:delete:general:title", {
lng: locale,
ns: "plugins",
})
)
.setTimestamp(new Date())
.setFooter({ text: footerText, iconURL: footerIcon });
const counter = await counterSchema?.findOne({
guildId: guild?.id,
channelId: discordChannel?.id,
@ -52,12 +63,17 @@ export default {
return interaction?.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:toolbox:] Manage - Counters (Delete)")
.setDescription(`The counter for this channel does not exist.`)
.setTimestamp(new Date())
.setColor(errorColor)
.setFooter({ text: footerText, iconURL: footerIcon }),
embed
.setDescription(
i18next.t(
"manage:groups:counters:modules:delete:error01:description",
{
lng: locale,
ns: "plugins",
}
)
)
.setColor(errorColor),
],
});
}
@ -72,12 +88,17 @@ export default {
return interaction?.editReply({
embeds: [
new MessageEmbed()
.setTitle("[:toolbox:] Manage - Counters (Delete)")
.setDescription(`The counter for this channel has been deleted.`)
.setTimestamp(new Date())
.setColor(successColor)
.setFooter({ text: footerText, iconURL: footerIcon }),
embed
.setDescription(
i18next.t(
"manage:groups:counters:modules:delete:success01:description",
{
lng: locale,
ns: "plugins",
}
)
)
.setColor(successColor),
],
});
})