diff --git a/src/database/schemas/guild.ts b/src/database/schemas/guild.ts index 792596b..849845b 100644 --- a/src/database/schemas/guild.ts +++ b/src/database/schemas/guild.ts @@ -65,7 +65,7 @@ const guildSchema = new Schema( roles: { status: { type: Boolean, - default: true, + default: false, }, pricePerHour: { type: Number, diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 51f5573..029568a 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -4,7 +4,7 @@ import modules from "@events/messageCreate/modules"; export default { name: "messageCreate", async execute(message: Message) { - await modules.counters.execute(message); + await modules.credits.execute(message); await modules.points.execute(message); await modules.counters.execute(message); }, diff --git a/src/plugins/settings/guild/index.ts b/src/plugins/settings/guild/index.ts index f9e8939..37218bd 100644 --- a/src/plugins/settings/guild/index.ts +++ b/src/plugins/settings/guild/index.ts @@ -13,6 +13,7 @@ import credits from "./modules/credits"; import points from "./modules/points"; import welcome from "./modules/welcome"; import audits from "./modules/audits"; +import shop from "./modules/shop"; import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; // Function @@ -25,7 +26,8 @@ export default { .addSubcommand(credits.data) .addSubcommand(points.data) .addSubcommand(welcome.data) - .addSubcommand(audits.data); + .addSubcommand(audits.data) + .addSubcommand(shop.data); }, execute: async (interaction: CommandInteraction) => { // Destructure member @@ -81,6 +83,12 @@ export default { return audits.execute(interaction); } + if (options?.getSubcommand() === "shop") { + logger?.verbose(`Executing shop subcommand`); + + return shop.execute(interaction); + } + logger?.verbose(`No subcommand found`); }, }; diff --git a/src/plugins/settings/guild/modules/shop.ts b/src/plugins/settings/guild/modules/shop.ts new file mode 100644 index 0000000..5c633a0 --- /dev/null +++ b/src/plugins/settings/guild/modules/shop.ts @@ -0,0 +1,89 @@ +// Dependencies +import { CommandInteraction } from "discord.js"; + +// Configurations +import { successColor, footerText, footerIcon } from "@config/embed"; + +// Handlers +import logger from "@logger"; + +// Models +import guildSchema from "@schemas/guild"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import { ChannelType } from "discord-api-types/v10"; + +// Function +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("shop") + .setDescription("Shop") + .addBooleanOption((option) => + option + .setName("roles-status") + .setDescription("Should roles be enabled?") + ) + .addNumberOption((option) => + option + .setName("roles-price-per-hour") + .setDescription("Price per hour for roles.") + ); + }, + execute: async (interaction: CommandInteraction) => { + // Destructure member + const { options, guild } = interaction; + + // Get options + const rolesStatus = options?.getBoolean("roles-status"); + const rolesPricePerHour = options?.getNumber("roles-price-per-hour"); + + // Get guild object + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) { + return logger?.verbose(`Guild not found in database.`); + } + + // Modify values + guildDB.shop.roles.status = + rolesStatus !== null ? rolesStatus : guildDB?.shop?.roles?.status; + guildDB.shop.roles.pricePerHour = + rolesPricePerHour !== null + ? rolesPricePerHour + : guildDB?.shop?.roles?.pricePerHour; + + // Save guild + await guildDB?.save()?.then(async () => { + logger?.verbose(`Guild shop updated.`); + + return interaction?.editReply({ + embeds: [ + { + title: ":hammer: Settings - Guild [Shop]", + description: `Shop settings updated.`, + color: successColor, + fields: [ + { + name: "🤖 Roles Status", + value: `${guildDB?.shop?.roles.status}`, + inline: true, + }, + { + name: "🌊 Roles Price Per Hour", + value: `${guildDB?.shop?.roles.pricePerHour}`, + inline: true, + }, + ], + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + }); + }); + }, +}; diff --git a/src/plugins/shop/roles/index.ts b/src/plugins/shop/roles/index.ts index 7672f51..96ae1ca 100644 --- a/src/plugins/shop/roles/index.ts +++ b/src/plugins/shop/roles/index.ts @@ -5,10 +5,14 @@ import { CommandInteraction } from "discord.js"; // Handlers import logger from "../../../logger"; +import { errorColor, footerText, footerIcon } from "@config/embed"; + // Modules import buy from "./modules/buy"; import cancel from "./modules/cancel"; +import guildSchema from "@schemas/guild"; + // Function export default { data: (group: SlashCommandSubcommandGroupBuilder) => { @@ -19,7 +23,32 @@ export default { .addSubcommand(cancel.data); }, execute: async (interaction: CommandInteraction) => { - const { options } = interaction; + const { options, guild } = interaction; + + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) return; + + if (!guildDB.shop.roles.status) { + logger.verbose(`Shop roles disabled.`); + + return interaction?.editReply({ + embeds: [ + { + title: ":dollar: Shop - Roles", + description: "This server has disabled shop roles.", + color: errorColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + }); + } if (options?.getSubcommand() === "buy") { logger.verbose(`Executing buy subcommand`);