♻️ 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")
|
embedFooterText String @default("https://github.com/ZynerOrg/xyter")
|
||||||
embedFooterIcon String @default("https://github.com/ZynerOrg.png")
|
embedFooterIcon String @default("https://github.com/ZynerOrg.png")
|
||||||
|
|
||||||
apiCpggUrlIv String?
|
|
||||||
apiCpggUrlContent String?
|
|
||||||
apiCpggTokenIv String?
|
|
||||||
apiCpggTokenContent String?
|
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
creditsEnabled Boolean @default(false)
|
creditsEnabled Boolean @default(false)
|
||||||
creditsRate Int @default(1)
|
creditsRate Int @default(1)
|
||||||
|
@ -46,6 +41,14 @@ model Guild {
|
||||||
countersEnabled Boolean @default(false)
|
countersEnabled Boolean @default(false)
|
||||||
counters GuildCounter[]
|
counters GuildCounter[]
|
||||||
|
|
||||||
|
apiCpggUrlIv String?
|
||||||
|
apiCpggUrlContent String?
|
||||||
|
apiCpggTokenIv String?
|
||||||
|
apiCpggTokenContent String?
|
||||||
|
|
||||||
|
auditsEnabled Boolean @default(false)
|
||||||
|
auditsChannelId String?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import {
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
PermissionsBitField,
|
PermissionsBitField,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
import prisma from "../../../../handlers/database";
|
||||||
import getEmbedConfig from "../../../../helpers/getEmbedData";
|
import getEmbedConfig from "../../../../helpers/getEmbedData";
|
||||||
import logger from "../../../../middlewares/logger";
|
import logger from "../../../../middlewares/logger";
|
||||||
import guildSchema from "../../../../models/guild";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
metadata: {
|
metadata: {
|
||||||
|
@ -21,13 +21,17 @@ export default {
|
||||||
.setName("audits")
|
.setName("audits")
|
||||||
.setDescription("Audits")
|
.setDescription("Audits")
|
||||||
.addBooleanOption((option) =>
|
.addBooleanOption((option) =>
|
||||||
option.setName("status").setDescription("Should audits be enabled?")
|
option
|
||||||
|
.setName("status")
|
||||||
|
.setDescription("Should audits be enabled?")
|
||||||
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addChannelOption((option) =>
|
.addChannelOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("channel")
|
.setName("channel")
|
||||||
.setDescription("Channel for audit messages.")
|
.setDescription("Channel for audit messages.")
|
||||||
.addChannelTypes(ChannelType.GuildText)
|
.addChannelTypes(ChannelType.GuildText)
|
||||||
|
.setRequired(true)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
execute: async (interaction: ChatInputCommandInteraction) => {
|
execute: async (interaction: ChatInputCommandInteraction) => {
|
||||||
|
@ -39,49 +43,55 @@ export default {
|
||||||
const channel = options.getChannel("channel");
|
const channel = options.getChannel("channel");
|
||||||
|
|
||||||
if (!guild) throw new Error("Guild not found.");
|
if (!guild) throw new Error("Guild not found.");
|
||||||
const guildDB = await guildSchema.findOne({
|
if (!channel) throw new Error("Channel not found.");
|
||||||
guildId: guild.id,
|
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;
|
logger.silly(createGuild);
|
||||||
guildDB.audits.channelId = channel ? channel.id : guildDB.audits.channelId;
|
|
||||||
|
|
||||||
await guildDB.save().then(async () => {
|
const embedSuccess = new EmbedBuilder()
|
||||||
logger.verbose(
|
.setTitle("[:hammer:] Audits")
|
||||||
`Guild ${guild.name} updated their configuration for audits.`
|
.setDescription("Guild configuration updated successfully.")
|
||||||
);
|
.setColor(successColor)
|
||||||
|
.addFields(
|
||||||
const embedSuccess = new EmbedBuilder()
|
{
|
||||||
.setTitle("[:hammer:] Audits")
|
name: "🤖 Status",
|
||||||
.setDescription("Guild configuration updated successfully.")
|
value: `${
|
||||||
.setColor(successColor)
|
createGuild.auditsEnabled
|
||||||
.addFields(
|
? ":white_check_mark: Enabled"
|
||||||
{
|
: ":x: Disabled"
|
||||||
name: "🤖 Status",
|
}`,
|
||||||
value: `${
|
inline: true,
|
||||||
guildDB.audits.status
|
},
|
||||||
? ":white_check_mark: Enabled"
|
{
|
||||||
: ":x: Disabled"
|
name: "🌊 Channel",
|
||||||
}`,
|
value: `<#${createGuild.auditsChannelId}>`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
}
|
||||||
{
|
)
|
||||||
name: "🌊 Channel",
|
.setTimestamp()
|
||||||
value: `<#${guildDB.audits.channelId}>`,
|
.setFooter({
|
||||||
inline: true,
|
iconURL: footerIcon,
|
||||||
}
|
text: footerText,
|
||||||
)
|
|
||||||
.setTimestamp()
|
|
||||||
.setFooter({
|
|
||||||
iconURL: footerIcon,
|
|
||||||
text: footerText,
|
|
||||||
});
|
|
||||||
|
|
||||||
await interaction.editReply({
|
|
||||||
embeds: [embedSuccess],
|
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [embedSuccess],
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue