♻️ Audit Config now on Prisma
This commit is contained in:
parent
a43750080a
commit
3b6d0a7f54
3 changed files with 95 additions and 46 deletions
36
prisma/migrations/20221020111948_audits_module/migration.sql
Normal file
36
prisma/migrations/20221020111948_audits_module/migration.sql
Normal file
|
@ -0,0 +1,36 @@
|
|||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Guild" (
|
||||
"id" TEXT NOT NULL,
|
||||
"embedColorSuccess" TEXT NOT NULL DEFAULT '#22bb33',
|
||||
"embedColorWait" TEXT NOT NULL DEFAULT '#f0ad4e',
|
||||
"embedColorError" TEXT NOT NULL DEFAULT '#bb2124',
|
||||
"embedFooterText" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg/xyter',
|
||||
"embedFooterIcon" TEXT NOT NULL DEFAULT 'https://github.com/ZynerOrg.png',
|
||||
"creditsEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"creditsRate" INTEGER NOT NULL DEFAULT 1,
|
||||
"creditsTimeout" INTEGER NOT NULL DEFAULT 5,
|
||||
"creditsWorkRate" INTEGER NOT NULL DEFAULT 25,
|
||||
"creditsWorkTimeout" INTEGER NOT NULL DEFAULT 86400,
|
||||
"creditsMinimumLength" INTEGER NOT NULL DEFAULT 5,
|
||||
"pointsEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"pointsRate" INTEGER NOT NULL DEFAULT 1,
|
||||
"pointsTimeout" INTEGER NOT NULL DEFAULT 5,
|
||||
"pointsMinimumLength" INTEGER NOT NULL DEFAULT 5,
|
||||
"reputationsEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"countersEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"apiCpggUrlIv" TEXT,
|
||||
"apiCpggUrlContent" TEXT,
|
||||
"apiCpggTokenIv" TEXT,
|
||||
"apiCpggTokenContent" TEXT,
|
||||
"auditsEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"auditsChannelId" TEXT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
INSERT INTO "new_Guild" ("apiCpggTokenContent", "apiCpggTokenIv", "apiCpggUrlContent", "apiCpggUrlIv", "countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "embedColorError", "embedColorSuccess", "embedColorWait", "embedFooterIcon", "embedFooterText", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "updatedAt") SELECT "apiCpggTokenContent", "apiCpggTokenIv", "apiCpggUrlContent", "apiCpggUrlIv", "countersEnabled", "createdAt", "creditsEnabled", "creditsMinimumLength", "creditsRate", "creditsTimeout", "creditsWorkRate", "creditsWorkTimeout", "embedColorError", "embedColorSuccess", "embedColorWait", "embedFooterIcon", "embedFooterText", "id", "pointsEnabled", "pointsMinimumLength", "pointsRate", "pointsTimeout", "reputationsEnabled", "updatedAt" FROM "Guild";
|
||||
DROP TABLE "Guild";
|
||||
ALTER TABLE "new_Guild" RENAME TO "Guild";
|
||||
CREATE UNIQUE INDEX "Guild_id_key" ON "Guild"("id");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
|
@ -23,11 +23,6 @@ model Guild {
|
|||
embedFooterText String @default("https://github.com/ZynerOrg/xyter")
|
||||
embedFooterIcon String @default("https://github.com/ZynerOrg.png")
|
||||
|
||||
apiCpggUrlIv String?
|
||||
apiCpggUrlContent String?
|
||||
apiCpggTokenIv String?
|
||||
apiCpggTokenContent String?
|
||||
|
||||
// Modules
|
||||
creditsEnabled Boolean @default(false)
|
||||
creditsRate Int @default(1)
|
||||
|
@ -46,6 +41,14 @@ model Guild {
|
|||
countersEnabled Boolean @default(false)
|
||||
counters GuildCounter[]
|
||||
|
||||
apiCpggUrlIv String?
|
||||
apiCpggUrlContent String?
|
||||
apiCpggTokenIv String?
|
||||
apiCpggTokenContent String?
|
||||
|
||||
auditsEnabled Boolean @default(false)
|
||||
auditsChannelId String?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import {
|
|||
EmbedBuilder,
|
||||
PermissionsBitField,
|
||||
} from "discord.js";
|
||||
import prisma from "../../../../handlers/database";
|
||||
import getEmbedConfig from "../../../../helpers/getEmbedData";
|
||||
import logger from "../../../../middlewares/logger";
|
||||
import guildSchema from "../../../../models/guild";
|
||||
|
||||
export default {
|
||||
metadata: {
|
||||
|
@ -21,13 +21,17 @@ export default {
|
|||
.setName("audits")
|
||||
.setDescription("Audits")
|
||||
.addBooleanOption((option) =>
|
||||
option.setName("status").setDescription("Should audits be enabled?")
|
||||
option
|
||||
.setName("status")
|
||||
.setDescription("Should audits be enabled?")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addChannelOption((option) =>
|
||||
option
|
||||
.setName("channel")
|
||||
.setDescription("Channel for audit messages.")
|
||||
.addChannelTypes(ChannelType.GuildText)
|
||||
.setRequired(true)
|
||||
);
|
||||
},
|
||||
execute: async (interaction: ChatInputCommandInteraction) => {
|
||||
|
@ -39,18 +43,25 @@ export default {
|
|||
const channel = options.getChannel("channel");
|
||||
|
||||
if (!guild) throw new Error("Guild not found.");
|
||||
const guildDB = await guildSchema.findOne({
|
||||
guildId: guild.id,
|
||||
if (!channel) throw new Error("Channel not found.");
|
||||
if (status === null) throw new Error("Status not found.");
|
||||
|
||||
const createGuild = await prisma.guild.upsert({
|
||||
where: {
|
||||
id: guild.id,
|
||||
},
|
||||
update: {
|
||||
auditsEnabled: status,
|
||||
auditsChannelId: channel.id,
|
||||
},
|
||||
create: {
|
||||
id: guild.id,
|
||||
auditsEnabled: status,
|
||||
auditsChannelId: channel.id,
|
||||
},
|
||||
});
|
||||
if (!guildDB) throw new Error("Guild configuration not found.");
|
||||
|
||||
guildDB.audits.status = status !== null ? status : guildDB.audits.status;
|
||||
guildDB.audits.channelId = channel ? channel.id : guildDB.audits.channelId;
|
||||
|
||||
await guildDB.save().then(async () => {
|
||||
logger.verbose(
|
||||
`Guild ${guild.name} updated their configuration for audits.`
|
||||
);
|
||||
logger.silly(createGuild);
|
||||
|
||||
const embedSuccess = new EmbedBuilder()
|
||||
.setTitle("[:hammer:] Audits")
|
||||
|
@ -60,7 +71,7 @@ export default {
|
|||
{
|
||||
name: "🤖 Status",
|
||||
value: `${
|
||||
guildDB.audits.status
|
||||
createGuild.auditsEnabled
|
||||
? ":white_check_mark: Enabled"
|
||||
: ":x: Disabled"
|
||||
}`,
|
||||
|
@ -68,7 +79,7 @@ export default {
|
|||
},
|
||||
{
|
||||
name: "🌊 Channel",
|
||||
value: `<#${guildDB.audits.channelId}>`,
|
||||
value: `<#${createGuild.auditsChannelId}>`,
|
||||
inline: true,
|
||||
}
|
||||
)
|
||||
|
@ -82,6 +93,5 @@ export default {
|
|||
embeds: [embedSuccess],
|
||||
});
|
||||
return;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue