perf: 🗃️ seperate configs in database
This commit is contained in:
parent
c3fe4ca2d5
commit
258e15c45d
41 changed files with 821 additions and 449 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -36,5 +36,8 @@
|
|||
"conventionalCommits.scopes": ["git", "github", "prisma"],
|
||||
"[dockerfile]": {
|
||||
"editor.defaultFormatter": "foxundermoon.shell-format"
|
||||
},
|
||||
"[sql]": {
|
||||
"editor.defaultFormatter": "sqlfluff.vscode-sqlfluff"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
9
prisma/migrations/20221219171553_fix_typo/migration.sql
Normal file
9
prisma/migrations/20221219171553_fix_typo/migration.sql
Normal file
|
@ -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;
|
|
@ -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`;
|
|
@ -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"
|
|
@ -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])
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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: <string>newSuccessColor,
|
||||
embedColorWait: <string>newWaitColor,
|
||||
embedColorError: <string>newErrorColor,
|
||||
embedFooterIcon: newFooterIcon,
|
||||
embedFooterText: newFooterText,
|
||||
successColor: <string>newSuccessColor,
|
||||
waitColor: <string>newWaitColor,
|
||||
errorColor: <string>newErrorColor,
|
||||
footerIcon: newFooterIcon,
|
||||
footerText: newFooterText,
|
||||
},
|
||||
create: {
|
||||
id: guild.id,
|
||||
embedColorSuccess: <string>newSuccessColor,
|
||||
embedColorWait: <string>newWaitColor,
|
||||
embedColorError: <string>newErrorColor,
|
||||
embedFooterIcon: newFooterIcon,
|
||||
embedFooterText: newFooterText,
|
||||
successColor: <string>newSuccessColor,
|
||||
waitColor: <string>newWaitColor,
|
||||
errorColor: <string>newErrorColor,
|
||||
footerIcon: newFooterIcon,
|
||||
footerText: newFooterText,
|
||||
},
|
||||
});
|
||||
|
||||
logger.silly(createGuild);
|
||||
|
||||
const successColor = <ColorResolvable>createGuild.embedColorSuccess;
|
||||
const waitColor = <ColorResolvable>createGuild.embedColorWait;
|
||||
const errorColor = <ColorResolvable>createGuild.embedColorError;
|
||||
const footerText = createGuild.embedFooterText;
|
||||
const footerIcon = createGuild.embedFooterIcon;
|
||||
const successColor = <ColorResolvable>createGuild.successColor;
|
||||
const waitColor = <ColorResolvable>createGuild.waitColor;
|
||||
const errorColor = <ColorResolvable>createGuild.errorColor;
|
||||
const footerText = createGuild.footerText;
|
||||
const footerIcon = createGuild.footerIcon;
|
||||
|
||||
return { successColor, waitColor, errorColor, footerText, footerIcon };
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.`
|
||||
),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -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!`
|
||||
),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:`
|
||||
),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
})}`,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -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 },
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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: <ColorResolvable>createGuildMember.guild.embedColorSuccess,
|
||||
waitColor: <ColorResolvable>createGuildMember.guild.embedColorWait,
|
||||
errorColor: <ColorResolvable>createGuildMember.guild.embedColorError,
|
||||
footerText: createGuildMember.guild.embedFooterText,
|
||||
footerIcon: createGuildMember.guild.embedFooterIcon,
|
||||
successColor: <ColorResolvable>upsertGuildConfigEmbeds.successColor,
|
||||
waitColor: <ColorResolvable>upsertGuildConfigEmbeds.waitColor,
|
||||
errorColor: <ColorResolvable>upsertGuildConfigEmbeds.errorColor,
|
||||
footerText: upsertGuildConfigEmbeds.footerText,
|
||||
footerIcon: upsertGuildConfigEmbeds.footerIcon,
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue