From a3ac4ca7fab4dcad726a3b55ce4f8e090a489014 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 15:45:56 +0200 Subject: [PATCH 01/23] =?UTF-8?q?=F0=9F=9A=A7=20Moving=20guard=20classes?= =?UTF-8?q?=20out=20of=20metadata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handlers/command/index.ts | 30 +++++++++---------- src/helpers/checkPermission/index.ts | 12 ++++++++ 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 src/helpers/checkPermission/index.ts diff --git a/src/events/interactionCreate/handlers/command/index.ts b/src/events/interactionCreate/handlers/command/index.ts index db90796..2f726e9 100644 --- a/src/events/interactionCreate/handlers/command/index.ts +++ b/src/events/interactionCreate/handlers/command/index.ts @@ -1,7 +1,5 @@ // Dependencies import { ChatInputCommandInteraction } from "discord.js"; -import { command as CooldownCommand } from "../../../../handlers/cooldown"; -import deferReply from "../../../../handlers/deferReply"; import getCommandMetadata from "../../../../helpers/getCommandMetadata"; export default async (interaction: ChatInputCommandInteraction) => { @@ -12,23 +10,23 @@ export default async (interaction: ChatInputCommandInteraction) => { if (!currentCommand) throw new Error(`Unknown command ${commandName}`); const metadata = await getCommandMetadata(interaction, currentCommand); - await deferReply(interaction, metadata.ephemeral || false); + // await deferReply(interaction, metadata.ephemeral || false); - if (metadata.guildOnly && !interaction.guild) - throw new Error("This command is guild only."); + // if (metadata.guildOnly && !interaction.guild) + // throw new Error("This command is guild only."); - if ( - metadata.permissions && - metadata.guildOnly && - !interaction.memberPermissions?.has(metadata.permissions) - ) - throw new Error("You don't have the required permissions"); + // if (metadata.dmOnly && interaction.guild) + // throw new Error("This command is only available in DM"); - if (metadata.dmOnly && interaction.guild) - throw new Error("This command is only available in DM"); + // if ( + // metadata.permissions && + // metadata.guildOnly && + // !interaction.memberPermissions?.has(metadata.permissions) + // ) + // throw new Error("You don't have the required permissions"); - if (metadata.cooldown) { - await CooldownCommand(interaction, metadata.cooldown); - } + // if (metadata.cooldown) { + // await CooldownCommand(interaction, metadata.cooldown); + // } await currentCommand.execute(interaction); }; diff --git a/src/helpers/checkPermission/index.ts b/src/helpers/checkPermission/index.ts new file mode 100644 index 0000000..2de1162 --- /dev/null +++ b/src/helpers/checkPermission/index.ts @@ -0,0 +1,12 @@ +import { BaseInteraction, PermissionResolvable } from "discord.js"; + +export default async ( + interaction: BaseInteraction, + permission: PermissionResolvable +) => { + if (!interaction.memberPermissions) + throw new Error("Could not check user for permissions"); + + if (!interaction.memberPermissions.has(permission)) + throw new Error("Permission denied"); +}; From ab7043d75f10cd64246b19937747713b8ff9bccc Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 15:49:11 +0200 Subject: [PATCH 02/23] =?UTF-8?q?=F0=9F=97=91=EF=B8=8F=20deprecate=20modul?= =?UTF-8?q?eData=20and=20metadata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/interactionCreate/handlers/command/index.ts | 3 +-- src/handlers/command/index.ts | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/events/interactionCreate/handlers/command/index.ts b/src/events/interactionCreate/handlers/command/index.ts index 2f726e9..0e79da8 100644 --- a/src/events/interactionCreate/handlers/command/index.ts +++ b/src/events/interactionCreate/handlers/command/index.ts @@ -1,6 +1,5 @@ // Dependencies import { ChatInputCommandInteraction } from "discord.js"; -import getCommandMetadata from "../../../../helpers/getCommandMetadata"; export default async (interaction: ChatInputCommandInteraction) => { if (!interaction.isCommand()) return; @@ -9,7 +8,7 @@ export default async (interaction: ChatInputCommandInteraction) => { const currentCommand = client.commands.get(commandName); if (!currentCommand) throw new Error(`Unknown command ${commandName}`); - const metadata = await getCommandMetadata(interaction, currentCommand); + // const metadata = await getCommandMetadata(interaction, currentCommand); // await deferReply(interaction, metadata.ephemeral || false); // if (metadata.guildOnly && !interaction.guild) diff --git a/src/handlers/command/index.ts b/src/handlers/command/index.ts index 865c349..09d05e2 100644 --- a/src/handlers/command/index.ts +++ b/src/handlers/command/index.ts @@ -21,10 +21,6 @@ export const register = async (client: Client) => { throw new Error( `📦 No command builder found while importing "${commandName}"` ); - if (!command.moduleData) - throw new Error( - `📦 No command moduleData found while importing "${commandName}"` - ); // Add command to collection client.commands.set(command.builder.name, command); From 9d2bd0c848a8e16037d3dafe5852c8c805e8afba Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:07:25 +0200 Subject: [PATCH 03/23] =?UTF-8?q?=F0=9F=8E=A8=20Config=20Command=20is=20no?= =?UTF-8?q?w=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/config/index.ts | 60 +++++++++++--------- src/commands/config/modules/audits/index.ts | 14 ++--- src/commands/config/modules/cpgg/index.ts | 12 ++-- src/commands/config/modules/credits/index.ts | 12 ++-- src/commands/config/modules/embeds/index.ts | 12 ++-- src/commands/config/modules/index.ts | 9 --- src/commands/config/modules/points/index.ts | 12 ++-- src/commands/config/modules/shop/index.ts | 12 ++-- src/commands/config/modules/welcome/index.ts | 12 ++-- 9 files changed, 77 insertions(+), 78 deletions(-) delete mode 100644 src/commands/config/modules/index.ts diff --git a/src/commands/config/index.ts b/src/commands/config/index.ts index 783219b..cbaa582 100644 --- a/src/commands/config/index.ts +++ b/src/commands/config/index.ts @@ -1,43 +1,51 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; -import modules from "./modules"; + +// Modules +import moduleAudits from "./modules/audits"; +import moduleCpgg from "./modules/cpgg"; +import moduleCredits from "./modules/credits"; +import moduleEmbeds from "./modules/embeds"; +import modulePoints from "./modules/points"; +import moduleShop from "./modules/shop"; +import moduleWelcome from "./modules/welcome"; export const builder = new SlashCommandBuilder() .setName("config") .setDescription("Manage guild configurations.") + .setDMPermission(false) - .addSubcommand(modules.cpgg.builder) - .addSubcommand(modules.credits.builder) - .addSubcommand(modules.points.builder) - .addSubcommand(modules.welcome.builder) - .addSubcommand(modules.audits.builder) - .addSubcommand(modules.shop.builder) - .addSubcommand(modules.embeds.builder); - -export const moduleData = modules; + // Modules + .addSubcommand(moduleAudits.builder) + .addSubcommand(moduleCpgg.builder) + .addSubcommand(moduleCredits.builder) + .addSubcommand(moduleEmbeds.builder) + .addSubcommand(modulePoints.builder) + .addSubcommand(moduleShop.builder) + .addSubcommand(moduleWelcome.builder); export const execute = async (interaction: ChatInputCommandInteraction) => { - switch (interaction.options?.getSubcommand()) { + switch (interaction.options.getSubcommand()) { + case "audits": + await moduleAudits.execute(interaction); + break; case "cpgg": - await modules.cpgg.execute(interaction); + await moduleCpgg.execute(interaction); break; case "credits": - await modules.credits.execute(interaction); - break; - case "points": - await modules.points.execute(interaction); - break; - case "welcome": - await modules.welcome.execute(interaction); - break; - case "audits": - await modules.audits.execute(interaction); - break; - case "shop": - await modules.shop.execute(interaction); + await moduleCredits.execute(interaction); break; case "embeds": - await modules.embeds.execute(interaction); + await moduleEmbeds.execute(interaction); + break; + case "points": + await modulePoints.execute(interaction); + break; + case "shop": + await moduleShop.execute(interaction); + break; + case "welcome": + await moduleWelcome.execute(interaction); break; default: throw new Error("No module found for that specific command."); diff --git a/src/commands/config/modules/audits/index.ts b/src/commands/config/modules/audits/index.ts index 3a6dd1f..a3d4c00 100644 --- a/src/commands/config/modules/audits/index.ts +++ b/src/commands/config/modules/audits/index.ts @@ -1,21 +1,17 @@ -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; import { ChatInputCommandInteraction, EmbedBuilder, PermissionsBitField, + SlashCommandSubcommandBuilder, } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("audits") @@ -35,6 +31,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { guild, options } = interaction; const { successColor, footerText, footerIcon } = await getEmbedConfig( guild diff --git a/src/commands/config/modules/cpgg/index.ts b/src/commands/config/modules/cpgg/index.ts index 01d13ed..b9ce119 100644 --- a/src/commands/config/modules/cpgg/index.ts +++ b/src/commands/config/modules/cpgg/index.ts @@ -5,17 +5,13 @@ import { PermissionsBitField, } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; import encryption from "../../../../helpers/encryption"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("cpgg") @@ -44,6 +40,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/config/modules/credits/index.ts b/src/commands/config/modules/credits/index.ts index 4d25feb..e76cd77 100644 --- a/src/commands/config/modules/credits/index.ts +++ b/src/commands/config/modules/credits/index.ts @@ -5,16 +5,12 @@ import { PermissionsBitField, } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("credits") @@ -57,6 +53,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/config/modules/embeds/index.ts b/src/commands/config/modules/embeds/index.ts index 3ec6661..a9e1ae9 100644 --- a/src/commands/config/modules/embeds/index.ts +++ b/src/commands/config/modules/embeds/index.ts @@ -5,15 +5,11 @@ import { } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; import getValues from "./components/getValues"; export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("embeds") @@ -50,6 +46,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { guild } = interaction; if (!guild) throw new Error("Guild not found"); diff --git a/src/commands/config/modules/index.ts b/src/commands/config/modules/index.ts deleted file mode 100644 index 7d8ba77..0000000 --- a/src/commands/config/modules/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import audits from "./audits"; -import cpgg from "./cpgg"; -import credits from "./credits"; -import embeds from "./embeds"; -import points from "./points"; -import shop from "./shop"; -import welcome from "./welcome"; - -export default { audits, credits, points, cpgg, shop, welcome, embeds }; diff --git a/src/commands/config/modules/points/index.ts b/src/commands/config/modules/points/index.ts index fc67d3b..7f89c8a 100644 --- a/src/commands/config/modules/points/index.ts +++ b/src/commands/config/modules/points/index.ts @@ -5,16 +5,12 @@ import { PermissionsBitField, } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("points") @@ -45,6 +41,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/config/modules/shop/index.ts b/src/commands/config/modules/shop/index.ts index 2d605d6..fd23ac1 100644 --- a/src/commands/config/modules/shop/index.ts +++ b/src/commands/config/modules/shop/index.ts @@ -5,16 +5,12 @@ import { PermissionsBitField, } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("shop") @@ -33,6 +29,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/config/modules/welcome/index.ts b/src/commands/config/modules/welcome/index.ts index fd604a1..259a63f 100644 --- a/src/commands/config/modules/welcome/index.ts +++ b/src/commands/config/modules/welcome/index.ts @@ -6,16 +6,12 @@ import { PermissionsBitField, } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("welcome") @@ -56,6 +52,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); From dd5ed64e1aae826bb42860fb6004df0a3db8da30 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:15:44 +0200 Subject: [PATCH 04/23] =?UTF-8?q?=F0=9F=8E=A8=20Counters=20Command=20is=20?= =?UTF-8?q?now=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/counters/index.ts | 17 +++++++++++------ src/commands/counters/modules/index.ts | 3 --- src/commands/counters/modules/view/index.ts | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 src/commands/counters/modules/index.ts diff --git a/src/commands/counters/index.ts b/src/commands/counters/index.ts index e70e460..edb73e2 100644 --- a/src/commands/counters/index.ts +++ b/src/commands/counters/index.ts @@ -1,18 +1,23 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; -import modules from "./modules"; +// Modules +import moduleView from "./modules/view"; export const builder = new SlashCommandBuilder() .setName("counters") .setDescription("View guild counters") + .setDMPermission(false) - .addSubcommand(modules.view.builder); - -export const moduleData = modules; + // Modules + .addSubcommand(moduleView.builder); export const execute = async (interaction: ChatInputCommandInteraction) => { - if (interaction.options.getSubcommand() === "view") { - await modules.view.execute(interaction); + switch (interaction.options.getSubcommand()) { + case "view": + await moduleView.execute(interaction); + break; + default: + throw new Error("No module found for that command."); } }; diff --git a/src/commands/counters/modules/index.ts b/src/commands/counters/modules/index.ts deleted file mode 100644 index dc539f8..0000000 --- a/src/commands/counters/modules/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import view from "./view"; - -export default { view }; diff --git a/src/commands/counters/modules/view/index.ts b/src/commands/counters/modules/view/index.ts index dd8e510..76611f8 100644 --- a/src/commands/counters/modules/view/index.ts +++ b/src/commands/counters/modules/view/index.ts @@ -2,11 +2,10 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; import { ChatInputCommandInteraction, EmbedBuilder } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; export default { - metadata: { guildOnly: true, ephemeral: false }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("view") @@ -23,6 +22,8 @@ export default { }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, false); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); From be500e7f3424d6104f98a101d96671727c894e20 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:15:49 +0200 Subject: [PATCH 05/23] =?UTF-8?q?=F0=9F=8E=A8=20Credits=20Command=20is=20n?= =?UTF-8?q?ow=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/credits/index.ts | 26 +++++++++++-------- src/commands/credits/modules/balance/index.ts | 4 ++- src/commands/credits/modules/gift/index.ts | 5 ++-- src/commands/credits/modules/index.ts | 6 ----- src/commands/credits/modules/top/index.ts | 3 +++ src/commands/credits/modules/work/index.ts | 5 ++-- 6 files changed, 27 insertions(+), 22 deletions(-) delete mode 100644 src/commands/credits/modules/index.ts diff --git a/src/commands/credits/index.ts b/src/commands/credits/index.ts index ad0f771..a1aaad6 100644 --- a/src/commands/credits/index.ts +++ b/src/commands/credits/index.ts @@ -2,34 +2,38 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; import logger from "../../middlewares/logger"; -import modules from "./modules"; +// Modules +import moduleBalance from "./modules/balance"; +import moduleGift from "./modules/gift"; +import moduleTop from "./modules/top"; +import moduleWork from "./modules/work"; export const builder = new SlashCommandBuilder() .setName("credits") .setDescription("Manage your credits.") + .setDMPermission(false) - .addSubcommand(modules.balance.builder) - .addSubcommand(modules.gift.builder) - .addSubcommand(modules.top.builder) - .addSubcommand(modules.work.builder); - -export const moduleData = modules; + // Modules + .addSubcommand(moduleBalance.builder) + .addSubcommand(moduleGift.builder) + .addSubcommand(moduleTop.builder) + .addSubcommand(moduleWork.builder); export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; switch (options.getSubcommand()) { case "balance": - await modules.balance.execute(interaction); + await moduleBalance.execute(interaction); break; case "gift": - await modules.gift.execute(interaction); + await moduleGift.execute(interaction); break; case "top": - await modules.top.execute(interaction); + await moduleTop.execute(interaction); break; case "work": - await modules.work.execute(interaction); + await moduleWork.execute(interaction); break; default: logger.silly(`Unknown subcommand ${options.getSubcommand()}`); diff --git a/src/commands/credits/modules/balance/index.ts b/src/commands/credits/modules/balance/index.ts index a360c8e..9034f63 100644 --- a/src/commands/credits/modules/balance/index.ts +++ b/src/commands/credits/modules/balance/index.ts @@ -1,11 +1,11 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { CommandInteraction, EmbedBuilder } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { guildOnly: true, ephemeral: true }, builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("balance") @@ -17,6 +17,8 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, true); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, user, guild } = interaction; diff --git a/src/commands/credits/modules/gift/index.ts b/src/commands/credits/modules/gift/index.ts index 4c2e541..db3435c 100644 --- a/src/commands/credits/modules/gift/index.ts +++ b/src/commands/credits/modules/gift/index.ts @@ -7,13 +7,12 @@ import { } from "discord.js"; import transferCredits from "../../../../helpers/transferCredits"; // Configurations +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; // Handlers // Function export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("gift") @@ -35,6 +34,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/credits/modules/index.ts b/src/commands/credits/modules/index.ts deleted file mode 100644 index 20edcaf..0000000 --- a/src/commands/credits/modules/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import balance from "./balance"; -import gift from "./gift"; -import top from "./top"; -import work from "./work"; - -export default { balance, gift, top, work }; diff --git a/src/commands/credits/modules/top/index.ts b/src/commands/credits/modules/top/index.ts index 7162744..075c599 100644 --- a/src/commands/credits/modules/top/index.ts +++ b/src/commands/credits/modules/top/index.ts @@ -2,6 +2,7 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { GuildMember } from "@prisma/client"; import { CommandInteraction, EmbedBuilder } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; @@ -12,6 +13,8 @@ export default { return command.setName("top").setDescription(`View the top users`); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, false); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { guild } = interaction; diff --git a/src/commands/credits/modules/work/index.ts b/src/commands/credits/modules/work/index.ts index 1a5407b..939ee06 100644 --- a/src/commands/credits/modules/work/index.ts +++ b/src/commands/credits/modules/work/index.ts @@ -9,15 +9,16 @@ import getEmbedConfig from "../../../../helpers/getEmbedData"; // Helpers // Handlers import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; import logger from "../../../../middlewares/logger"; export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("work").setDescription(`Work to earn credits`); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, true); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); // Destructure member From f5c988b77bdeda9bf03aa99136a2680ab50dcc02 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:18:00 +0200 Subject: [PATCH 06/23] =?UTF-8?q?=F0=9F=8E=A8=20DNS=20Commands=20is=20now?= =?UTF-8?q?=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/dns/index.ts | 9 +++++---- src/commands/dns/modules/index.ts | 3 --- src/commands/dns/modules/lookup/index.ts | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 src/commands/dns/modules/index.ts diff --git a/src/commands/dns/index.ts b/src/commands/dns/index.ts index 551814b..cd5f9ec 100644 --- a/src/commands/dns/index.ts +++ b/src/commands/dns/index.ts @@ -1,20 +1,21 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; -import modules from "./modules"; -export const moduleData = modules; +// Modules +import moduleLookup from "./modules/lookup"; export const builder = new SlashCommandBuilder() .setName("dns") .setDescription("DNS commands.") - .addSubcommand(modules.lookup.builder); + // Modules + .addSubcommand(moduleLookup.builder); // Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "lookup": - await modules.lookup.execute(interaction); + await moduleLookup.execute(interaction); break; default: throw new Error( diff --git a/src/commands/dns/modules/index.ts b/src/commands/dns/modules/index.ts deleted file mode 100644 index 92a80ac..0000000 --- a/src/commands/dns/modules/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import lookup from "./lookup"; - -export default { lookup }; diff --git a/src/commands/dns/modules/lookup/index.ts b/src/commands/dns/modules/lookup/index.ts index afa51a6..b64c18f 100644 --- a/src/commands/dns/modules/lookup/index.ts +++ b/src/commands/dns/modules/lookup/index.ts @@ -1,11 +1,10 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import axios from "axios"; import { ChatInputCommandInteraction, EmbedBuilder } from "discord.js"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; export default { - metadata: { guildOnly: false, ephemeral: false }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("lookup") @@ -20,6 +19,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, false); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const embedTitle = "[:hammer:] Utility (Lookup)"; From cb19e0f788155c2157b86b608cfffb6b402bce3c Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:33:31 +0200 Subject: [PATCH 07/23] =?UTF-8?q?=F0=9F=8E=A8=20Fun=20Command=20is=20now?= =?UTF-8?q?=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/fun/index.ts | 9 ++++----- src/commands/fun/modules/index.ts | 5 ----- src/commands/fun/modules/meme/index.ts | 8 ++++++-- 3 files changed, 10 insertions(+), 12 deletions(-) delete mode 100644 src/commands/fun/modules/index.ts diff --git a/src/commands/fun/index.ts b/src/commands/fun/index.ts index 8c166f0..e010d5d 100644 --- a/src/commands/fun/index.ts +++ b/src/commands/fun/index.ts @@ -2,21 +2,20 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; import logger from "../../middlewares/logger"; -import modules from "./modules"; +// Modules +import moduleMeme from "./modules/meme"; export const builder = new SlashCommandBuilder() .setName("fun") .setDescription("Fun commands.") - .addSubcommand(modules.meme.builder); - -export const moduleData = modules; + .addSubcommand(moduleMeme.builder); export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; if (options.getSubcommand() === "meme") { - await modules.meme.execute(interaction); + await moduleMeme.execute(interaction); } else { logger.silly(`Unknown subcommand ${options.getSubcommand()}`); } diff --git a/src/commands/fun/modules/index.ts b/src/commands/fun/modules/index.ts deleted file mode 100644 index 53aeddc..0000000 --- a/src/commands/fun/modules/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import meme from "./meme"; - -export default { - meme, -}; diff --git a/src/commands/fun/modules/meme/index.ts b/src/commands/fun/modules/meme/index.ts index b5c3db3..1ed1ea0 100644 --- a/src/commands/fun/modules/meme/index.ts +++ b/src/commands/fun/modules/meme/index.ts @@ -1,16 +1,20 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import axios from "axios"; import { CommandInteraction, EmbedBuilder } from "discord.js"; +import { command as CooldownCommand } from "../../../../handlers/cooldown"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; export default { - metadata: { guildOnly: false, ephemeral: false, cooldown: 15 }, - builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("meme").setDescription("Get a meme from r/memes)"); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, false); + + await CooldownCommand(interaction, 15); + const { guild } = interaction; const embedConfig = await getEmbedConfig(guild); From 4606392189108a00811e6c690d24db80a55f43d9 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:33:49 +0200 Subject: [PATCH 08/23] =?UTF-8?q?=F0=9F=8E=A8=20Manage=20Command=20is=20no?= =?UTF-8?q?w=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/manage/index.ts | 18 ++--- src/commands/manage/modules/counters/index.ts | 55 +++++++------- .../modules/counters/modules/add/index.ts | 12 ++-- .../manage/modules/counters/modules/index.ts | 4 -- .../modules/counters/modules/remove/index.ts | 12 ++-- src/commands/manage/modules/credits/index.ts | 71 ++++++++++--------- .../modules/credits/modules/give/index.ts | 12 ++-- .../modules/credits/modules/giveaway/index.ts | 12 ++-- .../manage/modules/credits/modules/index.ts | 7 -- .../modules/credits/modules/set/index.ts | 12 ++-- .../modules/credits/modules/take/index.ts | 12 ++-- .../modules/credits/modules/transfer/index.ts | 13 ++-- src/commands/manage/modules/index.ts | 4 -- 13 files changed, 116 insertions(+), 128 deletions(-) delete mode 100644 src/commands/manage/modules/counters/modules/index.ts delete mode 100644 src/commands/manage/modules/credits/modules/index.ts delete mode 100644 src/commands/manage/modules/index.ts diff --git a/src/commands/manage/index.ts b/src/commands/manage/index.ts index d488bd1..0062de7 100644 --- a/src/commands/manage/index.ts +++ b/src/commands/manage/index.ts @@ -2,17 +2,19 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; -// Groups -import modules from "./modules"; - -export const moduleData = modules; +// Modules +import moduleCounters from "./modules/counters"; +import moduleCredits from "./modules/credits"; // Function export const builder = new SlashCommandBuilder() .setName("manage") .setDescription("Manage the bot.") - .addSubcommandGroup(modules.counters.builder) - .addSubcommandGroup(modules.credits.builder); + .setDMPermission(false) + + // Modules + .addSubcommandGroup(moduleCounters.builder) + .addSubcommandGroup(moduleCredits.builder); export const execute = async (interaction: ChatInputCommandInteraction) => { // Destructure @@ -20,11 +22,11 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { switch (options.getSubcommandGroup()) { case "credits": { - await modules.credits.execute(interaction); + await moduleCredits.execute(interaction); break; } case "counters": { - await modules.counters.execute(interaction); + await moduleCounters.execute(interaction); break; } default: { diff --git a/src/commands/manage/modules/counters/index.ts b/src/commands/manage/modules/counters/index.ts index 941d672..7412a09 100644 --- a/src/commands/manage/modules/counters/index.ts +++ b/src/commands/manage/modules/counters/index.ts @@ -3,35 +3,32 @@ import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; // Modules -import modules from "./modules"; +import moduleAdd from "./modules/add"; +import moduleRemove from "./modules/remove"; -// Function -export const moduleData = modules; +export default { + builder: (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("counters") + .setDescription("Manage guild counters.") + .addSubcommand(moduleAdd.builder) + .addSubcommand(moduleRemove.builder); + }, + execute: async (interaction: ChatInputCommandInteraction) => { + const { options } = interaction; -// Create a discord builder -export const builder = (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("counters") - .setDescription("Manage guild counters.") - .addSubcommand(modules.add.builder) - .addSubcommand(modules.remove.builder); -}; - -// Execute the command -export const execute = async (interaction: ChatInputCommandInteraction) => { - const { options } = interaction; - - switch (options.getSubcommand()) { - case "add": { - await modules.add.execute(interaction); - break; - } - case "remove": { - await modules.remove.execute(interaction); - break; - } - default: { - throw new Error("Could not found a module for that command."); - } - } + switch (options.getSubcommand()) { + case "add": { + await moduleAdd.execute(interaction); + break; + } + case "remove": { + await moduleRemove.execute(interaction); + break; + } + default: { + throw new Error("Could not found a module for that command."); + } + } + }, }; diff --git a/src/commands/manage/modules/counters/modules/add/index.ts b/src/commands/manage/modules/counters/modules/add/index.ts index 403a234..13399bc 100644 --- a/src/commands/manage/modules/counters/modules/add/index.ts +++ b/src/commands/manage/modules/counters/modules/add/index.ts @@ -6,6 +6,8 @@ import { EmbedBuilder, PermissionsBitField, } from "discord.js"; +import deferReply from "../../../../../../handlers/deferReply"; +import checkPermission from "../../../../../../helpers/checkPermission"; // Configurations import prisma from "../../../../../../handlers/database"; import getEmbedConfig from "../../../../../../helpers/getEmbedData"; @@ -13,12 +15,6 @@ import logger from "../../../../../../middlewares/logger"; // Function export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("add") @@ -43,6 +39,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/manage/modules/counters/modules/index.ts b/src/commands/manage/modules/counters/modules/index.ts deleted file mode 100644 index bc9da9c..0000000 --- a/src/commands/manage/modules/counters/modules/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import add from "./add"; -import remove from "./remove"; - -export default { add, remove }; diff --git a/src/commands/manage/modules/counters/modules/remove/index.ts b/src/commands/manage/modules/counters/modules/remove/index.ts index 74caae3..dff0ec8 100644 --- a/src/commands/manage/modules/counters/modules/remove/index.ts +++ b/src/commands/manage/modules/counters/modules/remove/index.ts @@ -7,18 +7,14 @@ import { EmbedBuilder, PermissionsBitField, } from "discord.js"; +import deferReply from "../../../../../../handlers/deferReply"; +import checkPermission from "../../../../../../helpers/checkPermission"; // Configurations import prisma from "../../../../../../handlers/database"; import getEmbedConfig from "../../../../../../helpers/getEmbedData"; // Function export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("remove") @@ -32,6 +28,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/manage/modules/credits/index.ts b/src/commands/manage/modules/credits/index.ts index bf6f578..681cc24 100644 --- a/src/commands/manage/modules/credits/index.ts +++ b/src/commands/manage/modules/credits/index.ts @@ -1,38 +1,43 @@ import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; -import modules from "./modules"; -export const moduleData = modules; +// Modules +import moduleGive from "./modules/give"; +import moduleGiveaway from "./modules/giveaway"; +import moduleSet from "./modules/set"; +import moduleTake from "./modules/take"; +import moduleTransfer from "./modules/transfer"; -export const builder = (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("credits") - .setDescription("Manage the credits of a user.") - .addSubcommand(modules.give.builder) - .addSubcommand(modules.set.builder) - .addSubcommand(modules.take.builder) - .addSubcommand(modules.transfer.builder) - .addSubcommand(modules.giveaway.builder); -}; - -export const execute = async (interaction: ChatInputCommandInteraction) => { - switch (interaction.options.getSubcommand()) { - case "give": - await modules.give.execute(interaction); - break; - case "set": - await modules.set.execute(interaction); - break; - case "take": - await modules.take.execute(interaction); - break; - case "transfer": - await modules.transfer.execute(interaction); - break; - case "giveaway": - await modules.giveaway.execute(interaction); - break; - default: - throw new Error("No module found for that specific command"); - } +export default { + builder: (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("credits") + .setDescription("Manage the credits of a user.") + .addSubcommand(moduleGive.builder) + .addSubcommand(moduleSet.builder) + .addSubcommand(moduleTake.builder) + .addSubcommand(moduleTransfer.builder) + .addSubcommand(moduleGiveaway.builder); + }, + execute: async (interaction: ChatInputCommandInteraction) => { + switch (interaction.options.getSubcommand()) { + case "give": + await moduleGive.execute(interaction); + break; + case "set": + await moduleSet.execute(interaction); + break; + case "take": + await moduleTake.execute(interaction); + break; + case "transfer": + await moduleTransfer.execute(interaction); + break; + case "giveaway": + await moduleGiveaway.execute(interaction); + break; + default: + throw new Error("No module found for that specific command"); + } + }, }; diff --git a/src/commands/manage/modules/credits/modules/give/index.ts b/src/commands/manage/modules/credits/modules/give/index.ts index 3235c7e..28d7eeb 100644 --- a/src/commands/manage/modules/credits/modules/give/index.ts +++ b/src/commands/manage/modules/credits/modules/give/index.ts @@ -13,14 +13,10 @@ import pluralize from "../../../../../../helpers/pluralize"; // Models // Handlers import prisma from "../../../../../../handlers/database"; +import deferReply from "../../../../../../handlers/deferReply"; +import checkPermission from "../../../../../../helpers/checkPermission"; // Function export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("give") @@ -39,6 +35,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); // Destructure diff --git a/src/commands/manage/modules/credits/modules/giveaway/index.ts b/src/commands/manage/modules/credits/modules/giveaway/index.ts index db3beb5..3c2ea05 100644 --- a/src/commands/manage/modules/credits/modules/giveaway/index.ts +++ b/src/commands/manage/modules/credits/modules/giveaway/index.ts @@ -13,17 +13,13 @@ import { v4 as uuidv4 } from "uuid"; import encryption from "../../../../../../helpers/encryption"; // Configurations import prisma from "../../../../../../handlers/database"; +import deferReply from "../../../../../../handlers/deferReply"; +import checkPermission from "../../../../../../helpers/checkPermission"; import getEmbedConfig from "../../../../../../helpers/getEmbedData"; import logger from "../../../../../../middlewares/logger"; // Function export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("giveaway") @@ -49,6 +45,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); // Destructure diff --git a/src/commands/manage/modules/credits/modules/index.ts b/src/commands/manage/modules/credits/modules/index.ts deleted file mode 100644 index c82650d..0000000 --- a/src/commands/manage/modules/credits/modules/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import give from "./give"; -import giveaway from "./giveaway"; -import set from "./set"; -import take from "./take"; -import transfer from "./transfer"; - -export default { give, set, take, transfer, giveaway }; diff --git a/src/commands/manage/modules/credits/modules/set/index.ts b/src/commands/manage/modules/credits/modules/set/index.ts index efb700e..e8fe3cc 100644 --- a/src/commands/manage/modules/credits/modules/set/index.ts +++ b/src/commands/manage/modules/credits/modules/set/index.ts @@ -11,16 +11,12 @@ import { import getEmbedConfig from "../../../../../../helpers/getEmbedData"; // Handlers import prisma from "../../../../../../handlers/database"; +import deferReply from "../../../../../../handlers/deferReply"; +import checkPermission from "../../../../../../helpers/checkPermission"; import logger from "../../../../../../middlewares/logger"; // Function export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("set") @@ -39,6 +35,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild } = interaction; diff --git a/src/commands/manage/modules/credits/modules/take/index.ts b/src/commands/manage/modules/credits/modules/take/index.ts index 9f70b1e..8f55ad3 100644 --- a/src/commands/manage/modules/credits/modules/take/index.ts +++ b/src/commands/manage/modules/credits/modules/take/index.ts @@ -12,16 +12,12 @@ import getEmbedConfig from "../../../../../../helpers/getEmbedData"; import pluralize from "../../../../../../helpers/pluralize"; // Handlers import prisma from "../../../../../../handlers/database"; +import deferReply from "../../../../../../handlers/deferReply"; +import checkPermission from "../../../../../../helpers/checkPermission"; import logger from "../../../../../../middlewares/logger"; // Function export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("take") @@ -40,6 +36,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); // Destructure const { guild, options } = interaction; diff --git a/src/commands/manage/modules/credits/modules/transfer/index.ts b/src/commands/manage/modules/credits/modules/transfer/index.ts index 4a8bd40..488ae70 100644 --- a/src/commands/manage/modules/credits/modules/transfer/index.ts +++ b/src/commands/manage/modules/credits/modules/transfer/index.ts @@ -8,17 +8,12 @@ import { } from "discord.js"; import transferCredits from "../../../../../../helpers/transferCredits"; // Configurations +import deferReply from "../../../../../../handlers/deferReply"; +import checkPermission from "../../../../../../helpers/checkPermission"; import getEmbedConfig from "../../../../../../helpers/getEmbedData"; -// Handlers../../../../../../../helpers/userData // Function export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [PermissionsBitField.Flags.ManageGuild], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("transfer") @@ -43,6 +38,10 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + + await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); // Destructure member const { guild, options } = interaction; diff --git a/src/commands/manage/modules/index.ts b/src/commands/manage/modules/index.ts deleted file mode 100644 index c55982f..0000000 --- a/src/commands/manage/modules/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import * as counters from "./counters"; -import * as credits from "./credits"; - -export default { counters, credits }; From db9c05c2e96d35ae6ab4b01822a3da1086148878 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:35:18 +0200 Subject: [PATCH 09/23] =?UTF-8?q?=F0=9F=8E=A8=20Moderation=20Command=20is?= =?UTF-8?q?=20now=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/moderation/index.ts | 9 +++++---- src/commands/moderation/modules/index.ts | 3 --- src/commands/moderation/modules/prune/index.ts | 15 +++++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) delete mode 100644 src/commands/moderation/modules/index.ts diff --git a/src/commands/moderation/index.ts b/src/commands/moderation/index.ts index e74193e..cfc9e20 100644 --- a/src/commands/moderation/index.ts +++ b/src/commands/moderation/index.ts @@ -1,20 +1,21 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; -import modules from "./modules"; -export const moduleData = modules; +// Modules +import modulePrune from "./modules/prune"; export const builder = new SlashCommandBuilder() .setName("moderation") .setDescription("Moderation.") + .setDMPermission(false) - .addSubcommand(modules.prune.builder); + .addSubcommand(modulePrune.builder); // Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "prune": { - await modules.prune.execute(interaction); + await modulePrune.execute(interaction); break; } default: { diff --git a/src/commands/moderation/modules/index.ts b/src/commands/moderation/modules/index.ts deleted file mode 100644 index e7dd532..0000000 --- a/src/commands/moderation/modules/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import prune from "./prune"; - -export default { prune }; diff --git a/src/commands/moderation/modules/prune/index.ts b/src/commands/moderation/modules/prune/index.ts index 80251b9..0245a33 100644 --- a/src/commands/moderation/modules/prune/index.ts +++ b/src/commands/moderation/modules/prune/index.ts @@ -6,17 +6,13 @@ import { EmbedBuilder, PermissionsBitField, } from "discord.js"; +import deferReply from "../../../../handlers/deferReply"; +import checkPermission from "../../../../helpers/checkPermission"; // Configurations import getEmbedConfig from "../../../../helpers/getEmbedData"; // Function export default { - metadata: { - guildOnly: true, - ephemeral: false, - permissions: [PermissionsBitField.Flags.ManageMessages], - }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("prune") @@ -32,6 +28,13 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, false); + + await checkPermission( + interaction, + PermissionsBitField.Flags.ManageMessages + ); + const { errorColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); From 6589ac3ba3cbf34f5d9c7ef242cc4134795fffb2 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:38:43 +0200 Subject: [PATCH 10/23] =?UTF-8?q?=F0=9F=8E=A8=20Reputation=20Command=20is?= =?UTF-8?q?=20now=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/reputation/index.ts | 18 +++++++++--------- src/commands/reputation/modules/give/index.ts | 5 +++-- src/commands/reputation/modules/index.ts | 4 ---- src/commands/reputation/modules/view/index.ts | 5 +++-- 4 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 src/commands/reputation/modules/index.ts diff --git a/src/commands/reputation/index.ts b/src/commands/reputation/index.ts index 1f1511a..d339cb2 100644 --- a/src/commands/reputation/index.ts +++ b/src/commands/reputation/index.ts @@ -3,26 +3,26 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; // Modules -import modules from "./modules"; - -// Handlers - -export const moduleData = modules; +import moduleGive from "./modules/give"; +import moduleView from "./modules/view"; // Function export const builder = new SlashCommandBuilder() .setName("reputation") .setDescription("Manage reputation.") - .addSubcommand(modules.give.builder) - .addSubcommand(modules.view.builder); + .setDMPermission(false) + + // Modules + .addSubcommand(moduleGive.builder) + .addSubcommand(moduleView.builder); export const execute = async (interaction: ChatInputCommandInteraction) => { if (interaction.options.getSubcommand() === "give") { - await modules.give.execute(interaction); + await moduleGive.execute(interaction); return; } if (interaction.options.getSubcommand() === "view") { - await modules.view.execute(interaction); + await moduleView.execute(interaction); return; } }; diff --git a/src/commands/reputation/modules/give/index.ts b/src/commands/reputation/modules/give/index.ts index 6f8c438..7adf7be 100644 --- a/src/commands/reputation/modules/give/index.ts +++ b/src/commands/reputation/modules/give/index.ts @@ -6,10 +6,9 @@ import logger from "../../../../middlewares/logger"; import noSelfReputation from "./components/noSelfReputation"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("give") @@ -35,6 +34,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + const { options, user, guild } = interaction; const { successColor, footerText, footerIcon } = await getEmbedConfig( diff --git a/src/commands/reputation/modules/index.ts b/src/commands/reputation/modules/index.ts deleted file mode 100644 index 9e1c2a8..0000000 --- a/src/commands/reputation/modules/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import give from "./give"; -import view from "./view"; - -export default { give, view }; diff --git a/src/commands/reputation/modules/view/index.ts b/src/commands/reputation/modules/view/index.ts index c4ccc41..0722cf3 100644 --- a/src/commands/reputation/modules/view/index.ts +++ b/src/commands/reputation/modules/view/index.ts @@ -1,12 +1,11 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction, EmbedBuilder } from "discord.js"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("view") @@ -19,6 +18,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + const { options, user, guild } = interaction; const { successColor, footerText, footerIcon } = await getEmbedConfig( From 0816d0abe270d248ad2d62213779142161f27992 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:42:15 +0200 Subject: [PATCH 11/23] =?UTF-8?q?=F0=9F=8E=A8=20Shop=20Command=20is=20now?= =?UTF-8?q?=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/shop/index.ts | 18 ++--- src/commands/shop/modules/cpgg/index.ts | 5 +- src/commands/shop/modules/index.ts | 4 -- src/commands/shop/modules/roles/index.ts | 65 ++++++++++--------- .../shop/modules/roles/modules/buy/index.ts | 5 +- .../modules/roles/modules/cancel/index.ts | 5 +- .../shop/modules/roles/modules/index.ts | 7 -- 7 files changed, 52 insertions(+), 57 deletions(-) delete mode 100644 src/commands/shop/modules/index.ts delete mode 100644 src/commands/shop/modules/roles/modules/index.ts diff --git a/src/commands/shop/index.ts b/src/commands/shop/index.ts index 1da2442..bf3c20d 100644 --- a/src/commands/shop/index.ts +++ b/src/commands/shop/index.ts @@ -3,18 +3,18 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; // Modules -import modules from "./modules"; - -// Handlers - -export const moduleData = modules; +import moduleCpgg from "./modules/cpgg"; +import moduleRoles from "./modules/roles"; // Function export const builder = new SlashCommandBuilder() .setName("shop") .setDescription("Shop for credits and custom roles.") - .addSubcommand(modules.cpgg.builder) - .addSubcommandGroup(modules.roles.builder); + .setDMPermission(false) + + // Modules + .addSubcommand(moduleCpgg.builder) + .addSubcommandGroup(moduleRoles.builder); // Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { @@ -22,7 +22,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { switch (options.getSubcommand()) { case "cpgg": { - await modules.cpgg.execute(interaction); + await moduleCpgg.execute(interaction); break; } default: { @@ -32,7 +32,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { switch (options.getSubcommandGroup()) { case "roles": { - await modules.roles.execute(interaction); + await moduleRoles.execute(interaction); break; } default: { diff --git a/src/commands/shop/modules/cpgg/index.ts b/src/commands/shop/modules/cpgg/index.ts index f7df0a4..1e50907 100644 --- a/src/commands/shop/modules/cpgg/index.ts +++ b/src/commands/shop/modules/cpgg/index.ts @@ -10,13 +10,12 @@ import { } from "discord.js"; import { v4 as uuidv4 } from "uuid"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; import encryption from "../../../../helpers/encryption"; import getEmbedData from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("cpgg") @@ -29,6 +28,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedData(interaction.guild); const { options, guild, user, client } = interaction; diff --git a/src/commands/shop/modules/index.ts b/src/commands/shop/modules/index.ts deleted file mode 100644 index c3df89d..0000000 --- a/src/commands/shop/modules/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import cpgg from "./cpgg"; -import * as roles from "./roles"; - -export default { cpgg, roles }; diff --git a/src/commands/shop/modules/roles/index.ts b/src/commands/shop/modules/roles/index.ts index ae87e29..0064d14 100644 --- a/src/commands/shop/modules/roles/index.ts +++ b/src/commands/shop/modules/roles/index.ts @@ -5,39 +5,42 @@ import { ChatInputCommandInteraction } from "discord.js"; // Handlers // Modules -import modules from "./modules"; +import moduleBuy from "./modules/buy"; +import moduleCancel from "./modules/cancel"; import guildSchema from "../../../../models/guild"; -export const moduleData = modules; +export default { + builder: (group: SlashCommandSubcommandGroupBuilder) => { + return ( + group + .setName("roles") + .setDescription("Shop for custom roles.") -// Function -export const builder = (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("roles") - .setDescription("Shop for custom roles.") - .addSubcommand(modules.buy.builder) - .addSubcommand(modules.cancel.builder); -}; - -export const execute = async (interaction: ChatInputCommandInteraction) => { - if (!interaction.guild) return; - const { options, guild } = interaction; - - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) return; - - if (!guildDB.shop.roles.status) - throw new Error("This server has disabled shop roles."); - - if (options?.getSubcommand() === "buy") { - await modules.buy.execute(interaction); - } - - if (options?.getSubcommand() === "cancel") { - await modules.cancel.execute(interaction); - } + // Modules + .addSubcommand(moduleBuy.builder) + .addSubcommand(moduleCancel.builder) + ); + }, + execute: async (interaction: ChatInputCommandInteraction) => { + if (!interaction.guild) return; + const { options, guild } = interaction; + + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) return; + + if (!guildDB.shop.roles.status) + throw new Error("This server has disabled shop roles."); + + if (options?.getSubcommand() === "buy") { + await moduleBuy.execute(interaction); + } + + if (options?.getSubcommand() === "cancel") { + await moduleCancel.execute(interaction); + } + }, }; diff --git a/src/commands/shop/modules/roles/modules/buy/index.ts b/src/commands/shop/modules/roles/modules/buy/index.ts index f776e2c..e1ca0b2 100644 --- a/src/commands/shop/modules/roles/modules/buy/index.ts +++ b/src/commands/shop/modules/roles/modules/buy/index.ts @@ -2,14 +2,13 @@ // Helpers import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; +import deferReply from "../../../../../../handlers/deferReply"; // Configurations // import fetchUser from "../../../../../../helpers/userData"; // Models // Function export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("buy") @@ -28,6 +27,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + // const { successColor, footerText, footerIcon } = await getEmbedConfig( // interaction.guild // ); diff --git a/src/commands/shop/modules/roles/modules/cancel/index.ts b/src/commands/shop/modules/roles/modules/cancel/index.ts index 4d0cfc9..4f842f9 100644 --- a/src/commands/shop/modules/roles/modules/cancel/index.ts +++ b/src/commands/shop/modules/roles/modules/cancel/index.ts @@ -5,11 +5,10 @@ import { ChatInputCommandInteraction } from "discord.js"; // Configurations // import fetchUser from "../../../../../../helpers/userData"; // Models +import deferReply from "../../../../../../handlers/deferReply"; // Function export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("cancel") @@ -22,6 +21,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + // const { successColor, footerText, footerIcon } = await getEmbedConfig( // interaction.guild // ); diff --git a/src/commands/shop/modules/roles/modules/index.ts b/src/commands/shop/modules/roles/modules/index.ts deleted file mode 100644 index b9e1626..0000000 --- a/src/commands/shop/modules/roles/modules/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import buy from "./buy"; -import cancel from "./cancel"; - -export default { - buy, - cancel, -}; From 5c97c21e2a120204d6806392f70a5aca381e17f6 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:44:41 +0200 Subject: [PATCH 12/23] =?UTF-8?q?=F0=9F=8E=A8=20Utility=20Command=20is=20n?= =?UTF-8?q?ow=20using=20guard=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/utility/index.ts | 24 ++++++++++++-------- src/commands/utility/modules/about/index.ts | 5 ++-- src/commands/utility/modules/avatar/index.ts | 5 ++-- src/commands/utility/modules/index.ts | 11 --------- src/commands/utility/modules/ping/index.ts | 5 ++-- src/commands/utility/modules/stats/index.ts | 5 ++-- 6 files changed, 26 insertions(+), 29 deletions(-) delete mode 100644 src/commands/utility/modules/index.ts diff --git a/src/commands/utility/index.ts b/src/commands/utility/index.ts index fb87528..a58d229 100644 --- a/src/commands/utility/index.ts +++ b/src/commands/utility/index.ts @@ -1,32 +1,36 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; -import modules from "./modules"; -export const moduleData = modules; +// Modules +import moduleAbout from "./modules/about"; +import moduleAvatar from "./modules/avatar"; +import modulePing from "./modules/ping"; +import moduleStats from "./modules/stats"; export const builder = new SlashCommandBuilder() .setName("utility") .setDescription("Common utility.") - .addSubcommand(modules.about.builder) - .addSubcommand(modules.stats.builder) - .addSubcommand(modules.avatar.builder) - .addSubcommand(modules.ping.builder); + // Modules + .addSubcommand(moduleAbout.builder) + .addSubcommand(moduleStats.builder) + .addSubcommand(moduleAvatar.builder) + .addSubcommand(modulePing.builder); // Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "about": - await modules.about.execute(interaction); + await moduleAbout.execute(interaction); break; case "stats": - await modules.stats.execute(interaction); + await moduleStats.execute(interaction); break; case "avatar": - await modules.avatar.execute(interaction); + await moduleAvatar.execute(interaction); break; case "ping": - await modules.ping.execute(interaction); + await modulePing.execute(interaction); break; default: throw new Error( diff --git a/src/commands/utility/modules/about/index.ts b/src/commands/utility/modules/about/index.ts index 7265dad..01f0ad7 100644 --- a/src/commands/utility/modules/about/index.ts +++ b/src/commands/utility/modules/about/index.ts @@ -7,17 +7,18 @@ import { CommandInteraction, EmbedBuilder, } from "discord.js"; +import deferReply from "../../../../handlers/deferReply"; // Configurations import getEmbedConfig from "../../../../helpers/getEmbedData"; // Function export default { - metadata: { guildOnly: false, ephemeral: false }, - builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("about").setDescription("About this bot!)"); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, false); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/utility/modules/avatar/index.ts b/src/commands/utility/modules/avatar/index.ts index 1b87931..a6e4ffb 100644 --- a/src/commands/utility/modules/avatar/index.ts +++ b/src/commands/utility/modules/avatar/index.ts @@ -1,10 +1,9 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { CommandInteraction, EmbedBuilder } from "discord.js"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; export default { - metadata: { guildOnly: false, ephemeral: false }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("avatar") @@ -16,6 +15,8 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, false); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/utility/modules/index.ts b/src/commands/utility/modules/index.ts deleted file mode 100644 index 7383403..0000000 --- a/src/commands/utility/modules/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import about from "./about"; -import avatar from "./avatar"; -import ping from "./ping"; -import stats from "./stats"; - -export default { - avatar, - about, - stats, - ping, -}; diff --git a/src/commands/utility/modules/ping/index.ts b/src/commands/utility/modules/ping/index.ts index 1442e03..3855e89 100644 --- a/src/commands/utility/modules/ping/index.ts +++ b/src/commands/utility/modules/ping/index.ts @@ -2,16 +2,17 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { CommandInteraction, EmbedBuilder } from "discord.js"; // Configurations +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; // Function export default { - metadata: { guildOnly: false, ephemeral: false }, - builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("ping").setDescription("Ping this bot"); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, false); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/utility/modules/stats/index.ts b/src/commands/utility/modules/stats/index.ts index eae22f3..b422423 100644 --- a/src/commands/utility/modules/stats/index.ts +++ b/src/commands/utility/modules/stats/index.ts @@ -1,14 +1,15 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { CommandInteraction, EmbedBuilder } from "discord.js"; +import deferReply from "../../../../handlers/deferReply"; import getEmbedConfig from "../../../../helpers/getEmbedData"; export default { - metadata: { guildOnly: false, ephemeral: false }, - builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("stats").setDescription("Check bot statistics!)"); }, execute: async (interaction: CommandInteraction) => { + await deferReply(interaction, false); + const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); From 193b778910be1d48bc896fcf0ecb317f111d3abb Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 16:49:35 +0200 Subject: [PATCH 13/23] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Rewritten=20join=20a?= =?UTF-8?q?nd=20leave=20messages=20to=20use=20Prisma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildMemberAdd/joinMessage.ts | 26 +++++++++++--------- src/events/guildMemberRemove/leaveMessage.ts | 26 +++++++++++--------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/events/guildMemberAdd/joinMessage.ts b/src/events/guildMemberAdd/joinMessage.ts index bf97b12..57703fb 100644 --- a/src/events/guildMemberAdd/joinMessage.ts +++ b/src/events/guildMemberAdd/joinMessage.ts @@ -1,6 +1,6 @@ -import { EmbedBuilder, GuildMember, TextChannel } from "discord.js"; +import { ChannelType, EmbedBuilder, GuildMember } from "discord.js"; +import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; -import guildSchema from "../../models/guild"; export default { execute: async (member: GuildMember) => { @@ -8,29 +8,33 @@ export default { member.guild ); - const guildData = await guildSchema.findOne({ guildId: member.guild.id }); + const getGuild = await prisma.guild.findUnique({ + where: { id: member.guild.id }, + }); + + if (!getGuild) throw new Error("Guild not found"); const { client } = member; - if (guildData === null) return; - - if (guildData.welcome.status !== true) return; - if (!guildData.welcome.joinChannel) return; + if (getGuild.welcomeEnabled !== true) return; + if (!getGuild.welcomeJoinChannelId) return; const channel = client.channels.cache.get( - `${guildData.welcome.joinChannel}` + `${getGuild.welcomeJoinChannelId}` ); - if (channel === null) return; + if (!channel) throw new Error("Channel not found"); + if (channel.type !== ChannelType.GuildText) + throw new Error("Channel is not a text channel"); - (channel as TextChannel).send({ + channel.send({ embeds: [ new EmbedBuilder() .setColor(successColor) .setTitle(`${member.user.username} has joined the server!`) .setThumbnail(member.user.displayAvatarURL()) .setDescription( - guildData.welcome.joinChannelMessage || + getGuild.welcomeJoinChannelMessage || "Configure a join message in the `/settings guild welcome`." ) .setTimestamp() diff --git a/src/events/guildMemberRemove/leaveMessage.ts b/src/events/guildMemberRemove/leaveMessage.ts index 79a2460..9ac7c85 100644 --- a/src/events/guildMemberRemove/leaveMessage.ts +++ b/src/events/guildMemberRemove/leaveMessage.ts @@ -1,6 +1,6 @@ -import { EmbedBuilder, GuildMember, TextChannel } from "discord.js"; +import { ChannelType, EmbedBuilder, GuildMember } from "discord.js"; +import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; -import guildSchema from "../../models/guild"; export default { execute: async (member: GuildMember) => { @@ -8,29 +8,33 @@ export default { member.guild ); - const guildData = await guildSchema.findOne({ guildId: member.guild.id }); + const getGuild = await prisma.guild.findUnique({ + where: { id: member.guild.id }, + }); + + if (!getGuild) throw new Error("Guild not found"); const { client } = member; - if (guildData === null) return; - - if (guildData.welcome.status !== true) return; - if (!guildData.welcome.leaveChannel) return; + if (getGuild.welcomeEnabled !== true) return; + if (!getGuild.welcomeLeaveChannelId) return; const channel = client.channels.cache.get( - `${guildData.welcome.leaveChannel}` + `${getGuild.welcomeLeaveChannelId}` ); - if (channel === null) return; + if (!channel) throw new Error("Channel not found"); + if (channel.type !== ChannelType.GuildText) + throw new Error("Channel is not a text channel"); - (channel as TextChannel).send({ + channel.send({ embeds: [ new EmbedBuilder() .setColor(errorColor) .setTitle(`${member.user.username} has left the server!`) .setThumbnail(member.user.displayAvatarURL()) .setDescription( - guildData.welcome.leaveChannelMessage || + getGuild.welcomeLeaveChannelMessage || "Configure a leave message in the `/settings guild welcome`." ) .setTimestamp() From 8898959c848d057dd176180e27b2b07fbd3725c6 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 17:36:34 +0200 Subject: [PATCH 14/23] =?UTF-8?q?=F0=9F=9A=80=20Bot=20is=20fully=20migrate?= =?UTF-8?q?d=20over=20to=20Prisma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 16 ++ .../migration.sql | 25 +++ .../migration.sql | 20 ++ .../migration.sql | 20 ++ prisma/migrations/migration_lock.toml | 2 +- prisma/schema.prisma | 32 ++- src/commands/shop/modules/roles/index.ts | 11 +- .../shop/modules/roles/modules/buy/index.ts | 207 ++++++++++++------ .../modules/roles/modules/cancel/index.ts | 144 ++++++++---- src/events/guildMemberAdd/audits.ts | 21 +- src/events/guildMemberRemove/audits.ts | 17 +- src/events/interactionCreate/audits.ts | 19 +- src/events/messageDelete/audits.ts | 15 +- src/events/messageUpdate/audits.ts | 15 +- src/models/guild.ts | 142 ------------ src/models/shopRole.ts | 48 ---- src/models/timeout.ts | 38 ---- src/models/user.ts | 42 ---- .../modules/roles/components/dueForPayment.ts | 4 +- .../roles/components/overDueForPayment.ts | 140 ++++++++---- src/schedules/shop/modules/roles/index.ts | 35 ++- src/schedules/timeouts/index.ts | 44 ++-- 22 files changed, 541 insertions(+), 516 deletions(-) create mode 100644 prisma/migrations/20221021150615_shoproles_model/migration.sql create mode 100644 prisma/migrations/20221021151136_shoproles_model_correction/migration.sql create mode 100644 prisma/migrations/20221021151337_shoproles_model_correction/migration.sql create mode 100644 prisma/migrations/20221021153546_shoproles_model_correction/migration.sql delete mode 100644 src/models/guild.ts delete mode 100644 src/models/shopRole.ts delete mode 100644 src/models/timeout.ts delete mode 100644 src/models/user.ts diff --git a/prisma/migrations/20221021150615_shoproles_model/migration.sql b/prisma/migrations/20221021150615_shoproles_model/migration.sql new file mode 100644 index 0000000..1859cc1 --- /dev/null +++ b/prisma/migrations/20221021150615_shoproles_model/migration.sql @@ -0,0 +1,16 @@ +-- CreateTable +CREATE TABLE "GuildShopRoles" ( + "guildId" TEXT NOT NULL, + "channelId" TEXT NOT NULL, + "roleId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "pricePerHour" INTEGER NOT NULL DEFAULT 5, + "lastPayed" DATETIME NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildShopRoles_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "GuildShopRoles_guildId_channelId_key" ON "GuildShopRoles"("guildId", "channelId"); diff --git a/prisma/migrations/20221021151136_shoproles_model_correction/migration.sql b/prisma/migrations/20221021151136_shoproles_model_correction/migration.sql new file mode 100644 index 0000000..5631656 --- /dev/null +++ b/prisma/migrations/20221021151136_shoproles_model_correction/migration.sql @@ -0,0 +1,25 @@ +/* + Warnings: + + - You are about to drop the column `channelId` on the `GuildShopRoles` table. All the data in the column will be lost. + +*/ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_GuildShopRoles" ( + "guildId" TEXT NOT NULL, + "roleId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "pricePerHour" INTEGER NOT NULL DEFAULT 5, + "lastPayed" DATETIME NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildShopRoles_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildShopRoles" ("createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId") SELECT "createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId" FROM "GuildShopRoles"; +DROP TABLE "GuildShopRoles"; +ALTER TABLE "new_GuildShopRoles" RENAME TO "GuildShopRoles"; +CREATE UNIQUE INDEX "GuildShopRoles_guildId_userId_roleId_key" ON "GuildShopRoles"("guildId", "userId", "roleId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221021151337_shoproles_model_correction/migration.sql b/prisma/migrations/20221021151337_shoproles_model_correction/migration.sql new file mode 100644 index 0000000..8a3fe75 --- /dev/null +++ b/prisma/migrations/20221021151337_shoproles_model_correction/migration.sql @@ -0,0 +1,20 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_GuildShopRoles" ( + "guildId" TEXT NOT NULL, + "roleId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "pricePerHour" INTEGER NOT NULL DEFAULT 5, + "lastPayed" DATETIME NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildShopRoles_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_guildId_userId_fkey" FOREIGN KEY ("guildId", "userId") REFERENCES "GuildMember" ("guildId", "userId") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildShopRoles" ("createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId") SELECT "createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId" FROM "GuildShopRoles"; +DROP TABLE "GuildShopRoles"; +ALTER TABLE "new_GuildShopRoles" RENAME TO "GuildShopRoles"; +CREATE UNIQUE INDEX "GuildShopRoles_guildId_userId_roleId_key" ON "GuildShopRoles"("guildId", "userId", "roleId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221021153546_shoproles_model_correction/migration.sql b/prisma/migrations/20221021153546_shoproles_model_correction/migration.sql new file mode 100644 index 0000000..88d1d66 --- /dev/null +++ b/prisma/migrations/20221021153546_shoproles_model_correction/migration.sql @@ -0,0 +1,20 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_GuildShopRoles" ( + "guildId" TEXT NOT NULL, + "roleId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "pricePerHour" INTEGER NOT NULL DEFAULT 5, + "lastPayed" DATETIME NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildShopRoles_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_guildId_fkey" FOREIGN KEY ("userId", "guildId") REFERENCES "GuildMember" ("userId", "guildId") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildShopRoles" ("createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId") SELECT "createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId" FROM "GuildShopRoles"; +DROP TABLE "GuildShopRoles"; +ALTER TABLE "new_GuildShopRoles" RENAME TO "GuildShopRoles"; +CREATE UNIQUE INDEX "GuildShopRoles_guildId_userId_roleId_key" ON "GuildShopRoles"("guildId", "userId", "roleId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index 6fcf33d..e5e5c47 100644 --- a/prisma/migrations/migration_lock.toml +++ b/prisma/migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually # It should be added in your version-control system (i.e. Git) -provider = "sqlite" +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5418d5b..f7923d4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -58,8 +58,9 @@ model Guild { welcomeLeaveChannelId String? welcomeLeaveChannelMessage String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + GuildShopRoles GuildShopRoles[] } model User { @@ -72,8 +73,9 @@ model User { reputationsEarned Int @default(0) Cooldown Cooldown[] - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + GuildShopRoles GuildShopRoles[] } model GuildMember { @@ -89,8 +91,9 @@ model GuildMember { creditsEarned Int @default(0) pointsEarned Int @default(0) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + GuildShopRoles GuildShopRoles[] // Unique Identifier @@unique([userId, guildId]) @@ -122,3 +125,20 @@ model Cooldown { @@unique([guildId, userId, timeoutId]) } + +model GuildShopRoles { + guildId String + roleId String + userId String + pricePerHour Int @default(5) + lastPayed DateTime + + guild Guild @relation(fields: [guildId], references: [id]) + user User @relation(fields: [userId], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + member GuildMember? @relation(fields: [userId, guildId], references: [userId, guildId]) + + @@unique([guildId, userId, roleId]) +} diff --git a/src/commands/shop/modules/roles/index.ts b/src/commands/shop/modules/roles/index.ts index 0064d14..4d954cf 100644 --- a/src/commands/shop/modules/roles/index.ts +++ b/src/commands/shop/modules/roles/index.ts @@ -8,7 +8,7 @@ import { ChatInputCommandInteraction } from "discord.js"; import moduleBuy from "./modules/buy"; import moduleCancel from "./modules/cancel"; -import guildSchema from "../../../../models/guild"; +import prisma from "../../../../handlers/database"; export default { builder: (group: SlashCommandSubcommandGroupBuilder) => { @@ -26,13 +26,12 @@ export default { if (!interaction.guild) return; const { options, guild } = interaction; - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, + const getGuild = await prisma.guild.findUnique({ + where: { id: guild.id }, }); + if (!getGuild) throw new Error("Guild not found"); - if (guildDB === null) return; - - if (!guildDB.shop.roles.status) + if (!getGuild.shopRolesEnabled) throw new Error("This server has disabled shop roles."); if (options?.getSubcommand() === "buy") { diff --git a/src/commands/shop/modules/roles/modules/buy/index.ts b/src/commands/shop/modules/roles/modules/buy/index.ts index e1ca0b2..a6e3b0b 100644 --- a/src/commands/shop/modules/roles/modules/buy/index.ts +++ b/src/commands/shop/modules/roles/modules/buy/index.ts @@ -1,12 +1,22 @@ // Dependencies // Helpers import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import { ChatInputCommandInteraction } from "discord.js"; +import { + ChatInputCommandInteraction, + ColorResolvable, + EmbedBuilder, + GuildMemberRoleManager, +} from "discord.js"; import deferReply from "../../../../../../handlers/deferReply"; +import getEmbedData from "../../../../../../helpers/getEmbedData"; +import logger from "../../../../../../middlewares/logger"; // Configurations // import fetchUser from "../../../../../../helpers/userData"; // Models +import prisma from "../../../../../../handlers/database"; +import pluralize from "../../../../../../helpers/pluralize"; + // Function export default { builder: (command: SlashCommandSubcommandBuilder) => { @@ -29,65 +39,140 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - // const { successColor, footerText, footerIcon } = await getEmbedConfig( - // interaction.guild - // ); - // const { options, guild, user, member } = interaction; - // const optionName = options?.getString("name"); - // const optionColor = options?.getString("color"); - // // If amount is null - // if (optionName === null) - // throw new Error("We could not read your requested name"); - // await guild?.roles - // .create({ - // name: optionName, - // color: optionColor as ColorResolvable, - // reason: `${user?.id} bought from shop`, - // }) - // .then(async (role) => { - // // Get guild object - // const guildDB = await guildSchema?.findOne({ - // guildId: guild?.id, - // }); - // const userDB = await fetchUser(user, guild); - // if (userDB === null) { - // return logger?.silly(`User is null`); - // } - // if (guildDB === null) { - // return logger?.silly(`Guild is null`); - // } - // if (guildDB.shop === null) { - // return logger?.silly(`Shop is null`); - // } - // const { pricePerHour } = guildDB.shop.roles; - // userDB.credits -= pricePerHour; - // await userDB?.save(); - // await shopRolesSchema?.create({ - // roleId: role?.id, - // userId: user?.id, - // guildId: guild?.id, - // pricePerHour, - // lastPayed: new Date(), - // }); - // await (member?.roles as GuildMemberRoleManager)?.add(role?.id); - // logger?.silly(`Role ${role?.name} was bought by ${user?.tag}`); - // const interactionEmbed = new EmbedBuilder() - // .setTitle("[:shopping_cart:] Buy") - // .setDescription( - // `You bought **${optionName}** for **${pluralize( - // pricePerHour, - // "credit" - // )}**.` - // ) - // .setTimestamp() - // .setColor(successColor) - // .setFooter({ text: footerText, iconURL: footerIcon }); - // return interaction?.editReply({ - // embeds: [interactionEmbed], - // }); - // }) - // .catch(() => { - // throw new Error("Failed creating role."); - // }); + const { successColor, footerText, footerIcon } = await getEmbedData( + interaction.guild + ); + const { options, guild, user, member } = interaction; + const optionName = options?.getString("name"); + const optionColor = options?.getString("color"); + // If amount is null + if (optionName === null) + throw new Error("We could not read your requested name"); + await guild?.roles + .create({ + name: optionName, + color: optionColor as ColorResolvable, + reason: `${user?.id} bought from shop`, + }) + .then(async (role) => { + const userId = "SNOWFLKAE"; + const guildId = "SNOWFLAKE"; + + const createGuildMember = await prisma.guildMember.upsert({ + where: { + userId_guildId: { + userId, + guildId, + }, + }, + update: {}, + create: { + user: { + connectOrCreate: { + create: { + id: userId, + }, + where: { + id: userId, + }, + }, + }, + guild: { + connectOrCreate: { + create: { + id: guildId, + }, + where: { + id: guildId, + }, + }, + }, + }, + include: { + user: true, + guild: true, + }, + }); + + logger.silly(createGuildMember); + + // Get guild object + const pricePerHour = createGuildMember.guild.shopRolesPricePerHour; + + const updateGuildMember = await prisma.guildMember.update({ + where: { + userId_guildId: { + userId, + guildId, + }, + }, + data: { + creditsEarned: { decrement: pricePerHour }, + }, + }); + + logger.silly(updateGuildMember); + + const createShopRole = await prisma.guildShopRoles.upsert({ + where: { + guildId_userId_roleId: { + guildId: guild.id, + userId: user.id, + roleId: role.id, + }, + }, + update: {}, + create: { + roleId: role.id, + lastPayed: new Date(), + user: { + connectOrCreate: { + create: { + id: user.id, + }, + where: { + id: user.id, + }, + }, + }, + guild: { + connectOrCreate: { + create: { + id: guild.id, + }, + where: { + id: guild.id, + }, + }, + }, + }, + include: { + user: true, + guild: true, + }, + }); + + logger.silly(createShopRole); + + await (member?.roles as GuildMemberRoleManager)?.add(role?.id); + logger?.silly(`Role ${role?.name} was bought by ${user?.tag}`); + const interactionEmbed = new EmbedBuilder() + .setTitle("[:shopping_cart:] Buy") + .setDescription( + `You bought **${optionName}** for **${pluralize( + pricePerHour, + "credit" + )}**.` + ) + .setTimestamp() + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }); + return interaction?.editReply({ + embeds: [interactionEmbed], + }); + }) + .catch(() => { + throw new Error("Failed creating role."); + }); }, }; diff --git a/src/commands/shop/modules/roles/modules/cancel/index.ts b/src/commands/shop/modules/roles/modules/cancel/index.ts index 4f842f9..8807ac4 100644 --- a/src/commands/shop/modules/roles/modules/cancel/index.ts +++ b/src/commands/shop/modules/roles/modules/cancel/index.ts @@ -1,11 +1,21 @@ // Dependencies // Helpers import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import { ChatInputCommandInteraction } from "discord.js"; +import { + ChatInputCommandInteraction, + EmbedBuilder, + GuildMemberRoleManager, +} from "discord.js"; // Configurations -// import fetchUser from "../../../../../../helpers/userData"; // Models import deferReply from "../../../../../../handlers/deferReply"; +import logger from "../../../../../../middlewares/logger"; +// Configurations +// Models + +import prisma from "../../../../../../handlers/database"; +import getEmbedData from "../../../../../../helpers/getEmbedData"; +import pluralize from "../../../../../../helpers/pluralize"; // Function export default { @@ -23,45 +33,95 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - // const { successColor, footerText, footerIcon } = await getEmbedConfig( - // interaction.guild - // ); - // const { options, guild, user, member } = interaction; - // const optionRole = options.getRole("role"); - // if (optionRole === null) - // throw new Error("We could not read your requested role."); - // const roleExist = await shopRolesSchema?.findOne({ - // guildId: guild?.id, - // userId: user?.id, - // roleId: optionRole?.id, - // }); - // if (roleExist === null) return; - // await (member?.roles as GuildMemberRoleManager)?.remove(optionRole?.id); - // await guild?.roles - // .delete(optionRole?.id, `${user?.id} canceled from shop`) - // .then(async () => { - // const userDB = await fetchUser(user, guild); - // if (userDB === null) { - // return logger?.silly(`User is null`); - // } - // await shopRolesSchema?.deleteOne({ - // roleId: optionRole?.id, - // userId: user?.id, - // guildId: guild?.id, - // }); - // const interactionEmbed = new EmbedBuilder() - // .setTitle("[:shopping_cart:] Cancel") - // .setDescription(`You have canceled ${optionRole.name}.`) - // .setTimestamp() - // .setColor(successColor) - // .addFields({ - // name: "Your balance", - // value: `${pluralize(userDB?.credits, "credit")}`, - // }) - // .setFooter({ text: footerText, iconURL: footerIcon }); - // return interaction?.editReply({ - // embeds: [interactionEmbed], - // }); - // }); + const { successColor, footerText, footerIcon } = await getEmbedData( + interaction.guild + ); + const { options, guild, user, member } = interaction; + const optionRole = options.getRole("role"); + if (optionRole === null) + throw new Error("We could not read your requested role."); + if (!guild) throw new Error("No guild specified"); + if (!user) throw new Error("No user specified"); + + const roleExist = await prisma.guildShopRoles.findUnique({ + where: { + guildId_userId_roleId: { + guildId: guild.id, + userId: user.id, + roleId: optionRole.id, + }, + }, + }); + if (roleExist === null) return; + await (member?.roles as GuildMemberRoleManager)?.remove(optionRole?.id); + await guild?.roles + .delete(optionRole?.id, `${user?.id} canceled from shop`) + .then(async () => { + const createGuildMember = await prisma.guildMember.upsert({ + where: { + userId_guildId: { + userId: user.id, + guildId: guild.id, + }, + }, + update: {}, + create: { + user: { + connectOrCreate: { + create: { + id: user.id, + }, + where: { + id: user.id, + }, + }, + }, + guild: { + connectOrCreate: { + create: { + id: guild.id, + }, + where: { + id: guild.id, + }, + }, + }, + }, + include: { + user: true, + guild: true, + }, + }); + + logger.silly(createGuildMember); + + if (!createGuildMember) throw new Error("Guild member not created"); + + const deleteShopRole = await prisma.guildShopRoles.delete({ + where: { + guildId_userId_roleId: { + guildId: guild?.id, + userId: user?.id, + roleId: optionRole?.id, + }, + }, + }); + + logger.silly(deleteShopRole); + + const interactionEmbed = new EmbedBuilder() + .setTitle("[:shopping_cart:] Cancel") + .setDescription(`You have canceled ${optionRole.name}.`) + .setTimestamp() + .setColor(successColor) + .addFields({ + name: "Your balance", + value: `${pluralize(createGuildMember.creditsEarned, "credit")}`, + }) + .setFooter({ text: footerText, iconURL: footerIcon }); + return interaction?.editReply({ + embeds: [interactionEmbed], + }); + }); }, }; diff --git a/src/events/guildMemberAdd/audits.ts b/src/events/guildMemberAdd/audits.ts index 697408d..0d61fa1 100644 --- a/src/events/guildMemberAdd/audits.ts +++ b/src/events/guildMemberAdd/audits.ts @@ -1,25 +1,28 @@ import { ChannelType, EmbedBuilder, GuildMember } from "discord.js"; +import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; import logger from "../../middlewares/logger"; -import guildSchema from "../../models/guild"; export default { execute: async (member: GuildMember) => { const { client, guild } = member; - const guildData = await guildSchema.findOne({ guildId: member.guild.id }); - if (!guildData) { - throw new Error("Could not find guild"); - } - if (guildData.audits.status !== true) return; - if (!guildData.audits.channelId) { + const getGuild = await prisma.guild.findUnique({ + where: { id: member.guild.id }, + }); + if (!getGuild) throw new Error("Guild not found"); + + if (getGuild.auditsEnabled !== true) return; + if (!getGuild.auditsChannelId) { throw new Error("Channel not found"); } const embedConfig = await getEmbedConfig(guild); - const channel = client.channels.cache.get(guildData.audits.channelId); - if (channel?.type !== ChannelType.GuildText) { + const channel = client.channels.cache.get(getGuild.auditsChannelId); + + if (!channel) throw new Error("Channel not found"); + if (channel.type !== ChannelType.GuildText) { throw new Error("Channel must be a text channel"); } diff --git a/src/events/guildMemberRemove/audits.ts b/src/events/guildMemberRemove/audits.ts index d3967cd..ff4bb59 100644 --- a/src/events/guildMemberRemove/audits.ts +++ b/src/events/guildMemberRemove/audits.ts @@ -1,24 +1,25 @@ import { ChannelType, EmbedBuilder, GuildMember } from "discord.js"; +import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; import logger from "../../middlewares/logger"; -import guildSchema from "../../models/guild"; export default { execute: async (member: GuildMember) => { const { client, guild } = member; - const guildData = await guildSchema.findOne({ guildId: member.guild.id }); - if (!guildData) { - throw new Error("Could not find guild"); - } - if (guildData.audits.status !== true) return; - if (!guildData.audits.channelId) { + const getGuild = await prisma.guild.findUnique({ + where: { id: member.guild.id }, + }); + if (!getGuild) throw new Error("Guild not found"); + + if (getGuild.auditsEnabled !== true) return; + if (!getGuild.auditsChannelId) { throw new Error("Channel not found"); } const embedConfig = await getEmbedConfig(guild); - const channel = client.channels.cache.get(guildData.audits.channelId); + const channel = client.channels.cache.get(getGuild.auditsChannelId); if (channel?.type !== ChannelType.GuildText) { throw new Error("Channel must be a text channel"); } diff --git a/src/events/interactionCreate/audits.ts b/src/events/interactionCreate/audits.ts index 3fc22f3..90a55e4 100644 --- a/src/events/interactionCreate/audits.ts +++ b/src/events/interactionCreate/audits.ts @@ -1,7 +1,7 @@ import { BaseInteraction, ChannelType, EmbedBuilder } from "discord.js"; +import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; import logger from "../../middlewares/logger"; -import guildSchema from "../../models/guild"; export default { execute: async (interaction: BaseInteraction) => { @@ -9,22 +9,21 @@ export default { if (interaction.guild === null) return; + const getGuild = await prisma.guild.findUnique({ + where: { id: interaction.guild.id }, + }); + if (!getGuild) throw new Error("Guild not found"); + const { footerText, footerIcon, successColor } = await getEmbedConfig( interaction.guild ); - const guildData = await guildSchema.findOne({ - guildId: interaction.guild.id, - }); - const { client } = interaction; - if (guildData === null) return; + if (getGuild.auditsEnabled !== true) return; + if (!getGuild.auditsChannelId) return; - if (guildData.audits.status !== true) return; - if (!guildData.audits.channelId) return; - - const channel = client.channels.cache.get(`${guildData.audits.channelId}`); + const channel = client.channels.cache.get(`${getGuild.auditsChannelId}`); if (!channel) return; if (channel.type !== ChannelType.GuildText) return; diff --git a/src/events/messageDelete/audits.ts b/src/events/messageDelete/audits.ts index 9bf3ae9..56a8ac1 100644 --- a/src/events/messageDelete/audits.ts +++ b/src/events/messageDelete/audits.ts @@ -1,7 +1,7 @@ import { ChannelType, EmbedBuilder, Message } from "discord.js"; +import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; import logger from "../../middlewares/logger"; -import guildSchema from "../../models/guild"; export default { execute: async (message: Message) => { @@ -13,18 +13,19 @@ export default { message.guild ); - const guildData = await guildSchema.findOne({ - guildId: message.guild.id, + const getGuild = await prisma.guild.findUnique({ + where: { id: message.guild.id }, }); + if (!getGuild) throw new Error("Guild not found"); const { client } = message; - if (guildData === null) return; + if (!getGuild) throw new Error("Guild not found"); - if (guildData.audits.status !== true) return; - if (!guildData.audits.channelId) return; + if (getGuild.auditsEnabled !== true) return; + if (!getGuild.auditsChannelId) return; - const channel = client.channels.cache.get(`${guildData.audits.channelId}`); + const channel = client.channels.cache.get(`${getGuild.auditsChannelId}`); if (!channel) return; if (channel.type !== ChannelType.GuildText) return; diff --git a/src/events/messageUpdate/audits.ts b/src/events/messageUpdate/audits.ts index ba35962..a498385 100644 --- a/src/events/messageUpdate/audits.ts +++ b/src/events/messageUpdate/audits.ts @@ -1,8 +1,8 @@ /* eslint-disable no-loops/no-loops */ import { ChannelType, EmbedBuilder, Message } from "discord.js"; +import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; import logger from "../../middlewares/logger"; -import guildSchema from "../../models/guild"; export default { execute: async (oldMessage: Message, newMessage: Message) => { @@ -16,18 +16,17 @@ export default { newMessage.guild ); - const guildData = await guildSchema.findOne({ - guildId: oldMessage.guild.id, + const getGuild = await prisma.guild.findUnique({ + where: { id: oldMessage.guild.id }, }); + if (!getGuild) throw new Error("Guild not found"); const { client } = oldMessage; - if (guildData === null) return; + if (getGuild.auditsEnabled !== true) return; + if (!getGuild.auditsChannelId) return; - if (guildData.audits.status !== true) return; - if (!guildData.audits.channelId) return; - - const channel = client.channels.cache.get(`${guildData.audits.channelId}`); + const channel = client.channels.cache.get(`${getGuild.auditsChannelId}`); if (!channel) return; if (channel.type !== ChannelType.GuildText) return; diff --git a/src/models/guild.ts b/src/models/guild.ts deleted file mode 100644 index 140befa..0000000 --- a/src/models/guild.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { ColorResolvable } from "discord.js"; -import { model, Schema } from "mongoose"; - -interface IGuild { - guildId: string; - credits: { - status: boolean; - rate: number; - timeout: number; - workRate: number; - minimumLength: number; - workTimeout: number; - }; - embeds: { - successColor: ColorResolvable; - waitColor: ColorResolvable; - errorColor: ColorResolvable; - footerIcon: string; - footerText: string; - }; - shop: { roles: { status: boolean; pricePerHour: number } }; - points: { - status: boolean; - rate: number; - minimumLength: number; - timeout: number; - }; - welcome: { - status: boolean; - joinChannel: string; - leaveChannel: string; - joinChannelMessage: string; - leaveChannelMessage: string; - }; - audits: { status: boolean; channelId: string }; -} - -const guildSchema = new Schema( - { - guildId: { - type: String, - required: true, - unique: true, - index: true, - }, - credits: { - status: { - type: Boolean, - default: true, - }, - rate: { - type: Number, - default: 1, - }, - minimumLength: { - type: Number, - default: 5, - }, - timeout: { - type: Number, - default: 5, - }, - workRate: { - type: Number, - default: 15, - }, - workTimeout: { - type: Number, - default: 900, - }, - }, - embeds: { - successColor: { - type: String, - default: "#22bb33", - }, - waitColor: { - type: String, - default: "#f0ad4e", - }, - errorColor: { - type: String, - default: "#bb2124", - }, - footerText: { - type: String, - default: "https://github.com/ZynerOrg/xyter", - }, - footerIcon: { - type: String, - default: "https://github.com/ZynerOrg.png", - }, - }, - shop: { - roles: { - status: { - type: Boolean, - default: false, - }, - pricePerHour: { - type: Number, - default: 5, - }, - }, - }, - points: { - status: { - type: Boolean, - default: false, - }, - rate: { - type: Number, - default: 1, - }, - minimumLength: { - type: Number, - default: 5, - }, - timeout: { - type: Number, - default: 5, - }, - }, - welcome: { - status: { - type: Boolean, - default: false, - }, - joinChannel: { type: String }, - leaveChannel: { type: String }, - joinChannelMessage: { type: String }, - leaveChannelMessage: { type: String }, - }, - audits: { - status: { type: Boolean, default: false }, - channelId: { type: String }, - }, - }, - { timestamps: true } -); - -export default model("guild", guildSchema); diff --git a/src/models/shopRole.ts b/src/models/shopRole.ts deleted file mode 100644 index 8711760..0000000 --- a/src/models/shopRole.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Snowflake } from "discord.js"; -import { model, Schema } from "mongoose"; - -export interface IShopRole { - roleId: Snowflake; - userId: Snowflake; - guildId: Snowflake; - pricePerHour: number; - lastPayed: Date; -} - -const shopRoleSchema = new Schema( - { - roleId: { - type: String, - required: true, - unique: false, - index: true, - }, - userId: { - type: String, - required: true, - unique: false, - index: true, - }, - guildId: { - type: String, - required: true, - unique: false, - index: true, - }, - pricePerHour: { - type: Number, - required: true, - unique: false, - index: true, - default: 5, - }, - lastPayed: { - type: Date, - unique: false, - index: true, - }, - }, - { timestamps: true } -); - -export default model("shopRole", shopRoleSchema); diff --git a/src/models/timeout.ts b/src/models/timeout.ts deleted file mode 100644 index dc1ba97..0000000 --- a/src/models/timeout.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Snowflake } from "discord.js"; -import { model, Schema } from "mongoose"; - -export interface ITimeout { - userId: Snowflake; - guildId: Snowflake; - cooldown: number; - timeoutId: string; - createdAt: Date; - updatedAt: Date; -} - -const timeoutSchema = new Schema( - { - userId: { - type: String, - required: true, - unique: false, - index: true, - }, - guildId: { - type: String, - required: true, - unique: false, - index: true, - }, - cooldown: { - type: Number, - required: true, - unique: false, - index: true, - }, - timeoutId: { type: String }, - }, - { timestamps: true } -); - -export default model("timeout", timeoutSchema); diff --git a/src/models/user.ts b/src/models/user.ts deleted file mode 100644 index 8170ac6..0000000 --- a/src/models/user.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Snowflake } from "discord.js"; -import { model, Schema } from "mongoose"; - -export interface IUser { - guildId: Snowflake; - userId: Snowflake; - language: string; - reputation: number; - credits: number; - level: number; - points: number; - updatedAt: Date; - createdAt: Date; -} - -const userSchema = new Schema( - { - guildId: { - type: String, - required: true, - unique: false, - index: true, - }, - userId: { - type: String, - required: true, - unique: false, - index: true, - }, - language: { - type: String, - default: "en", - }, - reputation: { type: Number, default: 0 }, - credits: { type: Number, default: 0 }, - level: { type: Number, default: 0 }, - points: { type: Number, default: 0 }, - }, - { timestamps: true } -); - -export default model("user", userSchema); diff --git a/src/schedules/shop/modules/roles/components/dueForPayment.ts b/src/schedules/shop/modules/roles/components/dueForPayment.ts index f2b487d..f87c94c 100644 --- a/src/schedules/shop/modules/roles/components/dueForPayment.ts +++ b/src/schedules/shop/modules/roles/components/dueForPayment.ts @@ -1,9 +1,9 @@ import { Client } from "discord.js"; import logger from "../../../../../middlewares/logger"; -import { IShopRole } from "../../../../../interfaces/ShopRole"; +import { GuildShopRoles } from "@prisma/client"; -export const execute = async (_client: Client, role: IShopRole) => { +export const execute = async (_client: Client, role: GuildShopRoles) => { const { roleId } = role; logger.silly(`Shop role ${roleId} is not due for payment.`); diff --git a/src/schedules/shop/modules/roles/components/overDueForPayment.ts b/src/schedules/shop/modules/roles/components/overDueForPayment.ts index cbc5568..7020db7 100644 --- a/src/schedules/shop/modules/roles/components/overDueForPayment.ts +++ b/src/schedules/shop/modules/roles/components/overDueForPayment.ts @@ -1,22 +1,14 @@ import { Client } from "discord.js"; import logger from "../../../../../middlewares/logger"; -import { IShopRole } from "../../../../../interfaces/ShopRole"; -import guildSchema from "../../../../../models/guild"; -import shopRoleSchema from "../../../../../models/shopRole"; -import userSchema from "../../../../../models/user"; +import { GuildShopRoles } from "@prisma/client"; +import prisma from "../../../../../handlers/database"; // Execute the component -export const execute = async (client: Client, role: IShopRole) => { +export const execute = async (client: Client, role: GuildShopRoles) => { const { guildId, userId, roleId } = role; if (!userId) throw new Error("User ID not found for shop role."); - const guildData = await guildSchema.findOne({ guildId }); - if (!guildData) throw new Error("Guild not found."); - - const userData = await userSchema.findOne({ guildId, userId }); - if (!userData) throw new Error("User not found."); - const rGuild = client.guilds.cache.get(guildId); if (!rGuild) throw new Error("Guild not found."); @@ -28,26 +20,44 @@ export const execute = async (client: Client, role: IShopRole) => { logger.debug(`Shop role ${roleId} is due for payment.`); - const { pricePerHour } = guildData.shop.roles; + const getGuildMember = await prisma.guildMember.findUnique({ + where: { + userId_guildId: { + userId, + guildId, + }, + }, + include: { + user: true, + guild: true, + }, + }); - if (userData.credits < pricePerHour) { + logger.silly(getGuildMember); + + if (!getGuildMember) throw new Error("Could not find guild member."); + + const pricePerHour = getGuildMember.guild.shopRolesPricePerHour; + + if (getGuildMember.creditsEarned < pricePerHour) { await rMember.roles .remove(roleId) .then(async () => { - await shopRoleSchema - .deleteOne({ - userId, - roleId, - guildId, - }) - .then(() => { - logger.silly( - `Shop role document ${roleId} has been deleted from user ${userId}.` - ); - }) - .catch(() => { - throw new Error("Failed deleting shop role from user."); - }); + const deleteShopRole = await prisma.guildShopRoles.delete({ + where: { + guildId_userId_roleId: { + guildId, + userId, + roleId, + }, + }, + }); + + logger.silly(deleteShopRole); + + logger.silly( + `Shop role document ${roleId} has been deleted from user ${userId}.` + ); }) .catch(() => { throw new Error(`Failed removing role from user.`); @@ -56,25 +66,63 @@ export const execute = async (client: Client, role: IShopRole) => { throw new Error("User does not have enough credits."); } - userData.credits -= pricePerHour; - await userData - .save() - .then(async () => { - logger.silly(`User ${userId} has been updated.`); + const createGuildMember = await prisma.guildMember.upsert({ + where: { + userId_guildId: { + userId, + guildId, + }, + }, + update: { creditsEarned: { decrement: pricePerHour } }, + create: { + creditsEarned: -pricePerHour, + user: { + connectOrCreate: { + create: { + id: userId, + }, + where: { + id: userId, + }, + }, + }, + guild: { + connectOrCreate: { + create: { + id: guildId, + }, + where: { + id: guildId, + }, + }, + }, + }, + include: { + user: true, + guild: true, + }, + }); - role.lastPayed = new Date(); - await role - .save() - .then(() => { - logger.silly(`Shop role ${roleId} has been updated.`); - }) - .catch(() => { - throw new Error("Failed updating shop role."); - }); + logger.silly(createGuildMember); - logger.debug(`Shop role ${roleId} has been paid.`); - }) - .catch(() => { - throw new Error("Failed updating user."); - }); + logger.silly(`User ${userId} has been updated.`); + + const updateGuildShopRole = await prisma.guildShopRoles.update({ + where: { + guildId_userId_roleId: { + guildId, + userId, + roleId, + }, + }, + data: { + lastPayed: new Date(), + }, + }); + + logger.silly(updateGuildShopRole); + + logger.silly(`Shop role ${roleId} has been updated.`); + + logger.debug(`Shop role ${roleId} has been paid.`); }; diff --git a/src/schedules/shop/modules/roles/index.ts b/src/schedules/shop/modules/roles/index.ts index d4e2c21..6dea00e 100644 --- a/src/schedules/shop/modules/roles/index.ts +++ b/src/schedules/shop/modules/roles/index.ts @@ -1,32 +1,27 @@ +/* eslint-disable no-loops/no-loops */ import { Client } from "discord.js"; - -import { IShopRole } from "../../../../interfaces/ShopRole"; -import shopRoleSchema from "../../../../models/shopRole"; +import prisma from "../../../../handlers/database"; import * as dueForPayment from "./components/dueForPayment"; import * as overDueForPayment from "./components/overDueForPayment"; export const execute = async (client: Client) => { - const roles = await shopRoleSchema.find(); + const roles = await prisma.guildShopRoles.findMany(); - await Promise.all( - roles.map(async (role: IShopRole) => { - const { lastPayed } = role; - const nextPayment = new Date( - lastPayed.setHours(lastPayed.getHours() + 1) - ); + for await (const role of roles) { + const { lastPayed } = role; + const nextPayment = new Date(lastPayed.setHours(lastPayed.getHours() + 1)); - const now = new Date(); + const now = new Date(); - if (nextPayment > now) { - await dueForPayment.execute(client, role); + if (nextPayment > now) { + await dueForPayment.execute(client, role); - return; - } + return; + } - if (nextPayment < now) { - await overDueForPayment.execute(client, role); - } - }) - ); + if (nextPayment < now) { + await overDueForPayment.execute(client, role); + } + } }; diff --git a/src/schedules/timeouts/index.ts b/src/schedules/timeouts/index.ts index bcdddd1..764d825 100644 --- a/src/schedules/timeouts/index.ts +++ b/src/schedules/timeouts/index.ts @@ -1,36 +1,40 @@ +/* eslint-disable no-loops/no-loops */ import logger from "../../middlewares/logger"; -import timeoutSchema from "../../models/timeout"; - import addSeconds from "../../helpers/addSeconds"; +import prisma from "../../handlers/database"; + export const options = { schedule: "*/30 * * * *", // https://crontab.guru/ }; // Execute the job export const execute = async () => { - const timeouts = await timeoutSchema.find(); - await Promise.all( - timeouts.map(async (timeout) => { - const { guildId, userId, timeoutId, cooldown, createdAt } = timeout; + const getCooldown = await prisma.cooldown.findMany(); - const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); + for await (const timeout of getCooldown) { + const { guildId, userId, timeoutId, cooldown, createdAt } = timeout; - if (overDue) { - timeoutSchema - .deleteOne({ + const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); + + if (overDue) { + logger.info(timeout); + const deleteCooldown = await prisma.cooldown.delete({ + where: { + guildId_userId_timeoutId: { guildId, userId, timeoutId, - cooldown, - }) - .then(() => { - logger.debug( - `Timeout document ${timeoutId} has been deleted from user ${userId}.` - ); - }); - } - }) - ); + }, + }, + }); + + logger.silly(deleteCooldown); + + logger.debug( + `Timeout document ${timeoutId} has been deleted from user ${userId}.` + ); + } + } }; From 61ab2cba9989c6ebd48c552979292b06c42889da Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 17:43:09 +0200 Subject: [PATCH 15/23] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20clean?= =?UTF-8?q?up=20of=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 +- .eslintignore | 2 -- .eslintrc.json | 15 --------------- .gitignore | 3 --- SECURITY.md | 14 -------------- prisma/.gitignore | 2 ++ 6 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json delete mode 100644 SECURITY.md create mode 100644 prisma/.gitignore diff --git a/.env.example b/.env.example index 3fd7d4f..a0b0942 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,7 @@ DISCORD_CLIENT_ID="" DISCORD_GUILD_ID="" # Database -MONGO_URL="mongodb+srv://username:password@host/database?retryWrites=true&w=majority" +DATABASE_URL="file:./production.db" # Encryption ENCRYPTION_ALGORITHM="aes-256-ctr" diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 76add87..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -dist \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 39d4adc..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "root": true, - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint", "no-loops", "prettier"], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - "prettier" - ], - "rules": { - "no-console": 1, - "no-loops/no-loops": 2 - } -} diff --git a/.gitignore b/.gitignore index fe6928b..1ab52e9 100644 --- a/.gitignore +++ b/.gitignore @@ -145,6 +145,3 @@ dist # Docker database docker-compose.local.yml - -# Prisma -prisma/*.db* \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 4933326..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,14 +0,0 @@ -# Security Policy - -## Supported Versions - -| Version | Supported | -| ---------- | ------------------ | -| 2022.4.x | :white_check_mark: | -| < 2022.4.x | :x: | - -## Reporting a Vulnerability - -Report a security issue to Vermium#9649 on discord or vermium@zyner.org - -I will try to fix the vulnerability within a month, often in some days only. If vulnerability is declined then still don't abuse it in any way you can. diff --git a/prisma/.gitignore b/prisma/.gitignore new file mode 100644 index 0000000..03f6f26 --- /dev/null +++ b/prisma/.gitignore @@ -0,0 +1,2 @@ +*.db +*.db-journal \ No newline at end of file From cd3f0fcec777b332b8055ed444f7148c70f8f120 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 18:07:54 +0200 Subject: [PATCH 16/23] =?UTF-8?q?=F0=9F=99=88=20Fixed=20missing=20commit?= =?UTF-8?q?=20of=20database=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ----- src/handlers/database/index.ts | 3 +++ 2 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 src/handlers/database/index.ts diff --git a/.gitignore b/.gitignore index 1ab52e9..9fe2862 100644 --- a/.gitignore +++ b/.gitignore @@ -140,8 +140,3 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* - - -# Docker -database -docker-compose.local.yml diff --git a/src/handlers/database/index.ts b/src/handlers/database/index.ts new file mode 100644 index 0000000..287669a --- /dev/null +++ b/src/handlers/database/index.ts @@ -0,0 +1,3 @@ +import { PrismaClient } from '@prisma/client' + +export default new PrismaClient() \ No newline at end of file From dc500eb666f4ffabd8bdf83de9237fcafee56ad7 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 18:41:01 +0200 Subject: [PATCH 17/23] =?UTF-8?q?=F0=9F=9A=80=20re-enabled=20audits=20for?= =?UTF-8?q?=20interactionCreate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/interactionCreate/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index 21fa2ff..dde7ab2 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -7,6 +7,7 @@ import { import { IEventOptions } from "../../interfaces/EventOptions"; import logger from "../../middlewares/logger"; // Dependencies +import audits from "./audits"; import { handleCommandInteraction as HandlersHandleCommandInteraction } from "./handlers"; export const options: IEventOptions = { @@ -21,7 +22,7 @@ export const execute = async (interaction: BaseInteraction) => { `New interaction: ${id} in guild: ${guild?.name} (${guild?.id})` ); - // await audits.execute(interaction); + await audits.execute(interaction); switch (interaction.type) { case InteractionType.ApplicationCommand: From 23e4834836516a47e439c9712583efa44084859f Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 19:30:25 +0200 Subject: [PATCH 18/23] =?UTF-8?q?=F0=9F=A5=85=20Do=20not=20catch=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 130 ++++++++++++++++++ .../migration.sql | 130 ++++++++++++++++++ src/commands/config/modules/credits/index.ts | 63 +++++---- 3 files changed, 298 insertions(+), 25 deletions(-) create mode 100644 prisma/migrations/20221021172156_int_to_bigint/migration.sql create mode 100644 prisma/migrations/20221021172345_bigint_to_int/migration.sql diff --git a/prisma/migrations/20221021172156_int_to_bigint/migration.sql b/prisma/migrations/20221021172156_int_to_bigint/migration.sql new file mode 100644 index 0000000..187923d --- /dev/null +++ b/prisma/migrations/20221021172156_int_to_bigint/migration.sql @@ -0,0 +1,130 @@ +/* + Warnings: + + - You are about to alter the column `count` on the `GuildCounter` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `creditsEarned` on the `GuildMember` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `pointsEarned` on the `GuildMember` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `pricePerHour` on the `GuildShopRoles` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `cooldown` on the `Cooldown` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `creditsMinimumLength` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `creditsRate` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `creditsTimeout` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `creditsWorkRate` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `creditsWorkTimeout` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `pointsMinimumLength` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `pointsRate` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `pointsTimeout` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `shopRolesPricePerHour` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + - You are about to alter the column `reputationsEarned` on the `User` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. + +*/ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_GuildCounter" ( + "guildId" TEXT NOT NULL, + "channelId" TEXT NOT NULL, + "triggerWord" TEXT NOT NULL, + "count" BIGINT NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildCounter_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildCounter" ("channelId", "count", "createdAt", "guildId", "triggerWord", "updatedAt") SELECT "channelId", "count", "createdAt", "guildId", "triggerWord", "updatedAt" FROM "GuildCounter"; +DROP TABLE "GuildCounter"; +ALTER TABLE "new_GuildCounter" RENAME TO "GuildCounter"; +CREATE UNIQUE INDEX "GuildCounter_guildId_channelId_key" ON "GuildCounter"("guildId", "channelId"); +CREATE TABLE "new_GuildMember" ( + "userId" TEXT NOT NULL, + "guildId" TEXT NOT NULL, + "creditsEarned" BIGINT NOT NULL DEFAULT 0, + "pointsEarned" BIGINT NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildMember_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildMember" ("createdAt", "creditsEarned", "guildId", "pointsEarned", "updatedAt", "userId") SELECT "createdAt", "creditsEarned", "guildId", "pointsEarned", "updatedAt", "userId" FROM "GuildMember"; +DROP TABLE "GuildMember"; +ALTER TABLE "new_GuildMember" RENAME TO "GuildMember"; +CREATE UNIQUE INDEX "GuildMember_userId_guildId_key" ON "GuildMember"("userId", "guildId"); +CREATE TABLE "new_GuildShopRoles" ( + "guildId" TEXT NOT NULL, + "roleId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "pricePerHour" BIGINT NOT NULL DEFAULT 5, + "lastPayed" DATETIME NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildShopRoles_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_guildId_fkey" FOREIGN KEY ("userId", "guildId") REFERENCES "GuildMember" ("userId", "guildId") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildShopRoles" ("createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId") SELECT "createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId" FROM "GuildShopRoles"; +DROP TABLE "GuildShopRoles"; +ALTER TABLE "new_GuildShopRoles" RENAME TO "GuildShopRoles"; +CREATE UNIQUE INDEX "GuildShopRoles_guildId_userId_roleId_key" ON "GuildShopRoles"("guildId", "userId", "roleId"); +CREATE TABLE "new_Cooldown" ( + "guildId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "cooldown" BIGINT NOT NULL, + "timeoutId" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "Cooldown_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "Cooldown_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_Cooldown" ("cooldown", "createdAt", "guildId", "timeoutId", "updatedAt", "userId") SELECT "cooldown", "createdAt", "guildId", "timeoutId", "updatedAt", "userId" FROM "Cooldown"; +DROP TABLE "Cooldown"; +ALTER TABLE "new_Cooldown" RENAME TO "Cooldown"; +CREATE UNIQUE INDEX "Cooldown_guildId_userId_timeoutId_key" ON "Cooldown"("guildId", "userId", "timeoutId"); +CREATE TABLE "new_Guild" ( + "id" TEXT NOT NULL, + "embedColorSuccess" TEXT NOT NULL DEFAULT '#22bb33', + "embedColorWait" TEXT NOT NULL DEFAULT '#f0ad4e', + "embedColorError" TEXT NOT NULL DEFAULT '#bb2124', + "embedFooterText" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg/xyter', + "embedFooterIcon" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg.png', + "creditsEnabled" BOOLEAN NOT NULL DEFAULT false, + "creditsRate" BIGINT NOT NULL DEFAULT 1, + "creditsTimeout" BIGINT NOT NULL DEFAULT 5, + "creditsWorkRate" BIGINT NOT NULL DEFAULT 25, + "creditsWorkTimeout" BIGINT NOT NULL DEFAULT 86400, + "creditsMinimumLength" BIGINT NOT NULL DEFAULT 5, + "pointsEnabled" BOOLEAN NOT NULL DEFAULT false, + "pointsRate" BIGINT NOT NULL DEFAULT 1, + "pointsTimeout" BIGINT NOT NULL DEFAULT 5, + "pointsMinimumLength" BIGINT NOT NULL DEFAULT 5, + "reputationsEnabled" BOOLEAN NOT NULL DEFAULT false, + "countersEnabled" BOOLEAN NOT NULL DEFAULT false, + "apiCpggUrlIv" TEXT, + "apiCpggUrlContent" TEXT, + "apiCpggTokenIv" TEXT, + "apiCpggTokenContent" TEXT, + "auditsEnabled" BOOLEAN NOT NULL DEFAULT false, + "auditsChannelId" TEXT, + "shopRolesEnabled" BOOLEAN NOT NULL DEFAULT false, + "shopRolesPricePerHour" BIGINT NOT NULL DEFAULT 5, + "welcomeEnabled" BOOLEAN NOT NULL DEFAULT false, + "welcomeJoinChannelId" TEXT, + "welcomeJoinChannelMessage" TEXT, + "welcomeLeaveChannelId" TEXT, + "welcomeLeaveChannelMessage" TEXT, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_Guild" ("apiCpggTokenContent", "apiCpggTokenIv", "apiCpggUrlContent", "apiCpggUrlIv", "auditsChannelId", "auditsEnabled", "countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "embedColorError", "embedColorSuccess", "embedColorWait", "embedFooterIcon", "embedFooterText", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "shopRolesEnabled", "shopRolesPricePerHour", "updatedAt", "welcomeEnabled", "welcomeJoinChannelId", "welcomeJoinChannelMessage", "welcomeLeaveChannelId", "welcomeLeaveChannelMessage") SELECT "apiCpggTokenContent", "apiCpggTokenIv", "apiCpggUrlContent", "apiCpggUrlIv", "auditsChannelId", "auditsEnabled", "countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "embedColorError", "embedColorSuccess", "embedColorWait", "embedFooterIcon", "embedFooterText", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "shopRolesEnabled", "shopRolesPricePerHour", "updatedAt", "welcomeEnabled", "welcomeJoinChannelId", "welcomeJoinChannelMessage", "welcomeLeaveChannelId", "welcomeLeaveChannelMessage" FROM "Guild"; +DROP TABLE "Guild"; +ALTER TABLE "new_Guild" RENAME TO "Guild"; +CREATE UNIQUE INDEX "Guild_id_key" ON "Guild"("id"); +CREATE TABLE "new_User" ( + "id" TEXT NOT NULL, + "reputationsEarned" BIGINT NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_User" ("createdAt", "id", "reputationsEarned", "updatedAt") SELECT "createdAt", "id", "reputationsEarned", "updatedAt" FROM "User"; +DROP TABLE "User"; +ALTER TABLE "new_User" RENAME TO "User"; +CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221021172345_bigint_to_int/migration.sql b/prisma/migrations/20221021172345_bigint_to_int/migration.sql new file mode 100644 index 0000000..978ac5c --- /dev/null +++ b/prisma/migrations/20221021172345_bigint_to_int/migration.sql @@ -0,0 +1,130 @@ +/* + Warnings: + + - You are about to alter the column `reputationsEarned` on the `User` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `count` on the `GuildCounter` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `creditsEarned` on the `GuildMember` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `pointsEarned` on the `GuildMember` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `pricePerHour` on the `GuildShopRoles` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `creditsMinimumLength` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `creditsRate` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `creditsTimeout` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `creditsWorkRate` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `creditsWorkTimeout` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `pointsMinimumLength` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `pointsRate` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `pointsTimeout` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `shopRolesPricePerHour` on the `Guild` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `cooldown` on the `Cooldown` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + +*/ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_User" ( + "id" TEXT NOT NULL, + "reputationsEarned" INTEGER NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_User" ("createdAt", "id", "reputationsEarned", "updatedAt") SELECT "createdAt", "id", "reputationsEarned", "updatedAt" FROM "User"; +DROP TABLE "User"; +ALTER TABLE "new_User" RENAME TO "User"; +CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); +CREATE TABLE "new_GuildCounter" ( + "guildId" TEXT NOT NULL, + "channelId" TEXT NOT NULL, + "triggerWord" TEXT NOT NULL, + "count" INTEGER NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildCounter_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildCounter" ("channelId", "count", "createdAt", "guildId", "triggerWord", "updatedAt") SELECT "channelId", "count", "createdAt", "guildId", "triggerWord", "updatedAt" FROM "GuildCounter"; +DROP TABLE "GuildCounter"; +ALTER TABLE "new_GuildCounter" RENAME TO "GuildCounter"; +CREATE UNIQUE INDEX "GuildCounter_guildId_channelId_key" ON "GuildCounter"("guildId", "channelId"); +CREATE TABLE "new_GuildMember" ( + "userId" TEXT NOT NULL, + "guildId" TEXT NOT NULL, + "creditsEarned" INTEGER NOT NULL DEFAULT 0, + "pointsEarned" INTEGER NOT NULL DEFAULT 0, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildMember_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildMember" ("createdAt", "creditsEarned", "guildId", "pointsEarned", "updatedAt", "userId") SELECT "createdAt", "creditsEarned", "guildId", "pointsEarned", "updatedAt", "userId" FROM "GuildMember"; +DROP TABLE "GuildMember"; +ALTER TABLE "new_GuildMember" RENAME TO "GuildMember"; +CREATE UNIQUE INDEX "GuildMember_userId_guildId_key" ON "GuildMember"("userId", "guildId"); +CREATE TABLE "new_GuildShopRoles" ( + "guildId" TEXT NOT NULL, + "roleId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "pricePerHour" INTEGER NOT NULL DEFAULT 5, + "lastPayed" DATETIME NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "GuildShopRoles_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "GuildShopRoles_userId_guildId_fkey" FOREIGN KEY ("userId", "guildId") REFERENCES "GuildMember" ("userId", "guildId") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_GuildShopRoles" ("createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId") SELECT "createdAt", "guildId", "lastPayed", "pricePerHour", "roleId", "updatedAt", "userId" FROM "GuildShopRoles"; +DROP TABLE "GuildShopRoles"; +ALTER TABLE "new_GuildShopRoles" RENAME TO "GuildShopRoles"; +CREATE UNIQUE INDEX "GuildShopRoles_guildId_userId_roleId_key" ON "GuildShopRoles"("guildId", "userId", "roleId"); +CREATE TABLE "new_Guild" ( + "id" TEXT NOT NULL, + "embedColorSuccess" TEXT NOT NULL DEFAULT '#22bb33', + "embedColorWait" TEXT NOT NULL DEFAULT '#f0ad4e', + "embedColorError" TEXT NOT NULL DEFAULT '#bb2124', + "embedFooterText" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg/xyter', + "embedFooterIcon" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg.png', + "creditsEnabled" BOOLEAN NOT NULL DEFAULT false, + "creditsRate" INTEGER NOT NULL DEFAULT 1, + "creditsTimeout" INTEGER NOT NULL DEFAULT 5, + "creditsWorkRate" INTEGER NOT NULL DEFAULT 25, + "creditsWorkTimeout" INTEGER NOT NULL DEFAULT 86400, + "creditsMinimumLength" INTEGER NOT NULL DEFAULT 5, + "pointsEnabled" BOOLEAN NOT NULL DEFAULT false, + "pointsRate" INTEGER NOT NULL DEFAULT 1, + "pointsTimeout" INTEGER NOT NULL DEFAULT 5, + "pointsMinimumLength" INTEGER NOT NULL DEFAULT 5, + "reputationsEnabled" BOOLEAN NOT NULL DEFAULT false, + "countersEnabled" BOOLEAN NOT NULL DEFAULT false, + "apiCpggUrlIv" TEXT, + "apiCpggUrlContent" TEXT, + "apiCpggTokenIv" TEXT, + "apiCpggTokenContent" TEXT, + "auditsEnabled" BOOLEAN NOT NULL DEFAULT false, + "auditsChannelId" TEXT, + "shopRolesEnabled" BOOLEAN NOT NULL DEFAULT false, + "shopRolesPricePerHour" INTEGER NOT NULL DEFAULT 5, + "welcomeEnabled" BOOLEAN NOT NULL DEFAULT false, + "welcomeJoinChannelId" TEXT, + "welcomeJoinChannelMessage" TEXT, + "welcomeLeaveChannelId" TEXT, + "welcomeLeaveChannelMessage" TEXT, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_Guild" ("apiCpggTokenContent", "apiCpggTokenIv", "apiCpggUrlContent", "apiCpggUrlIv", "auditsChannelId", "auditsEnabled", "countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "embedColorError", "embedColorSuccess", "embedColorWait", "embedFooterIcon", "embedFooterText", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "shopRolesEnabled", "shopRolesPricePerHour", "updatedAt", "welcomeEnabled", "welcomeJoinChannelId", "welcomeJoinChannelMessage", "welcomeLeaveChannelId", "welcomeLeaveChannelMessage") SELECT "apiCpggTokenContent", "apiCpggTokenIv", "apiCpggUrlContent", "apiCpggUrlIv", "auditsChannelId", "auditsEnabled", "countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "embedColorError", "embedColorSuccess", "embedColorWait", "embedFooterIcon", "embedFooterText", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "shopRolesEnabled", "shopRolesPricePerHour", "updatedAt", "welcomeEnabled", "welcomeJoinChannelId", "welcomeJoinChannelMessage", "welcomeLeaveChannelId", "welcomeLeaveChannelMessage" FROM "Guild"; +DROP TABLE "Guild"; +ALTER TABLE "new_Guild" RENAME TO "Guild"; +CREATE UNIQUE INDEX "Guild_id_key" ON "Guild"("id"); +CREATE TABLE "new_Cooldown" ( + "guildId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "cooldown" INTEGER NOT NULL, + "timeoutId" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "Cooldown_guildId_fkey" FOREIGN KEY ("guildId") REFERENCES "Guild" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "Cooldown_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_Cooldown" ("cooldown", "createdAt", "guildId", "timeoutId", "updatedAt", "userId") SELECT "cooldown", "createdAt", "guildId", "timeoutId", "updatedAt", "userId" FROM "Cooldown"; +DROP TABLE "Cooldown"; +ALTER TABLE "new_Cooldown" RENAME TO "Cooldown"; +CREATE UNIQUE INDEX "Cooldown_guildId_userId_timeoutId_key" ON "Cooldown"("guildId", "userId", "timeoutId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/src/commands/config/modules/credits/index.ts b/src/commands/config/modules/credits/index.ts index e76cd77..7608bc9 100644 --- a/src/commands/config/modules/credits/index.ts +++ b/src/commands/config/modules/credits/index.ts @@ -14,41 +14,49 @@ export default { builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("credits") - .setDescription(`Credits`) + .setDescription(`Configure this guild's credits module.`) .addBooleanOption((option) => option - .setName("status") - .setDescription("Should credits be enabled?") + .setName("enabled") + .setDescription("Do you want to activate the credit module?") .setRequired(true) ) .addNumberOption((option) => option .setName("rate") - .setDescription("Amount of credits per message.") + .setDescription("Credit rate per message.") .setRequired(true) + .setMinValue(1) ) .addNumberOption((option) => option .setName("minimum-length") - .setDescription("Minimum length of message to earn credits.") + .setDescription("Minimum message length to receive credit.") .setRequired(true) ) .addNumberOption((option) => option .setName("work-rate") - .setDescription("Maximum amount of credits on work.") + .setDescription( + "The maximum amount of credit that can be obtained within a working day." + ) .setRequired(true) + .setMinValue(1) ) .addNumberOption((option) => option .setName("work-timeout") - .setDescription("Timeout between work schedules (seconds).") + .setDescription( + "How long you need to wait before you can work again provided in seconds." + ) .setRequired(true) ) .addNumberOption((option) => option .setName("timeout") - .setDescription("Timeout between earning credits (seconds).") + .setDescription( + "How long you need to wait before you can earn more credits." + ) .setRequired(true) ); }, @@ -62,27 +70,32 @@ export default { ); const { guild, options } = interaction; - const status = options?.getBoolean("status"); - const rate = options?.getNumber("rate"); - const timeout = options?.getNumber("timeout"); - const minimumLength = options?.getNumber("minimum-length"); - const workRate = options?.getNumber("work-rate"); - const workTimeout = options?.getNumber("work-timeout"); + const enabled = options.getBoolean("enabled"); + const rate = options.getNumber("rate"); + const timeout = options.getNumber("timeout"); + const minimumLength = options.getNumber("minimum-length"); + const workRate = options.getNumber("work-rate"); + const workTimeout = options.getNumber("work-timeout"); - if (!guild) throw new Error("Guild is not found"); - if (status === null) throw new Error("Status is null"); - if (!rate) throw new Error("Rate is null"); - if (!workRate) throw new Error("WorkRate is null"); - if (!workTimeout) throw new Error("WorkTimeout is null"); - if (!timeout) throw new Error("Timeout is null"); - if (!minimumLength) throw new Error("Minimum Length is null"); + if (!guild) throw new Error("Guild not found."); + if (typeof enabled !== "boolean") + throw new Error("Enabled option is not a boolean."); + if (typeof rate !== "number") throw new Error("Rate is not a number."); + if (typeof workRate !== "number") + throw new Error("Work rate is not a number."); + if (typeof workTimeout !== "number") + throw new Error("Work timeout is not a number."); + if (typeof timeout !== "number") + throw new Error("Timeout is not a number."); + if (typeof minimumLength !== "number") + throw new Error("Minimum length is not a number."); const createGuild = await prisma.guild.upsert({ where: { id: guild.id, }, update: { - creditsEnabled: status, + creditsEnabled: enabled, creditsRate: rate, creditsTimeout: timeout, creditsWorkRate: workRate, @@ -91,7 +104,7 @@ export default { }, create: { id: guild.id, - creditsEnabled: status, + creditsEnabled: enabled, creditsRate: rate, creditsTimeout: timeout, creditsWorkRate: workRate, @@ -108,7 +121,7 @@ export default { .setColor(successColor) .addFields( { - name: "🤖 Status", + name: "🤖 Enabled?", value: `${createGuild.creditsEnabled}`, inline: true, }, @@ -144,7 +157,7 @@ export default { text: footerText, }); - await interaction?.editReply({ + await interaction.editReply({ embeds: [interactionEmbed], }); return; From dab00617a28bde6077825344399993a2e7f1fb96 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 19:45:56 +0200 Subject: [PATCH 19/23] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20remove=20moduleData?= =?UTF-8?q?=20and=20metadata=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/getCommandMetadata/index.ts | 14 -------------- src/interfaces/Command.ts | 1 - 2 files changed, 15 deletions(-) delete mode 100644 src/helpers/getCommandMetadata/index.ts diff --git a/src/helpers/getCommandMetadata/index.ts b/src/helpers/getCommandMetadata/index.ts deleted file mode 100644 index 6a6a8b7..0000000 --- a/src/helpers/getCommandMetadata/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ChatInputCommandInteraction } from "discord.js"; -import { ICommand } from "../../interfaces/Command"; - -export default async ( - interaction: ChatInputCommandInteraction, - currentCommand: ICommand -) => { - const subcommand = interaction.options.getSubcommand(); - const subcommandGroup = interaction.options.getSubcommandGroup(false); - - return subcommandGroup - ? currentCommand.moduleData[subcommandGroup].moduleData[subcommand].metadata - : currentCommand.moduleData[subcommand].metadata; -}; diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts index f8a895a..5d6f870 100644 --- a/src/interfaces/Command.ts +++ b/src/interfaces/Command.ts @@ -2,6 +2,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; export interface ICommand { builder: SlashCommandBuilder; - moduleData: any; execute: Promise; } From 89b67906ec91c58dd17fe406947c68b3a035777a Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 19:50:24 +0200 Subject: [PATCH 20/23] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20JS-0356=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/modules/credits/modules/transfer/index.ts | 5 +++-- src/commands/reputation/modules/view/index.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/manage/modules/credits/modules/transfer/index.ts b/src/commands/manage/modules/credits/modules/transfer/index.ts index 488ae70..c75da60 100644 --- a/src/commands/manage/modules/credits/modules/transfer/index.ts +++ b/src/commands/manage/modules/credits/modules/transfer/index.ts @@ -42,8 +42,9 @@ export default { await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); - const { errorColor, successColor, footerText, footerIcon } = - await getEmbedConfig(interaction.guild); // Destructure member + const { successColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); // Destructure member const { guild, options } = interaction; // Get options diff --git a/src/commands/reputation/modules/view/index.ts b/src/commands/reputation/modules/view/index.ts index 0722cf3..23598a0 100644 --- a/src/commands/reputation/modules/view/index.ts +++ b/src/commands/reputation/modules/view/index.ts @@ -20,7 +20,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - const { options, user, guild } = interaction; + const { options, guild } = interaction; const { successColor, footerText, footerIcon } = await getEmbedConfig( guild From 3e5cbeb2378709e8a11d416f2b9bc76c288c210b Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 19:53:47 +0200 Subject: [PATCH 21/23] =?UTF-8?q?=F0=9F=9A=A8=20Fixed=20some=20JS-0116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/config/modules/audits/index.ts | 2 +- src/commands/config/modules/cpgg/index.ts | 2 +- src/commands/config/modules/credits/index.ts | 2 +- src/commands/config/modules/embeds/index.ts | 2 +- src/commands/config/modules/points/index.ts | 2 +- src/commands/config/modules/shop/index.ts | 2 +- src/commands/config/modules/welcome/index.ts | 2 +- src/commands/manage/modules/counters/modules/add/index.ts | 2 +- src/commands/manage/modules/counters/modules/remove/index.ts | 2 +- src/commands/manage/modules/credits/modules/give/index.ts | 2 +- .../manage/modules/credits/modules/giveaway/index.ts | 2 +- src/commands/manage/modules/credits/modules/set/index.ts | 2 +- src/commands/manage/modules/credits/modules/take/index.ts | 2 +- .../manage/modules/credits/modules/transfer/index.ts | 2 +- src/commands/moderation/modules/prune/index.ts | 5 +---- src/helpers/checkPermission/index.ts | 2 +- src/schedules/shop/modules/roles/components/dueForPayment.ts | 2 +- src/schedules/shop/modules/roles/index.ts | 2 +- 18 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/commands/config/modules/audits/index.ts b/src/commands/config/modules/audits/index.ts index a3d4c00..bc91291 100644 --- a/src/commands/config/modules/audits/index.ts +++ b/src/commands/config/modules/audits/index.ts @@ -33,7 +33,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { guild, options } = interaction; const { successColor, footerText, footerIcon } = await getEmbedConfig( diff --git a/src/commands/config/modules/cpgg/index.ts b/src/commands/config/modules/cpgg/index.ts index b9ce119..56daed8 100644 --- a/src/commands/config/modules/cpgg/index.ts +++ b/src/commands/config/modules/cpgg/index.ts @@ -42,7 +42,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/config/modules/credits/index.ts b/src/commands/config/modules/credits/index.ts index 7608bc9..70525f2 100644 --- a/src/commands/config/modules/credits/index.ts +++ b/src/commands/config/modules/credits/index.ts @@ -63,7 +63,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/config/modules/embeds/index.ts b/src/commands/config/modules/embeds/index.ts index a9e1ae9..a4c8195 100644 --- a/src/commands/config/modules/embeds/index.ts +++ b/src/commands/config/modules/embeds/index.ts @@ -48,7 +48,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { guild } = interaction; if (!guild) throw new Error("Guild not found"); diff --git a/src/commands/config/modules/points/index.ts b/src/commands/config/modules/points/index.ts index 7f89c8a..8761bbe 100644 --- a/src/commands/config/modules/points/index.ts +++ b/src/commands/config/modules/points/index.ts @@ -43,7 +43,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/config/modules/shop/index.ts b/src/commands/config/modules/shop/index.ts index fd23ac1..577867b 100644 --- a/src/commands/config/modules/shop/index.ts +++ b/src/commands/config/modules/shop/index.ts @@ -31,7 +31,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/config/modules/welcome/index.ts b/src/commands/config/modules/welcome/index.ts index 259a63f..0ac56e1 100644 --- a/src/commands/config/modules/welcome/index.ts +++ b/src/commands/config/modules/welcome/index.ts @@ -54,7 +54,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/manage/modules/counters/modules/add/index.ts b/src/commands/manage/modules/counters/modules/add/index.ts index 13399bc..9c3dafe 100644 --- a/src/commands/manage/modules/counters/modules/add/index.ts +++ b/src/commands/manage/modules/counters/modules/add/index.ts @@ -41,7 +41,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/manage/modules/counters/modules/remove/index.ts b/src/commands/manage/modules/counters/modules/remove/index.ts index dff0ec8..742ec9a 100644 --- a/src/commands/manage/modules/counters/modules/remove/index.ts +++ b/src/commands/manage/modules/counters/modules/remove/index.ts @@ -30,7 +30,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/manage/modules/credits/modules/give/index.ts b/src/commands/manage/modules/credits/modules/give/index.ts index 28d7eeb..f2c070b 100644 --- a/src/commands/manage/modules/credits/modules/give/index.ts +++ b/src/commands/manage/modules/credits/modules/give/index.ts @@ -37,7 +37,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/manage/modules/credits/modules/giveaway/index.ts b/src/commands/manage/modules/credits/modules/giveaway/index.ts index 3c2ea05..9a0518c 100644 --- a/src/commands/manage/modules/credits/modules/giveaway/index.ts +++ b/src/commands/manage/modules/credits/modules/giveaway/index.ts @@ -47,7 +47,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/manage/modules/credits/modules/set/index.ts b/src/commands/manage/modules/credits/modules/set/index.ts index e8fe3cc..10dd37f 100644 --- a/src/commands/manage/modules/credits/modules/set/index.ts +++ b/src/commands/manage/modules/credits/modules/set/index.ts @@ -37,7 +37,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); diff --git a/src/commands/manage/modules/credits/modules/take/index.ts b/src/commands/manage/modules/credits/modules/take/index.ts index 8f55ad3..9e808af 100644 --- a/src/commands/manage/modules/credits/modules/take/index.ts +++ b/src/commands/manage/modules/credits/modules/take/index.ts @@ -38,7 +38,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); // Destructure diff --git a/src/commands/manage/modules/credits/modules/transfer/index.ts b/src/commands/manage/modules/credits/modules/transfer/index.ts index c75da60..6224ec4 100644 --- a/src/commands/manage/modules/credits/modules/transfer/index.ts +++ b/src/commands/manage/modules/credits/modules/transfer/index.ts @@ -40,7 +40,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, true); - await checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); + checkPermission(interaction, PermissionsBitField.Flags.ManageGuild); const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/commands/moderation/modules/prune/index.ts b/src/commands/moderation/modules/prune/index.ts index 0245a33..3641d98 100644 --- a/src/commands/moderation/modules/prune/index.ts +++ b/src/commands/moderation/modules/prune/index.ts @@ -30,10 +30,7 @@ export default { execute: async (interaction: ChatInputCommandInteraction) => { await deferReply(interaction, false); - await checkPermission( - interaction, - PermissionsBitField.Flags.ManageMessages - ); + checkPermission(interaction, PermissionsBitField.Flags.ManageMessages); const { errorColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild diff --git a/src/helpers/checkPermission/index.ts b/src/helpers/checkPermission/index.ts index 2de1162..a14c82d 100644 --- a/src/helpers/checkPermission/index.ts +++ b/src/helpers/checkPermission/index.ts @@ -1,6 +1,6 @@ import { BaseInteraction, PermissionResolvable } from "discord.js"; -export default async ( +export default ( interaction: BaseInteraction, permission: PermissionResolvable ) => { diff --git a/src/schedules/shop/modules/roles/components/dueForPayment.ts b/src/schedules/shop/modules/roles/components/dueForPayment.ts index f87c94c..ee2eb3f 100644 --- a/src/schedules/shop/modules/roles/components/dueForPayment.ts +++ b/src/schedules/shop/modules/roles/components/dueForPayment.ts @@ -3,7 +3,7 @@ import logger from "../../../../../middlewares/logger"; import { GuildShopRoles } from "@prisma/client"; -export const execute = async (_client: Client, role: GuildShopRoles) => { +export const execute = (_client: Client, role: GuildShopRoles) => { const { roleId } = role; logger.silly(`Shop role ${roleId} is not due for payment.`); diff --git a/src/schedules/shop/modules/roles/index.ts b/src/schedules/shop/modules/roles/index.ts index 6dea00e..6b863d0 100644 --- a/src/schedules/shop/modules/roles/index.ts +++ b/src/schedules/shop/modules/roles/index.ts @@ -15,7 +15,7 @@ export const execute = async (client: Client) => { const now = new Date(); if (nextPayment > now) { - await dueForPayment.execute(client, role); + dueForPayment.execute(client, role); return; } From a510ca7513551403fbe68bc4c22680ce113aa50e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 19:56:23 +0200 Subject: [PATCH 22/23] =?UTF-8?q?=F0=9F=9A=A8=20Fixed=20some=20JS-C1003?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/credits/modules/work/index.ts | 4 ++-- src/schedules/shop/modules/roles/index.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/commands/credits/modules/work/index.ts b/src/commands/credits/modules/work/index.ts index 939ee06..a69d155 100644 --- a/src/commands/credits/modules/work/index.ts +++ b/src/commands/credits/modules/work/index.ts @@ -3,7 +3,7 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import Chance from "chance"; import { CommandInteraction, EmbedBuilder } from "discord.js"; // Models -import * as cooldown from "../../../../handlers/cooldown"; +import { command as CooldownCommand } from "../../../../handlers/cooldown"; // Configurations import getEmbedConfig from "../../../../helpers/getEmbedData"; // Helpers @@ -51,7 +51,7 @@ export default { logger.silly(createGuild); - await cooldown.command(interaction, createGuild.creditsWorkTimeout); + await CooldownCommand(interaction, createGuild.creditsWorkTimeout); const creditsEarned = chance.integer({ min: 0, diff --git a/src/schedules/shop/modules/roles/index.ts b/src/schedules/shop/modules/roles/index.ts index 6b863d0..d3c7973 100644 --- a/src/schedules/shop/modules/roles/index.ts +++ b/src/schedules/shop/modules/roles/index.ts @@ -2,8 +2,8 @@ import { Client } from "discord.js"; import prisma from "../../../../handlers/database"; -import * as dueForPayment from "./components/dueForPayment"; -import * as overDueForPayment from "./components/overDueForPayment"; +import { execute as dueForPaymentExecute } from "./components/dueForPayment"; +import { execute as overDueForPaymentExecute } from "./components/overDueForPayment"; export const execute = async (client: Client) => { const roles = await prisma.guildShopRoles.findMany(); @@ -15,13 +15,13 @@ export const execute = async (client: Client) => { const now = new Date(); if (nextPayment > now) { - dueForPayment.execute(client, role); + dueForPaymentExecute(client, role); return; } if (nextPayment < now) { - await overDueForPayment.execute(client, role); + await overDueForPaymentExecute(client, role); } } }; From 3deec31b86263ea082a0c5e492712cc700f3c53a Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 21 Oct 2022 20:00:25 +0200 Subject: [PATCH 23/23] =?UTF-8?q?=F0=9F=9A=A8=20Fixed=20some=20JS-D1001?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/config/index.ts | 1 + src/commands/counters/index.ts | 1 + src/commands/credits/index.ts | 1 + src/commands/fun/index.ts | 1 + src/commands/reputation/index.ts | 1 + src/schedules/shop/modules/roles/components/dueForPayment.ts | 1 + src/schedules/shop/modules/roles/index.ts | 1 + 7 files changed, 7 insertions(+) diff --git a/src/commands/config/index.ts b/src/commands/config/index.ts index cbaa582..0d2a3eb 100644 --- a/src/commands/config/index.ts +++ b/src/commands/config/index.ts @@ -24,6 +24,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(moduleShop.builder) .addSubcommand(moduleWelcome.builder); +// Execute function export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "audits": diff --git a/src/commands/counters/index.ts b/src/commands/counters/index.ts index edb73e2..5abd43e 100644 --- a/src/commands/counters/index.ts +++ b/src/commands/counters/index.ts @@ -12,6 +12,7 @@ export const builder = new SlashCommandBuilder() // Modules .addSubcommand(moduleView.builder); +// Execute function export const execute = async (interaction: ChatInputCommandInteraction) => { switch (interaction.options.getSubcommand()) { case "view": diff --git a/src/commands/credits/index.ts b/src/commands/credits/index.ts index a1aaad6..777d32c 100644 --- a/src/commands/credits/index.ts +++ b/src/commands/credits/index.ts @@ -19,6 +19,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(moduleTop.builder) .addSubcommand(moduleWork.builder); +// Execute function export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; diff --git a/src/commands/fun/index.ts b/src/commands/fun/index.ts index e010d5d..e4f0972 100644 --- a/src/commands/fun/index.ts +++ b/src/commands/fun/index.ts @@ -11,6 +11,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(moduleMeme.builder); +// Execute function export const execute = async (interaction: ChatInputCommandInteraction) => { const { options } = interaction; diff --git a/src/commands/reputation/index.ts b/src/commands/reputation/index.ts index d339cb2..a550a7e 100644 --- a/src/commands/reputation/index.ts +++ b/src/commands/reputation/index.ts @@ -16,6 +16,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(moduleGive.builder) .addSubcommand(moduleView.builder); +// Execute function export const execute = async (interaction: ChatInputCommandInteraction) => { if (interaction.options.getSubcommand() === "give") { await moduleGive.execute(interaction); diff --git a/src/schedules/shop/modules/roles/components/dueForPayment.ts b/src/schedules/shop/modules/roles/components/dueForPayment.ts index ee2eb3f..fd08ae7 100644 --- a/src/schedules/shop/modules/roles/components/dueForPayment.ts +++ b/src/schedules/shop/modules/roles/components/dueForPayment.ts @@ -3,6 +3,7 @@ import logger from "../../../../../middlewares/logger"; import { GuildShopRoles } from "@prisma/client"; +// Execute the dueForPayment function export const execute = (_client: Client, role: GuildShopRoles) => { const { roleId } = role; diff --git a/src/schedules/shop/modules/roles/index.ts b/src/schedules/shop/modules/roles/index.ts index d3c7973..197cecd 100644 --- a/src/schedules/shop/modules/roles/index.ts +++ b/src/schedules/shop/modules/roles/index.ts @@ -5,6 +5,7 @@ import prisma from "../../../../handlers/database"; import { execute as dueForPaymentExecute } from "./components/dueForPayment"; import { execute as overDueForPaymentExecute } from "./components/overDueForPayment"; +// Execute the roles function export const execute = async (client: Client) => { const roles = await prisma.guildShopRoles.findMany();