diff --git a/.vscode/settings.json b/.vscode/settings.json index e9ea9d9..7474dd8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -36,5 +36,8 @@ "conventionalCommits.scopes": ["git", "github", "prisma"], "[dockerfile]": { "editor.defaultFormatter": "foxundermoon.shell-format" + }, + "[sql]": { + "editor.defaultFormatter": "sqlfluff.vscode-sqlfluff" } } diff --git a/prisma/migrations/20221217150334_move_credits_earned_to_seperate_model/migration.sql b/prisma/migrations/20221217150334_move_credits_earned_to_seperate_model/migration.sql new file mode 100644 index 0000000..667d8ae --- /dev/null +++ b/prisma/migrations/20221217150334_move_credits_earned_to_seperate_model/migration.sql @@ -0,0 +1,10 @@ +-- CreateTable +CREATE TABLE `GuildMemberCredits` ( + `userId` VARCHAR(191) NOT NULL, + `guildId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `GuildMemberCredits_userId_guildId_key`(`userId`, `guildId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `GuildMemberCredits` ADD CONSTRAINT `GuildMemberCredits_userId_guildId_fkey` FOREIGN KEY (`userId`, `guildId`) REFERENCES `GuildMember`(`userId`, `guildId`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20221217150459_move_credits_earned_to_credits_module/migration.sql b/prisma/migrations/20221217150459_move_credits_earned_to_credits_module/migration.sql new file mode 100644 index 0000000..073fb79 --- /dev/null +++ b/prisma/migrations/20221217150459_move_credits_earned_to_credits_module/migration.sql @@ -0,0 +1,16 @@ +-- AlterTable + +ALTER TABLE `GuildMemberCredits` ADD COLUMN `balance` INTEGER NOT NULL DEFAULT 0; + +-- InsertInto + +INSERT INTO GuildMemberCredits (balance, userId, guildId) +SELECT creditsEarned, + userId, + guildId +FROM GuildMember; + +-- DropColumn + +ALTER TABLE GuildMember +DROP COLUMN creditsEarned; \ No newline at end of file diff --git a/prisma/migrations/20221219165454_seperate_modules_on_guild/migration.sql b/prisma/migrations/20221219165454_seperate_modules_on_guild/migration.sql new file mode 100644 index 0000000..8c452fe --- /dev/null +++ b/prisma/migrations/20221219165454_seperate_modules_on_guild/migration.sql @@ -0,0 +1,259 @@ +/* + Warnings: + + - You are about to drop the column `apiCpggTokenContent` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `apiCpggTokenIv` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `apiCpggUrlContent` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `apiCpggUrlIv` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `auditsChannelId` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `auditsEnabled` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `countersEnabled` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `creditsEnabled` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `creditsMinimumLength` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `creditsRate` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `creditsTimeout` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `creditsWorkRate` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `creditsWorkTimeout` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `embedColorError` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `embedColorSuccess` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `embedColorWait` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `embedFooterIcon` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `embedFooterText` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `pointsEnabled` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `pointsMinimumLength` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `pointsRate` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `pointsTimeout` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `reputationsEnabled` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `shopRolesEnabled` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `shopRolesPricePerHour` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `welcomeEnabled` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `welcomeJoinChannelId` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `welcomeJoinChannelMessage` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `welcomeLeaveChannelId` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the column `welcomeLeaveChannelMessage` on the `Guild` table. All the data in the column will be lost. + - You are about to drop the `GuildCounter` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropForeignKey +ALTER TABLE `GuildCounter` DROP FOREIGN KEY `GuildCounter_guildId_fkey`; + +-- AlterTable +ALTER TABLE `Guild` DROP COLUMN `apiCpggTokenContent`, + DROP COLUMN `apiCpggTokenIv`, + DROP COLUMN `apiCpggUrlContent`, + DROP COLUMN `apiCpggUrlIv`, + DROP COLUMN `auditsChannelId`, + DROP COLUMN `auditsEnabled`, + DROP COLUMN `countersEnabled`, + DROP COLUMN `creditsEnabled`, + DROP COLUMN `creditsMinimumLength`, + DROP COLUMN `creditsRate`, + DROP COLUMN `creditsTimeout`, + DROP COLUMN `creditsWorkRate`, + DROP COLUMN `creditsWorkTimeout`, + DROP COLUMN `embedColorError`, + DROP COLUMN `embedColorSuccess`, + DROP COLUMN `embedColorWait`, + DROP COLUMN `embedFooterIcon`, + DROP COLUMN `embedFooterText`, + DROP COLUMN `pointsEnabled`, + DROP COLUMN `pointsMinimumLength`, + DROP COLUMN `pointsRate`, + DROP COLUMN `pointsTimeout`, + DROP COLUMN `reputationsEnabled`, + DROP COLUMN `shopRolesEnabled`, + DROP COLUMN `shopRolesPricePerHour`, + DROP COLUMN `welcomeEnabled`, + DROP COLUMN `welcomeJoinChannelId`, + DROP COLUMN `welcomeJoinChannelMessage`, + DROP COLUMN `welcomeLeaveChannelId`, + DROP COLUMN `welcomeLeaveChannelMessage`; + +-- DropTable +DROP TABLE `GuildCounter`; + +-- CreateTable +CREATE TABLE `GuildConfigEmbeds` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `successColor` VARCHAR(191) NOT NULL DEFAULT '#22bb33', + `waitColor` VARCHAR(191) NOT NULL DEFAULT '#f0ad4e', + `errorColor` VARCHAR(191) NOT NULL DEFAULT '#bb2124', + `footerText` VARCHAR(191) NOT NULL DEFAULT 'https://github.com/ZynerOrg/xyter', + `footerIcon` VARCHAR(191) NOT NULL DEFAULT 'https://github.com/ZynerOrg.png', + + UNIQUE INDEX `GuildConfigEmbeds_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigCredits` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `status` BOOLEAN NOT NULL DEFAULT false, + `rate` INTEGER NOT NULL DEFAULT 1, + `timeout` INTEGER NOT NULL DEFAULT 5, + `workRate` INTEGER NOT NULL DEFAULT 25, + `workTimeout` INTEGER NOT NULL DEFAULT 86400, + `minimumLength` INTEGER NOT NULL DEFAULT 5, + + UNIQUE INDEX `GuildConfigCredits_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigPoints` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `status` BOOLEAN NOT NULL DEFAULT false, + `rate` INTEGER NOT NULL DEFAULT 1, + `timeout` INTEGER NOT NULL DEFAULT 5, + `minimumLength` INTEGER NOT NULL DEFAULT 5, + + UNIQUE INDEX `GuildConfigPoints_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigReputation` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `status` BOOLEAN NOT NULL DEFAULT false, + + UNIQUE INDEX `GuildConfigReputation_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigCounters` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `status` BOOLEAN NOT NULL DEFAULT false, + + UNIQUE INDEX `GuildConfigCounters_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigApis` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `guildConfigApisCpggId` VARCHAR(191) NULL, + + UNIQUE INDEX `GuildConfigApis_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigApisCpgg` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `urlIv` VARCHAR(191) NULL, + `urlContent` VARCHAR(191) NULL, + `tokenIv` VARCHAR(191) NULL, + `tokenContent` VARCHAR(191) NULL, + + UNIQUE INDEX `GuildConfigApisCpgg_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigAudits` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `status` BOOLEAN NOT NULL DEFAULT false, + `channelId` VARCHAR(191) NOT NULL, + + UNIQUE INDEX `GuildConfigAudits_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigShop` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `status` BOOLEAN NOT NULL DEFAULT false, + `guildConfigShopRolesId` VARCHAR(191) NULL, + + UNIQUE INDEX `GuildConfigShop_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigShopRoles` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `status` BOOLEAN NOT NULL DEFAULT false, + `pricePerHour` INTEGER NOT NULL DEFAULT 5, + + UNIQUE INDEX `GuildConfigShopRoles_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildConfigWelcome` ( + `id` VARCHAR(191) NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + `statis` BOOLEAN NOT NULL DEFAULT false, + `joinChannelId` VARCHAR(191) NULL, + `joinChannelMessage` VARCHAR(191) NULL, + `leaveChannelId` VARCHAR(191) NULL, + `leaveChannelMessage` VARCHAR(191) NULL, + + UNIQUE INDEX `GuildConfigWelcome_id_key`(`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `GuildCounters` ( + `guildId` VARCHAR(191) NOT NULL, + `channelId` VARCHAR(191) NOT NULL, + `triggerWord` VARCHAR(191) NOT NULL, + `count` INTEGER NOT NULL DEFAULT 0, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + + UNIQUE INDEX `GuildCounters_guildId_channelId_key`(`guildId`, `channelId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `GuildConfigEmbeds` ADD CONSTRAINT `GuildConfigEmbeds_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigCredits` ADD CONSTRAINT `GuildConfigCredits_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigPoints` ADD CONSTRAINT `GuildConfigPoints_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigReputation` ADD CONSTRAINT `GuildConfigReputation_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigCounters` ADD CONSTRAINT `GuildConfigCounters_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigApis` ADD CONSTRAINT `GuildConfigApis_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigApis` ADD CONSTRAINT `GuildConfigApis_guildConfigApisCpggId_fkey` FOREIGN KEY (`guildConfigApisCpggId`) REFERENCES `GuildConfigApisCpgg`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigApisCpgg` ADD CONSTRAINT `GuildConfigApisCpgg_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigAudits` ADD CONSTRAINT `GuildConfigAudits_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigShop` ADD CONSTRAINT `GuildConfigShop_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigShop` ADD CONSTRAINT `GuildConfigShop_guildConfigShopRolesId_fkey` FOREIGN KEY (`guildConfigShopRolesId`) REFERENCES `GuildConfigShopRoles`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigShopRoles` ADD CONSTRAINT `GuildConfigShopRoles_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildConfigWelcome` ADD CONSTRAINT `GuildConfigWelcome_id_fkey` FOREIGN KEY (`id`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `GuildCounters` ADD CONSTRAINT `GuildCounters_guildId_fkey` FOREIGN KEY (`guildId`) REFERENCES `Guild`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20221219171553_fix_typo/migration.sql b/prisma/migrations/20221219171553_fix_typo/migration.sql new file mode 100644 index 0000000..be615cc --- /dev/null +++ b/prisma/migrations/20221219171553_fix_typo/migration.sql @@ -0,0 +1,9 @@ +/* + Warnings: + + - You are about to drop the column `statis` on the `GuildConfigWelcome` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE `GuildConfigWelcome` DROP COLUMN `statis`, + ADD COLUMN `status` BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/migrations/20221219175656_remove_api_collection/migration.sql b/prisma/migrations/20221219175656_remove_api_collection/migration.sql new file mode 100644 index 0000000..f6e459f --- /dev/null +++ b/prisma/migrations/20221219175656_remove_api_collection/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - You are about to drop the `GuildConfigApis` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropForeignKey +ALTER TABLE `GuildConfigApis` DROP FOREIGN KEY `GuildConfigApis_guildConfigApisCpggId_fkey`; + +-- DropForeignKey +ALTER TABLE `GuildConfigApis` DROP FOREIGN KEY `GuildConfigApis_id_fkey`; + +-- DropTable +DROP TABLE `GuildConfigApis`; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index 9bee74d..e5a788a 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 = "mysql" +provider = "mysql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7427a82..45e7f21 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -11,56 +11,27 @@ datasource db { url = env("DATABASE_URL") } +// + model Guild { - id String @unique - guildMembers GuildMember[] - cooldowns Cooldown[] + id String @unique + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt - // Settings - embedColorSuccess String @default("#22bb33") - embedColorWait String @default("#f0ad4e") - embedColorError String @default("#bb2124") - embedFooterText String @default("https://github.com/ZynerOrg/xyter") - embedFooterIcon String @default("https://github.com/ZynerOrg.png") - - // Modules - creditsEnabled Boolean @default(false) - creditsRate Int @default(1) - creditsTimeout Int @default(5) - creditsWorkRate Int @default(25) - creditsWorkTimeout Int @default(86400) - creditsMinimumLength Int @default(5) - - pointsEnabled Boolean @default(false) - pointsRate Int @default(1) - pointsTimeout Int @default(5) - pointsMinimumLength Int @default(5) - - reputationsEnabled Boolean @default(false) - - countersEnabled Boolean @default(false) - counters GuildCounter[] - - apiCpggUrlIv String? - apiCpggUrlContent String? - apiCpggTokenIv String? - apiCpggTokenContent String? - - auditsEnabled Boolean @default(false) - auditsChannelId String? - - shopRolesEnabled Boolean @default(false) - shopRolesPricePerHour Int @default(5) - - welcomeEnabled Boolean @default(false) - welcomeJoinChannelId String? - welcomeJoinChannelMessage String? - welcomeLeaveChannelId String? - welcomeLeaveChannelMessage String? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - GuildShopRoles GuildShopRoles[] + GuildConfigEmbeds GuildConfigEmbeds? + GuildConfigCredits GuildConfigCredits? + GuildConfigPoints GuildConfigPoints? + GuildConfigReputation GuildConfigReputation? + GuildConfigCounters GuildConfigCounters? + GuildConfigApisCpgg GuildConfigApisCpgg? + GuildConfigAudits GuildConfigAudits? + GuildConfigShop GuildConfigShop? + GuildConfigShopRoles GuildConfigShopRoles? + GuildConfigWelcome GuildConfigWelcome? + GuildShopRoles GuildShopRoles[] + GuildMember GuildMember[] + Cooldown Cooldown[] + GuildCounters GuildCounters[] } model User { @@ -87,19 +58,150 @@ model GuildMember { // Settings - // Modules - creditsEarned Int @default(0) - pointsEarned Int @default(0) + pointsEarned Int @default(0) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - GuildShopRoles GuildShopRoles[] + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + GuildShopRoles GuildShopRoles[] + GuildMemberCredits GuildMemberCredits? // Unique Identifier @@unique([userId, guildId]) } -model GuildCounter { +// + +model GuildConfigEmbeds { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + successColor String @default("#22bb33") + waitColor String @default("#f0ad4e") + errorColor String @default("#bb2124") + footerText String @default("https://github.com/ZynerOrg/xyter") + footerIcon String @default("https://github.com/ZynerOrg.png") +} + +model GuildConfigCredits { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) + rate Int @default(1) + timeout Int @default(5) + workRate Int @default(25) + workTimeout Int @default(86400) + minimumLength Int @default(5) +} + +model GuildConfigPoints { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) + rate Int @default(1) + timeout Int @default(5) + minimumLength Int @default(5) +} + +model GuildConfigReputation { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) +} + +model GuildConfigCounters { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) +} + +model GuildConfigApisCpgg { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + urlIv String? + urlContent String? + tokenIv String? + tokenContent String? +} + +model GuildConfigAudits { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) + channelId String +} + +model GuildConfigShop { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) + roles GuildConfigShopRoles? @relation(fields: [guildConfigShopRolesId], references: [id]) + guildConfigShopRolesId String? +} + +model GuildConfigShopRoles { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) + pricePerHour Int @default(5) + GuildConfigShop GuildConfigShop[] +} + +model GuildConfigWelcome { + id String @unique + guild Guild @relation(fields: [id], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + status Boolean @default(false) + joinChannelId String? + joinChannelMessage String? + leaveChannelId String? + leaveChannelMessage String? +} + +/////////////////////////////////////// +/////////////////////////////////////// +/////////////////////////////////////// +/////////////////////////////////////// +/////////////////////////////////////// + +model GuildCounters { guildId String channelId String triggerWord String @@ -112,6 +214,17 @@ model GuildCounter { @@unique([guildId, channelId]) } +model GuildMemberCredits { + userId String + guildId String + + GuildMember GuildMember @relation(fields: [userId, guildId], references: [userId, guildId]) + + balance Int @default(0) + + @@unique([userId, guildId]) +} + model Cooldown { guild Guild @relation(fields: [guildId], references: [id]) user User @relation(fields: [userId], references: [id]) diff --git a/src/commands/config/subcommands/audits/index.ts b/src/commands/config/subcommands/audits/index.ts index 843c2db..b54de5c 100644 --- a/src/commands/config/subcommands/audits/index.ts +++ b/src/commands/config/subcommands/audits/index.ts @@ -44,18 +44,18 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (!channel) throw new Error("Channel not found."); if (status === null) throw new Error("Status not found."); - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigAudits.upsert({ where: { id: guild.id, }, update: { - auditsEnabled: status, - auditsChannelId: channel.id, + status: status, + channelId: channel.id, }, create: { id: guild.id, - auditsEnabled: status, - auditsChannelId: channel.id, + status: status, + channelId: channel.id, }, }); @@ -69,15 +69,13 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { { name: "πŸ€– Status", value: `${ - createGuild.auditsEnabled - ? ":white_check_mark: Enabled" - : ":x: Disabled" + createGuild.status ? ":white_check_mark: Enabled" : ":x: Disabled" }`, inline: true, }, { name: "🌊 Channel", - value: `<#${createGuild.auditsChannelId}>`, + value: `<#${createGuild.channelId}>`, inline: true, } ) diff --git a/src/commands/config/subcommands/cpgg/index.ts b/src/commands/config/subcommands/cpgg/index.ts index 04928b0..286c77c 100644 --- a/src/commands/config/subcommands/cpgg/index.ts +++ b/src/commands/config/subcommands/cpgg/index.ts @@ -59,22 +59,22 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (!token) throw new Error("Token not found"); if (!url) throw new Error("URL not found"); - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigApisCpgg.upsert({ where: { id: guild.id, }, update: { - apiCpggTokenIv: token.iv, - apiCpggTokenContent: token.content, - apiCpggUrlIv: url.iv, - apiCpggUrlContent: url.content, + tokenIv: token.iv, + tokenContent: token.content, + urlIv: url.iv, + urlContent: url.content, }, create: { id: guild.id, - apiCpggTokenIv: token.iv, - apiCpggTokenContent: token.content, - apiCpggUrlIv: url.iv, - apiCpggUrlContent: url.content, + tokenIv: token.iv, + tokenContent: token.content, + urlIv: url.iv, + urlContent: url.content, }, }); diff --git a/src/commands/config/subcommands/credits/index.ts b/src/commands/config/subcommands/credits/index.ts index f69f208..ab2d094 100644 --- a/src/commands/config/subcommands/credits/index.ts +++ b/src/commands/config/subcommands/credits/index.ts @@ -89,26 +89,26 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (typeof minimumLength !== "number") throw new Error("Minimum length is not a number."); - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigCredits.upsert({ where: { id: guild.id, }, update: { - creditsEnabled: enabled, - creditsRate: rate, - creditsTimeout: timeout, - creditsWorkRate: workRate, - creditsWorkTimeout: workTimeout, - creditsMinimumLength: minimumLength, + status: enabled, + rate: rate, + timeout: timeout, + workRate: workRate, + workTimeout: workTimeout, + minimumLength: minimumLength, }, create: { id: guild.id, - creditsEnabled: enabled, - creditsRate: rate, - creditsTimeout: timeout, - creditsWorkRate: workRate, - creditsWorkTimeout: workTimeout, - creditsMinimumLength: minimumLength, + status: enabled, + rate: rate, + timeout: timeout, + workRate: workRate, + workTimeout: workTimeout, + minimumLength: minimumLength, }, }); @@ -121,32 +121,32 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .addFields( { name: "πŸ€– Enabled?", - value: `${createGuild.creditsEnabled}`, + value: `${createGuild.status}`, inline: true, }, { name: "πŸ“ˆ Rate", - value: `${createGuild.creditsRate}`, + value: `${createGuild.rate}`, inline: true, }, { name: "πŸ“ˆ Work Rate", - value: `${createGuild.creditsWorkRate}`, + value: `${createGuild.workRate}`, inline: true, }, { name: "πŸ”¨ Minimum Length", - value: `${createGuild.creditsMinimumLength}`, + value: `${createGuild.minimumLength}`, inline: true, }, { name: "⏰ Timeout", - value: `${createGuild.creditsTimeout}`, + value: `${createGuild.timeout}`, inline: true, }, { name: "⏰ Work Timeout", - value: `${createGuild.creditsWorkTimeout}`, + value: `${createGuild.workTimeout}`, inline: true, } ) diff --git a/src/commands/config/subcommands/embeds/components/getValues/index.ts b/src/commands/config/subcommands/embeds/components/getValues/index.ts index ae35157..1a68813 100644 --- a/src/commands/config/subcommands/embeds/components/getValues/index.ts +++ b/src/commands/config/subcommands/embeds/components/getValues/index.ts @@ -23,34 +23,34 @@ export default async (interaction: ChatInputCommandInteraction) => { if (!newFooterIcon) throw new Error("Footer icon not found"); if (!newFooterText) throw new Error("Footer text not found"); - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigEmbeds.upsert({ where: { id: guild.id, }, update: { - embedColorSuccess: newSuccessColor, - embedColorWait: newWaitColor, - embedColorError: newErrorColor, - embedFooterIcon: newFooterIcon, - embedFooterText: newFooterText, + successColor: newSuccessColor, + waitColor: newWaitColor, + errorColor: newErrorColor, + footerIcon: newFooterIcon, + footerText: newFooterText, }, create: { id: guild.id, - embedColorSuccess: newSuccessColor, - embedColorWait: newWaitColor, - embedColorError: newErrorColor, - embedFooterIcon: newFooterIcon, - embedFooterText: newFooterText, + successColor: newSuccessColor, + waitColor: newWaitColor, + errorColor: newErrorColor, + footerIcon: newFooterIcon, + footerText: newFooterText, }, }); logger.silly(createGuild); - const successColor = createGuild.embedColorSuccess; - const waitColor = createGuild.embedColorWait; - const errorColor = createGuild.embedColorError; - const footerText = createGuild.embedFooterText; - const footerIcon = createGuild.embedFooterIcon; + const successColor = createGuild.successColor; + const waitColor = createGuild.waitColor; + const errorColor = createGuild.errorColor; + const footerText = createGuild.footerText; + const footerIcon = createGuild.footerIcon; return { successColor, waitColor, errorColor, footerText, footerIcon }; }; diff --git a/src/commands/config/subcommands/points/index.ts b/src/commands/config/subcommands/points/index.ts index e7d206b..5db7845 100644 --- a/src/commands/config/subcommands/points/index.ts +++ b/src/commands/config/subcommands/points/index.ts @@ -62,22 +62,22 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (!timeout) throw new Error("Timeout must be specified"); if (!minimumLength) throw new Error("Minimum length must be specified"); - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigPoints.upsert({ where: { id: guild.id, }, update: { - pointsEnabled: status, - pointsRate: rate, - pointsTimeout: timeout, - pointsMinimumLength: minimumLength, + status: status, + rate: rate, + timeout: timeout, + minimumLength: minimumLength, }, create: { id: guild.id, - pointsEnabled: status, - pointsRate: rate, - pointsTimeout: timeout, - pointsMinimumLength: minimumLength, + status: status, + rate: rate, + timeout: timeout, + minimumLength: minimumLength, }, }); @@ -90,22 +90,22 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .addFields( { name: "πŸ€– Status", - value: `${createGuild.pointsEnabled}`, + value: `${createGuild.status}`, inline: true, }, { name: "πŸ“ˆ Rate", - value: `${createGuild.pointsRate}`, + value: `${createGuild.rate}`, inline: true, }, { name: "πŸ”¨ Minimum Length", - value: `${createGuild.pointsMinimumLength}`, + value: `${createGuild.minimumLength}`, inline: true, }, { name: "⏰ Timeout", - value: `${createGuild.pointsTimeout}`, + value: `${createGuild.timeout}`, inline: true, } ) diff --git a/src/commands/config/subcommands/shop/index.ts b/src/commands/config/subcommands/shop/index.ts index d3f6ec1..a3eebb4 100644 --- a/src/commands/config/subcommands/shop/index.ts +++ b/src/commands/config/subcommands/shop/index.ts @@ -46,18 +46,18 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (!rolesPricePerHour) throw new Error("Roles price per hour must be provided"); - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigShopRoles.upsert({ where: { id: guild.id, }, update: { - shopRolesEnabled: rolesStatus, - shopRolesPricePerHour: rolesPricePerHour, + status: rolesStatus, + pricePerHour: rolesPricePerHour, }, create: { id: guild.id, - shopRolesEnabled: rolesStatus, - shopRolesPricePerHour: rolesPricePerHour, + status: rolesStatus, + pricePerHour: rolesPricePerHour, }, }); @@ -70,12 +70,12 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .addFields( { name: "πŸ€– Roles Status", - value: `${createGuild.shopRolesEnabled}`, + value: `${createGuild.status}`, inline: true, }, { name: "🌊 Roles Price Per Hour", - value: `${createGuild.shopRolesPricePerHour}`, + value: `${createGuild.pricePerHour}`, inline: true, } ) diff --git a/src/commands/config/subcommands/welcome/index.ts b/src/commands/config/subcommands/welcome/index.ts index 73c4262..69e9a94 100644 --- a/src/commands/config/subcommands/welcome/index.ts +++ b/src/commands/config/subcommands/welcome/index.ts @@ -76,24 +76,24 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (!leaveChannelMessage) throw new Error("Leave channel message not specified"); - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigWelcome.upsert({ where: { id: guild.id, }, update: { - welcomeEnabled: status, - welcomeJoinChannelId: joinChannel.id, - welcomeJoinChannelMessage: joinChannelMessage, - welcomeLeaveChannelId: leaveChannel.id, - welcomeLeaveChannelMessage: leaveChannelMessage, + status: status, + joinChannelId: joinChannel.id, + joinChannelMessage: joinChannelMessage, + leaveChannelId: leaveChannel.id, + leaveChannelMessage: leaveChannelMessage, }, create: { id: guild.id, - welcomeEnabled: status, - welcomeJoinChannelId: joinChannel.id, - welcomeJoinChannelMessage: joinChannelMessage, - welcomeLeaveChannelId: leaveChannel.id, - welcomeLeaveChannelMessage: leaveChannelMessage, + status: status, + joinChannelId: joinChannel.id, + joinChannelMessage: joinChannelMessage, + leaveChannelId: leaveChannel.id, + leaveChannelMessage: leaveChannelMessage, }, }); @@ -111,7 +111,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { text: footerText, }); - if (!createGuild.welcomeEnabled) { + if (!createGuild.status) { return interaction?.editReply({ embeds: [interactionEmbedDisabled], }); @@ -124,13 +124,13 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { [πŸ‘‹] **Welcome** - γ…€**Channel**: <#${createGuild.welcomeJoinChannelId}> - γ…€**Message**: ${createGuild.welcomeJoinChannelMessage} + γ…€**Channel**: <#${createGuild.joinChannelId}> + γ…€**Message**: ${createGuild.joinChannelMessage} [πŸšͺ] **Leave** - γ…€**Channel**: <#${createGuild.welcomeLeaveChannelId}> - γ…€**Message**: ${createGuild.welcomeLeaveChannelMessage}` + γ…€**Channel**: <#${createGuild.leaveChannelId}> + γ…€**Message**: ${createGuild.leaveChannelMessage}` ) .setColor(successColor) .setTimestamp() diff --git a/src/commands/counters/subcommands/view/index.ts b/src/commands/counters/subcommands/view/index.ts index f62ccfb..9a6fb11 100644 --- a/src/commands/counters/subcommands/view/index.ts +++ b/src/commands/counters/subcommands/view/index.ts @@ -42,7 +42,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { const EmbedSuccess = await BaseEmbedSuccess(guild, "[:1234:] View"); // 5. Get counter from database. - const channelCounter = await prisma.guildCounter.findUnique({ + const channelCounter = await prisma.guildCounters.findUnique({ where: { guildId_channelId: { guildId: guild.id, diff --git a/src/commands/credits/subcommands/balance/index.ts b/src/commands/credits/subcommands/balance/index.ts index 60c17c6..76b5385 100644 --- a/src/commands/credits/subcommands/balance/index.ts +++ b/src/commands/credits/subcommands/balance/index.ts @@ -33,7 +33,7 @@ export const execute = async (interaction: CommandInteraction) => { const EmbedSuccess = await BaseEmbedSuccess(guild, ":credit_card:οΈ±Balance"); // 5. Upsert the user in the database. - const createGuildMember = await prisma.guildMember.upsert({ + const createGuildMember = await prisma.guildMemberCredits.upsert({ where: { userId_guildId: { userId: (target || user).id, @@ -42,32 +42,24 @@ export const execute = async (interaction: CommandInteraction) => { }, update: {}, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: (target || user).id, + userId: (target || user).id, + guildId: guild.id, }, where: { - id: (target || user).id, - }, - }, - }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, + userId_guildId: { + userId: (target || user).id, + guildId: guild.id, + }, }, }, }, }, - include: { - user: true, - guild: true, - }, + include: { GuildMember: true }, }); + logger.silly(createGuildMember); // 6. Send embed. @@ -75,8 +67,8 @@ export const execute = async (interaction: CommandInteraction) => { embeds: [ EmbedSuccess.setDescription( target - ? `${target} has ${createGuildMember.creditsEarned} coins in his account.` - : `You have ${createGuildMember.creditsEarned} coins in your account.` + ? `${target} has ${createGuildMember.balance} coins in his account.` + : `You have ${createGuildMember.balance} coins in your account.` ), ], }); diff --git a/src/commands/credits/subcommands/gift/index.ts b/src/commands/credits/subcommands/gift/index.ts index e21d9c9..57c52e5 100644 --- a/src/commands/credits/subcommands/gift/index.ts +++ b/src/commands/credits/subcommands/gift/index.ts @@ -62,7 +62,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { // 5. Start an transaction of the credits. await creditsTransfer(guild, user, account, credits); - const receiverGuildMember = await prisma.guildMember.upsert({ + const receiverGuildMember = await prisma.guildMemberCredits.upsert({ where: { userId_guildId: { userId: account.id, @@ -71,30 +71,23 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, update: {}, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: account.id, + userId: account.id, + guildId: guild.id, }, where: { - id: account.id, - }, - }, - }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, + userId_guildId: { + userId: account.id, + guildId: guild.id, + }, }, }, }, }, include: { - user: true, - guild: true, + GuildMember: true, }, }); logger.silly(receiverGuildMember); @@ -105,12 +98,12 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { await account.send({ embeds: [ receiverEmbed.setDescription( - `You received a gift containing ${credits} coins from ${user}! You now have ${receiverGuildMember.creditsEarned} coins in balance!` + `You received a gift containing ${credits} coins from ${user}! You now have ${receiverGuildMember.balance} coins in balance!` ), ], }); - const senderGuildMember = await prisma.guildMember.upsert({ + const senderGuildMember = await prisma.guildMemberCredits.upsert({ where: { userId_guildId: { userId: user.id, @@ -119,30 +112,23 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, update: {}, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: user.id, + userId: account.id, + guildId: guild.id, }, where: { - id: user.id, - }, - }, - }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, + userId_guildId: { + userId: account.id, + guildId: guild.id, + }, }, }, }, }, include: { - user: true, - guild: true, + GuildMember: true, }, }); logger.silly(senderGuildMember); @@ -158,7 +144,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { await interaction.editReply({ embeds: [ senderEmbed.setDescription( - `Your gift has been sent to ${account}. You now have ${senderGuildMember.creditsEarned} coins in balance!` + `Your gift has been sent to ${account}. You now have ${senderGuildMember.balance} coins in balance!` ), ], }); diff --git a/src/commands/credits/subcommands/top/index.ts b/src/commands/credits/subcommands/top/index.ts index 52444e2..7e6e016 100644 --- a/src/commands/credits/subcommands/top/index.ts +++ b/src/commands/credits/subcommands/top/index.ts @@ -1,4 +1,4 @@ -import { GuildMember } from "@prisma/client"; +import { GuildMemberCredits } from "@prisma/client"; import { CommandInteraction, SlashCommandSubcommandBuilder, @@ -29,21 +29,21 @@ export const execute = async (interaction: CommandInteraction) => { const EmbedSuccess = await BaseEmbedSuccess(guild, "[:dollar:] Top"); // 4. Get the top 10 users. - const topTen = await prisma.guildMember.findMany({ + const topTen = await prisma.guildMemberCredits.findMany({ where: { guildId: guild.id, }, orderBy: { - creditsEarned: "desc", + balance: "desc", }, take: 10, }); logger.silly(topTen); // 5. Create the top 10 list. - const entry = (guildMember: GuildMember, index: number) => - `${index + 1}. ${userMention(guildMember.userId)} | :coin: ${ - guildMember.creditsEarned + const entry = (guildMemberCredits: GuildMemberCredits, index: number) => + `${index + 1}. ${userMention(guildMemberCredits.userId)} | :coin: ${ + guildMemberCredits.balance }`; // 6. Send embed diff --git a/src/commands/credits/subcommands/work/index.ts b/src/commands/credits/subcommands/work/index.ts index 980e207..ed60419 100644 --- a/src/commands/credits/subcommands/work/index.ts +++ b/src/commands/credits/subcommands/work/index.ts @@ -30,7 +30,7 @@ export const execute = async (interaction: CommandInteraction) => { const chance = new Chance(); // 5. Upsert the guild in the database. - const createGuild = await prisma.guild.upsert({ + const createGuild = await prisma.guildConfigCredits.upsert({ where: { id: guild.id, }, @@ -43,12 +43,12 @@ export const execute = async (interaction: CommandInteraction) => { if (!createGuild) throw new Error("Guild not found"); // 6. Create a cooldown for the user. - await cooldown(guild, user, commandId, createGuild.creditsWorkTimeout); + await cooldown(guild, user, commandId, createGuild.workTimeout); // 6. Generate a random number between 0 and creditsWorkRate. const creditsEarned = chance.integer({ min: 0, - max: createGuild.creditsWorkRate, + max: createGuild.workRate, }); const upsertGuildMember = await creditsGive(guild, user, creditsEarned); @@ -57,7 +57,7 @@ export const execute = async (interaction: CommandInteraction) => { await interaction.editReply({ embeds: [ EmbedSuccess.setDescription( - `You worked and earned **${creditsEarned}** credits! You now have **${upsertGuildMember.creditsEarned}** credits. :tada:` + `You worked and earned **${creditsEarned}** credits! You now have **${upsertGuildMember.balance}** credits. :tada:` ), ], }); diff --git a/src/commands/manage/groups/counters/subcommands/add/index.ts b/src/commands/manage/groups/counters/subcommands/add/index.ts index 6915c3f..a20e48c 100644 --- a/src/commands/manage/groups/counters/subcommands/add/index.ts +++ b/src/commands/manage/groups/counters/subcommands/add/index.ts @@ -56,7 +56,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (!discordChannel) throw new Error("We could not find a channel"); if (!triggerWord) throw new Error("We could not find a word"); - const channelCounter = await prisma.guildCounter.findUnique({ + const channelCounter = await prisma.guildCounters.findUnique({ where: { guildId_channelId: { guildId: guild.id, @@ -68,7 +68,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (channelCounter) throw new Error("A counter already exists for this channel."); - const createGuildCounter = await prisma.guildCounter.upsert({ + const createGuildCounter = await prisma.guildCounters.upsert({ where: { guildId_channelId: { guildId: guild.id, diff --git a/src/commands/manage/groups/counters/subcommands/remove/index.ts b/src/commands/manage/groups/counters/subcommands/remove/index.ts index ce83c43..a022b59 100644 --- a/src/commands/manage/groups/counters/subcommands/remove/index.ts +++ b/src/commands/manage/groups/counters/subcommands/remove/index.ts @@ -47,7 +47,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .setTimestamp(new Date()) .setFooter({ text: footerText, iconURL: footerIcon }); - const channelCounter = await prisma.guildCounter.findUnique({ + const channelCounter = await prisma.guildCounters.findUnique({ where: { guildId_channelId: { guildId: guild.id, @@ -61,7 +61,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { "There is no counter sin this channel, please add one first." ); - const deleteGuildCounter = await prisma.guildCounter.deleteMany({ + const deleteGuildCounter = await prisma.guildCounters.deleteMany({ where: { guildId: guild.id, channelId: discordChannel.id, diff --git a/src/commands/manage/groups/credits/subcommands/giveaway/index.ts b/src/commands/manage/groups/credits/subcommands/giveaway/index.ts index dff104a..66f48c2 100644 --- a/src/commands/manage/groups/credits/subcommands/giveaway/index.ts +++ b/src/commands/manage/groups/credits/subcommands/giveaway/index.ts @@ -70,25 +70,12 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { const code = uuidv4(); - const createGuildMember = await prisma.guildMember.upsert({ + const createGuildMember = await prisma.guildConfigApisCpgg.upsert({ where: { - userId_guildId: { - userId: user.id, - guildId: guild.id, - }, + id: guild.id, }, update: {}, create: { - user: { - connectOrCreate: { - create: { - id: user.id, - }, - where: { - id: user.id, - }, - }, - }, guild: { connectOrCreate: { create: { @@ -101,35 +88,28 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, }, include: { - user: true, guild: true, }, }); logger.silly(createGuildMember); - if ( - !createGuildMember.guild.apiCpggUrlIv || - !createGuildMember.guild.apiCpggUrlContent - ) + if (!createGuildMember.urlIv || !createGuildMember.urlContent) throw new Error("No API url available"); - if ( - !createGuildMember.guild.apiCpggTokenIv || - !createGuildMember.guild.apiCpggTokenContent - ) + if (!createGuildMember.tokenIv || !createGuildMember.tokenContent) throw new Error("No API token available"); const url = encryption.decrypt({ - iv: createGuildMember.guild.apiCpggUrlIv, - content: createGuildMember.guild.apiCpggUrlContent, + iv: createGuildMember.urlIv, + content: createGuildMember.urlContent, }); const api = axios?.create({ baseURL: `${url}/api/`, headers: { Authorization: `Bearer ${encryption.decrypt({ - iv: createGuildMember.guild.apiCpggTokenIv, - content: createGuildMember.guild.apiCpggTokenContent, + iv: createGuildMember.tokenIv, + content: createGuildMember.tokenContent, })}`, }, }); diff --git a/src/commands/shop/groups/roles/index.ts b/src/commands/shop/groups/roles/index.ts index 7e43e0c..5615773 100644 --- a/src/commands/shop/groups/roles/index.ts +++ b/src/commands/shop/groups/roles/index.ts @@ -34,12 +34,12 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { if (!interaction.guild) return; const { options, guild } = interaction; - const getGuild = await prisma.guild.findUnique({ + const getGuildConfigShopRoles = await prisma.guildConfigShopRoles.findUnique({ where: { id: guild.id }, }); - if (!getGuild) throw new Error("Guild not found"); + if (!getGuildConfigShopRoles) throw new Error("Guild not found"); - if (!getGuild.shopRolesEnabled) + if (!getGuildConfigShopRoles.status) throw new Error("This server has disabled shop roles."); if (options?.getSubcommand() === "buy") { diff --git a/src/commands/shop/groups/roles/subcommands/buy/index.ts b/src/commands/shop/groups/roles/subcommands/buy/index.ts index 5a59720..a5fd55b 100644 --- a/src/commands/shop/groups/roles/subcommands/buy/index.ts +++ b/src/commands/shop/groups/roles/subcommands/buy/index.ts @@ -96,10 +96,35 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { logger.silly(createGuildMember); - // Get guild object - const pricePerHour = createGuildMember.guild.shopRolesPricePerHour; + const upsertGuildConfigShopRoles = + await prisma.guildConfigShopRoles.upsert({ + where: { + id: guildId, + }, + update: {}, + create: { + guild: { + connectOrCreate: { + create: { + id: guildId, + }, + where: { + id: guildId, + }, + }, + }, + }, + include: { + guild: true, + }, + }); - const updateGuildMember = await prisma.guildMember.update({ + logger.silly(upsertGuildConfigShopRoles); + + // Get guild object + const pricePerHour = upsertGuildConfigShopRoles.pricePerHour; + + const updateGuildMember = await prisma.guildMemberCredits.update({ where: { userId_guildId: { userId, @@ -107,7 +132,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, }, data: { - creditsEarned: { decrement: pricePerHour }, + balance: { decrement: pricePerHour }, }, }); diff --git a/src/commands/shop/groups/roles/subcommands/cancel/index.ts b/src/commands/shop/groups/roles/subcommands/cancel/index.ts index 80ff1cd..eeb5e9a 100644 --- a/src/commands/shop/groups/roles/subcommands/cancel/index.ts +++ b/src/commands/shop/groups/roles/subcommands/cancel/index.ts @@ -57,7 +57,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { await guild?.roles .delete(optionRole?.id, `${user?.id} canceled from shop`) .then(async () => { - const createGuildMember = await prisma.guildMember.upsert({ + const createGuildMember = await prisma.guildMemberCredits.upsert({ where: { userId_guildId: { userId: user.id, @@ -66,30 +66,23 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, update: {}, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: user.id, + userId: user.id, + guildId: guild.id, }, where: { - id: user.id, - }, - }, - }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, + userId_guildId: { + userId: user.id, + guildId: guild.id, + }, }, }, }, }, include: { - user: true, - guild: true, + GuildMember: true, }, }); @@ -116,7 +109,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .setColor(successColor) .addFields({ name: "Your balance", - value: `${pluralize(createGuildMember.creditsEarned, "credit")}`, + value: `${pluralize(createGuildMember.balance, "credit")}`, }) .setFooter({ text: footerText, iconURL: footerIcon }); return interaction?.editReply({ diff --git a/src/commands/shop/subcommands/cpgg/index.ts b/src/commands/shop/subcommands/cpgg/index.ts index 0fedae7..85e3269 100644 --- a/src/commands/shop/subcommands/cpgg/index.ts +++ b/src/commands/shop/subcommands/cpgg/index.ts @@ -48,7 +48,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { } if (!guild) throw new Error("Guild not found"); - const createGuildMember = await prisma.guildMember.upsert({ + const upsertGuildMemberCredits = await prisma.guildMemberCredits.upsert({ where: { userId_guildId: { userId: user.id, @@ -57,16 +57,32 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, update: {}, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: user.id, + userId: user.id, + guildId: guild.id, }, where: { - id: user.id, + userId_guildId: { + userId: user.id, + guildId: guild.id, + }, }, }, }, + }, + }); + + if (!upsertGuildMemberCredits) + throw new Error("upsertGuildMemberCredits unavailable"); + + const upsertGuildConfigApisCpgg = await prisma.guildConfigApisCpgg.upsert({ + where: { + id: guild.id, + }, + update: {}, + create: { guild: { connectOrCreate: { create: { @@ -79,47 +95,43 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, }, include: { - user: true, guild: true, }, }); - logger.silly(createGuildMember); + logger.silly(upsertGuildMemberCredits); const dmUser = client?.users?.cache?.get(user?.id); - if ((optionAmount || createGuildMember.creditsEarned) < 100) + if ((optionAmount || upsertGuildMemberCredits.balance) < 100) throw new Error("You can't withdraw to CPGG below 100 credits."); - if ((optionAmount || createGuildMember.creditsEarned) > 1000000) + if ((optionAmount || upsertGuildMemberCredits.balance) > 1000000) throw new Error("Amount or user credits is above 1.000.000."); - if (createGuildMember.creditsEarned < optionAmount) + if (upsertGuildMemberCredits.balance < optionAmount) throw new Error("You can't withdraw more than you have on your account."); - if ( - !createGuildMember.guild.apiCpggUrlIv || - !createGuildMember.guild.apiCpggUrlContent - ) + if (!upsertGuildConfigApisCpgg.urlIv || !upsertGuildConfigApisCpgg.urlContent) throw new Error("No API url available"); if ( - !createGuildMember.guild.apiCpggTokenIv || - !createGuildMember.guild.apiCpggTokenContent + !upsertGuildConfigApisCpgg.tokenIv || + !upsertGuildConfigApisCpgg.tokenContent ) throw new Error("No API token available"); const code = uuidv4(); const url = encryption.decrypt({ - iv: createGuildMember.guild.apiCpggUrlIv, - content: createGuildMember.guild.apiCpggUrlContent, + iv: upsertGuildConfigApisCpgg.urlIv, + content: upsertGuildConfigApisCpgg.urlContent, }); const api = axios?.create({ baseURL: `${url}/api/`, headers: { Authorization: `Bearer ${encryption.decrypt({ - iv: createGuildMember.guild.apiCpggTokenIv, - content: createGuildMember.guild.apiCpggTokenContent, + iv: upsertGuildConfigApisCpgg.tokenIv, + content: upsertGuildConfigApisCpgg.tokenContent, })}`, }, }); @@ -131,19 +143,20 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .setEmoji("🏦") .setURL(`${shopUrl}?voucher=${code}`) ); + await api ?.post("vouchers", { uses: 1, code, - credits: optionAmount || createGuildMember.creditsEarned, + credits: optionAmount || upsertGuildMemberCredits.balance, memo: `${interaction?.createdTimestamp} - ${interaction?.user?.id}`, }) ?.then(async () => { logger?.silly(`Successfully created voucher.`); - createGuildMember.creditsEarned -= - optionAmount || createGuildMember.creditsEarned; + upsertGuildMemberCredits.balance -= + optionAmount || upsertGuildMemberCredits.balance; - const updateGuildMember = await prisma.guildMember.update({ + const updateGuildMember = await prisma.guildMemberCredits.update({ where: { userId_guildId: { userId: user.id, @@ -151,8 +164,8 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { }, }, data: { - creditsEarned: { - decrement: optionAmount || createGuildMember.creditsEarned, + balance: { + decrement: optionAmount || upsertGuildMemberCredits.balance, }, }, }); @@ -168,7 +181,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { .setTimestamp() .addFields({ name: "πŸ’Ά Credits", - value: `${optionAmount || createGuildMember.creditsEarned}`, + value: `${optionAmount || upsertGuildMemberCredits.balance}`, inline: true, }) .setColor(successColor) diff --git a/src/events/guildMemberAdd/joinMessage.ts b/src/events/guildMemberAdd/joinMessage.ts index 57703fb..9be7fbd 100644 --- a/src/events/guildMemberAdd/joinMessage.ts +++ b/src/events/guildMemberAdd/joinMessage.ts @@ -1,6 +1,7 @@ import { ChannelType, EmbedBuilder, GuildMember } from "discord.js"; import prisma from "../../handlers/database"; import getEmbedConfig from "../../helpers/getEmbedData"; +import logger from "../../middlewares/logger"; export default { execute: async (member: GuildMember) => { @@ -8,19 +9,19 @@ export default { member.guild ); - const getGuild = await prisma.guild.findUnique({ + const getGuildConfigWelcome = await prisma.guildConfigWelcome.findUnique({ where: { id: member.guild.id }, }); - if (!getGuild) throw new Error("Guild not found"); + if (!getGuildConfigWelcome) return logger.verbose("Guild not found"); const { client } = member; - if (getGuild.welcomeEnabled !== true) return; - if (!getGuild.welcomeJoinChannelId) return; + if (getGuildConfigWelcome.status !== true) return; + if (!getGuildConfigWelcome.joinChannelId) return; const channel = client.channels.cache.get( - `${getGuild.welcomeJoinChannelId}` + `${getGuildConfigWelcome.joinChannelId}` ); if (!channel) throw new Error("Channel not found"); @@ -34,7 +35,7 @@ export default { .setTitle(`${member.user.username} has joined the server!`) .setThumbnail(member.user.displayAvatarURL()) .setDescription( - getGuild.welcomeJoinChannelMessage || + getGuildConfigWelcome.joinChannelMessage || "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 9ac7c85..4fb52e0 100644 --- a/src/events/guildMemberRemove/leaveMessage.ts +++ b/src/events/guildMemberRemove/leaveMessage.ts @@ -8,19 +8,19 @@ export default { member.guild ); - const getGuild = await prisma.guild.findUnique({ + const getGuildConfigWelcome = await prisma.guildConfigWelcome.findUnique({ where: { id: member.guild.id }, }); - if (!getGuild) throw new Error("Guild not found"); + if (!getGuildConfigWelcome) throw new Error("Guild not found"); const { client } = member; - if (getGuild.welcomeEnabled !== true) return; - if (!getGuild.welcomeLeaveChannelId) return; + if (getGuildConfigWelcome.status !== true) return; + if (!getGuildConfigWelcome.leaveChannelId) return; const channel = client.channels.cache.get( - `${getGuild.welcomeLeaveChannelId}` + `${getGuildConfigWelcome.leaveChannelId}` ); if (!channel) throw new Error("Channel not found"); @@ -34,7 +34,7 @@ export default { .setTitle(`${member.user.username} has left the server!`) .setThumbnail(member.user.displayAvatarURL()) .setDescription( - getGuild.welcomeLeaveChannelMessage || + getGuildConfigWelcome.leaveChannelMessage || "Configure a leave message in the `/settings guild welcome`." ) .setTimestamp() diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 36447e1..5b51731 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -16,8 +16,8 @@ export const execute = async (message: Message) => { if (!message.member) return; if (message.author.bot) return; - client.emit("guildMemberAdd", message.member); - client.emit("guildMemberRemove", message.member); - client.emit("messageDelete", message); - client.emit("messageUpdate", message, message); + // client.emit("guildMemberAdd", message.member); + // client.emit("guildMemberRemove", message.member); + // client.emit("messageDelete", message); + // client.emit("messageUpdate", message, message); }; diff --git a/src/events/messageCreate/modules/counters/index.ts b/src/events/messageCreate/modules/counters/index.ts index b6bd32d..416a308 100644 --- a/src/events/messageCreate/modules/counters/index.ts +++ b/src/events/messageCreate/modules/counters/index.ts @@ -13,7 +13,7 @@ export default { const messages = await message.channel.messages.fetch({ limit: 2 }); const lastMessage = messages.last(); - const channelCounter = await prisma.guildCounter.findUnique({ + const channelCounter = await prisma.guildCounters.findUnique({ where: { guildId_channelId: { guildId: guild.id, @@ -47,7 +47,7 @@ export default { return; } - const updateGuildCounter = await prisma.guildCounter.update({ + const updateGuildCounter = await prisma.guildCounters.update({ where: { guildId_channelId: { guildId: guild.id, diff --git a/src/events/messageCreate/modules/credits/index.ts b/src/events/messageCreate/modules/credits/index.ts index b38ad47..22a9068 100644 --- a/src/events/messageCreate/modules/credits/index.ts +++ b/src/events/messageCreate/modules/credits/index.ts @@ -50,16 +50,40 @@ export default { logger.silly(createGuildMember); - if (content.length < createGuildMember.guild.creditsMinimumLength) return; + const upsertGuildConfigCredits = await prisma.guildConfigCredits.upsert({ + where: { + id: guild.id, + }, + update: {}, + create: { + guild: { + connectOrCreate: { + create: { + id: guild.id, + }, + where: { + id: guild.id, + }, + }, + }, + }, + include: { + guild: true, + }, + }); + + logger.silly(upsertGuildConfigCredits); + + if (content.length < upsertGuildConfigCredits.minimumLength) return; await cooldown( guild, author, "event-messageCreate-credits", - createGuildMember.guild.creditsTimeout, + upsertGuildConfigCredits.timeout, true ); - await creditsGive(guild, author, createGuildMember.guild.creditsRate); + await creditsGive(guild, author, upsertGuildConfigCredits.rate); }, }; diff --git a/src/events/messageCreate/modules/points/index.ts b/src/events/messageCreate/modules/points/index.ts index d8f1494..b5b5372 100644 --- a/src/events/messageCreate/modules/points/index.ts +++ b/src/events/messageCreate/modules/points/index.ts @@ -11,25 +11,12 @@ export default { if (author.bot) return; if (channel.type !== ChannelType.GuildText) return; - const createGuildMember = await prisma.guildMember.upsert({ + const upsertGuildConfigPoints = await prisma.guildConfigPoints.upsert({ where: { - userId_guildId: { - userId: author.id, - guildId: guild.id, - }, + id: guild.id, }, update: {}, create: { - user: { - connectOrCreate: { - create: { - id: author.id, - }, - where: { - id: author.id, - }, - }, - }, guild: { connectOrCreate: { create: { @@ -42,20 +29,19 @@ export default { }, }, include: { - user: true, guild: true, }, }); - logger.silly(createGuildMember); + logger.silly(upsertGuildConfigPoints); - if (content.length < createGuildMember.guild.pointsMinimumLength) return; + if (content.length < upsertGuildConfigPoints.minimumLength) return; await cooldown( guild, author, "event-messageCreate-points", - createGuildMember.guild.pointsTimeout, + upsertGuildConfigPoints.timeout, true ); @@ -68,7 +54,7 @@ export default { }, data: { pointsEarned: { - increment: createGuildMember.guild.pointsRate, + increment: upsertGuildConfigPoints.rate, }, }, }); diff --git a/src/events/messageDelete/modules/counter.ts b/src/events/messageDelete/modules/counter.ts index 3dc0ab1..1cd1bd9 100644 --- a/src/events/messageDelete/modules/counter.ts +++ b/src/events/messageDelete/modules/counter.ts @@ -10,7 +10,7 @@ export default async (message: Message) => { if (!guild) throw new Error("Guild not found"); if (!channel) throw new Error("Channel not found"); - const channelCounter = await prisma.guildCounter.findUnique({ + const channelCounter = await prisma.guildCounters.findUnique({ where: { guildId_channelId: { guildId: guild.id, diff --git a/src/events/messageUpdate/modules/counter.ts b/src/events/messageUpdate/modules/counter.ts index 258e729..cbc844c 100644 --- a/src/events/messageUpdate/modules/counter.ts +++ b/src/events/messageUpdate/modules/counter.ts @@ -11,7 +11,7 @@ export default async (message: Message) => { if (!channel) throw new Error("Channel not found"); - const channelCounter = await prisma.guildCounter.findUnique({ + const channelCounter = await prisma.guildCounters.findUnique({ where: { guildId_channelId: { guildId: guild.id, diff --git a/src/helpers/auditLogger/index.ts b/src/helpers/auditLogger/index.ts index 480271a..7dd022b 100644 --- a/src/helpers/auditLogger/index.ts +++ b/src/helpers/auditLogger/index.ts @@ -4,13 +4,13 @@ import getEmbedConfig from "../../helpers/getEmbedData"; import logger from "../../middlewares/logger"; export default async (guild: Guild, embed: EmbedBuilder) => { - const getGuild = await prisma.guild.findUnique({ + const getGuildConfigAudits = await prisma.guildConfigAudits.findUnique({ where: { id: guild.id }, }); - if (!getGuild) throw new Error("Guild not found"); + if (!getGuildConfigAudits) return logger.verbose("Guild not found"); - if (getGuild.auditsEnabled !== true) return; - if (!getGuild.auditsChannelId) { + if (getGuildConfigAudits.status !== true) return; + if (!getGuildConfigAudits.channelId) { throw new Error("Channel not found"); } @@ -24,7 +24,9 @@ export default async (guild: Guild, embed: EmbedBuilder) => { }) .setColor(embedConfig.successColor); - const channel = guild.client.channels.cache.get(getGuild.auditsChannelId); + const channel = guild.client.channels.cache.get( + getGuildConfigAudits.channelId + ); if (!channel) throw new Error("Channel not found"); if (channel.type !== ChannelType.GuildText) { diff --git a/src/helpers/credits/give.ts b/src/helpers/credits/give.ts index 04395ed..f7c0d70 100644 --- a/src/helpers/credits/give.ts +++ b/src/helpers/credits/give.ts @@ -8,34 +8,20 @@ export default async (guild: Guild, user: User, amount: number) => { transactionRules(guild, user, amount); // 2. Make the transaction. - const recipient = await tx.guildMember.upsert({ + const recipient = await tx.guildMemberCredits.upsert({ update: { - creditsEarned: { + balance: { increment: amount, }, }, create: { - user: { + GuildMember: { connectOrCreate: { - create: { - id: user.id, - }, - where: { - id: user.id, - }, + create: { userId: user.id, guildId: guild.id }, + where: { userId_guildId: { userId: user.id, guildId: guild.id } }, }, }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, - }, - }, - }, - creditsEarned: amount, + balance: amount, }, where: { userId_guildId: { diff --git a/src/helpers/credits/set.ts b/src/helpers/credits/set.ts index c8053e0..adfe04e 100644 --- a/src/helpers/credits/set.ts +++ b/src/helpers/credits/set.ts @@ -8,32 +8,26 @@ export default async (guild: Guild, user: User, amount: number) => { transactionRules(guild, user, amount); // 2. Make the transaction. - const recipient = await tx.guildMember.upsert({ + const recipient = await tx.guildMemberCredits.upsert({ update: { - creditsEarned: amount, + balance: amount, }, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: user.id, + userId: user.id, + guildId: guild.id, }, where: { - id: user.id, + userId_guildId: { + userId: user.id, + guildId: guild.id, + }, }, }, }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, - }, - }, - }, - creditsEarned: amount, + balance: amount, }, where: { userId_guildId: { diff --git a/src/helpers/credits/take.ts b/src/helpers/credits/take.ts index 7b97e2b..1175aa3 100644 --- a/src/helpers/credits/take.ts +++ b/src/helpers/credits/take.ts @@ -8,34 +8,28 @@ export default async (guild: Guild, user: User, amount: number) => { transactionRules(guild, user, amount); // 2. Make the transaction. - const recipient = await tx.guildMember.upsert({ + const recipient = await tx.guildMemberCredits.upsert({ update: { - creditsEarned: { + balance: { decrement: amount, }, }, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: user.id, + userId: user.id, + guildId: guild.id, }, where: { - id: user.id, + userId_guildId: { + userId: user.id, + guildId: guild.id, + }, }, }, }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, - }, - }, - }, - creditsEarned: -amount, + balance: -amount, }, where: { userId_guildId: { @@ -46,7 +40,7 @@ export default async (guild: Guild, user: User, amount: number) => { }); // 3. Verify that the recipient credits are not below zero. - if (recipient.creditsEarned < -100) + if (recipient.balance < -100) throw new Error("User do not have enough credits"); // 4. Return the recipient. diff --git a/src/helpers/credits/transfer.ts b/src/helpers/credits/transfer.ts index c85518e..0e6bf21 100644 --- a/src/helpers/credits/transfer.ts +++ b/src/helpers/credits/transfer.ts @@ -5,34 +5,28 @@ import transactionRules from "./transactionRules"; export default async (guild: Guild, from: User, to: User, amount: number) => { return await prisma.$transaction(async (tx) => { // 1. Decrement amount from the sender. - const sender = await tx.guildMember.upsert({ + const sender = await tx.guildMemberCredits.upsert({ update: { - creditsEarned: { + balance: { decrement: amount, }, }, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: from.id, + userId: from.id, + guildId: guild.id, }, where: { - id: from.id, + userId_guildId: { + userId: from.id, + guildId: guild.id, + }, }, }, }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, - }, - }, - }, - creditsEarned: -amount, + balance: -amount, }, where: { userId_guildId: { @@ -43,7 +37,7 @@ export default async (guild: Guild, from: User, to: User, amount: number) => { }); // 4. Verify that the sender's balance didn't go below zero. - if (sender.creditsEarned < 0) { + if (sender.balance < 0) { throw new Error(`${from} doesn't have enough to send ${amount}`); } @@ -55,34 +49,28 @@ export default async (guild: Guild, from: User, to: User, amount: number) => { if (from.id === to.id) throw new Error("You can't transfer to yourself."); // 7. Increment the recipient's balance by amount. - const recipient = await tx.guildMember.upsert({ + const recipient = await tx.guildMemberCredits.upsert({ update: { - creditsEarned: { + balance: { increment: amount, }, }, create: { - user: { + GuildMember: { connectOrCreate: { create: { - id: to.id, + userId: to.id, + guildId: guild.id, }, where: { - id: to.id, + userId_guildId: { + userId: to.id, + guildId: guild.id, + }, }, }, }, - guild: { - connectOrCreate: { - create: { - id: guild.id, - }, - where: { - id: guild.id, - }, - }, - }, - creditsEarned: amount, + balance: amount, }, where: { userId_guildId: { diff --git a/src/helpers/getEmbedData/index.ts b/src/helpers/getEmbedData/index.ts index 069ce9b..e3fc516 100644 --- a/src/helpers/getEmbedData/index.ts +++ b/src/helpers/getEmbedData/index.ts @@ -23,25 +23,12 @@ export default async (guild?: Guild | null) => { return defaultEmbedConfig; } - const createGuildMember = await prisma.guildMember.upsert({ + const upsertGuildConfigEmbeds = await prisma.guildConfigEmbeds.upsert({ where: { - userId_guildId: { - userId: guild?.ownerId, - guildId: guild.id, - }, + id: guild.id, }, update: {}, create: { - user: { - connectOrCreate: { - create: { - id: guild.ownerId, - }, - where: { - id: guild.ownerId, - }, - }, - }, guild: { connectOrCreate: { create: { @@ -54,22 +41,21 @@ export default async (guild?: Guild | null) => { }, }, include: { - user: true, guild: true, }, }); - logger.silly(createGuildMember); + logger.silly(upsertGuildConfigEmbeds); - if (!createGuildMember) { + if (!upsertGuildConfigEmbeds) { return defaultEmbedConfig; } return { - successColor: createGuildMember.guild.embedColorSuccess, - waitColor: createGuildMember.guild.embedColorWait, - errorColor: createGuildMember.guild.embedColorError, - footerText: createGuildMember.guild.embedFooterText, - footerIcon: createGuildMember.guild.embedFooterIcon, + successColor: upsertGuildConfigEmbeds.successColor, + waitColor: upsertGuildConfigEmbeds.waitColor, + errorColor: upsertGuildConfigEmbeds.errorColor, + footerText: upsertGuildConfigEmbeds.footerText, + footerIcon: upsertGuildConfigEmbeds.footerIcon, }; };