♻️ Config Credits now on Prisma
This commit is contained in:
parent
3b6d0a7f54
commit
69be3ccf05
1 changed files with 87 additions and 70 deletions
|
@ -4,9 +4,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: {
|
||||||
|
@ -20,30 +20,40 @@ export default {
|
||||||
.setName("credits")
|
.setName("credits")
|
||||||
.setDescription(`Credits`)
|
.setDescription(`Credits`)
|
||||||
.addBooleanOption((option) =>
|
.addBooleanOption((option) =>
|
||||||
option.setName("status").setDescription("Should credits be enabled?")
|
option
|
||||||
|
.setName("status")
|
||||||
|
.setDescription("Should credits be enabled?")
|
||||||
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option.setName("rate").setDescription("Amount of credits per message.")
|
option
|
||||||
|
.setName("rate")
|
||||||
|
.setDescription("Amount of credits per message.")
|
||||||
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("minimum-length")
|
.setName("minimum-length")
|
||||||
.setDescription("Minimum length of message to earn credits.")
|
.setDescription("Minimum length of message to earn credits.")
|
||||||
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("work-rate")
|
.setName("work-rate")
|
||||||
.setDescription("Maximum amount of credits on work.")
|
.setDescription("Maximum amount of credits on work.")
|
||||||
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("work-timeout")
|
.setName("work-timeout")
|
||||||
.setDescription("Timeout between work schedules (seconds).")
|
.setDescription("Timeout between work schedules (seconds).")
|
||||||
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("timeout")
|
.setName("timeout")
|
||||||
.setDescription("Timeout between earning credits (seconds).")
|
.setDescription("Timeout between earning credits (seconds).")
|
||||||
|
.setRequired(true)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
execute: async (interaction: ChatInputCommandInteraction) => {
|
execute: async (interaction: ChatInputCommandInteraction) => {
|
||||||
|
@ -52,8 +62,6 @@ export default {
|
||||||
);
|
);
|
||||||
const { guild, options } = interaction;
|
const { guild, options } = interaction;
|
||||||
|
|
||||||
if (!guild) return;
|
|
||||||
|
|
||||||
const status = options?.getBoolean("status");
|
const status = options?.getBoolean("status");
|
||||||
const rate = options?.getNumber("rate");
|
const rate = options?.getNumber("rate");
|
||||||
const timeout = options?.getNumber("timeout");
|
const timeout = options?.getNumber("timeout");
|
||||||
|
@ -61,75 +69,84 @@ export default {
|
||||||
const workRate = options?.getNumber("work-rate");
|
const workRate = options?.getNumber("work-rate");
|
||||||
const workTimeout = options?.getNumber("work-timeout");
|
const workTimeout = options?.getNumber("work-timeout");
|
||||||
|
|
||||||
const guildDB = await guildSchema?.findOne({
|
if (!guild) throw new Error("Guild is not found");
|
||||||
guildId: guild?.id,
|
if (status === null) throw new Error("Status is null");
|
||||||
|
if (!rate) throw new Error("Rate is null");
|
||||||
|
if (!workRate) throw new Error("WorkRate is null");
|
||||||
|
if (!workTimeout) throw new Error("WorkTimeout is null");
|
||||||
|
if (!timeout) throw new Error("Timeout is null");
|
||||||
|
if (!minimumLength) throw new Error("Minimum Length is null");
|
||||||
|
|
||||||
|
const createGuild = await prisma.guild.upsert({
|
||||||
|
where: {
|
||||||
|
id: guild.id,
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
creditsEnabled: status,
|
||||||
|
creditsRate: rate,
|
||||||
|
creditsTimeout: timeout,
|
||||||
|
creditsWorkRate: workRate,
|
||||||
|
creditsWorkTimeout: workTimeout,
|
||||||
|
creditsMinimumLength: minimumLength,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
id: guild.id,
|
||||||
|
creditsEnabled: status,
|
||||||
|
creditsRate: rate,
|
||||||
|
creditsTimeout: timeout,
|
||||||
|
creditsWorkRate: workRate,
|
||||||
|
creditsWorkTimeout: workTimeout,
|
||||||
|
creditsMinimumLength: minimumLength,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (guildDB === null) {
|
logger.silly(createGuild);
|
||||||
return logger?.silly(`Guild is null`);
|
|
||||||
}
|
|
||||||
|
|
||||||
guildDB.credits.status =
|
const interactionEmbed = new EmbedBuilder()
|
||||||
status !== null ? status : guildDB?.credits?.status;
|
.setTitle("[:tools:] Credits")
|
||||||
guildDB.credits.rate = rate !== null ? rate : guildDB?.credits?.rate;
|
.setDescription("Credits settings updated")
|
||||||
guildDB.credits.timeout =
|
.setColor(successColor)
|
||||||
timeout !== null ? timeout : guildDB?.credits?.timeout;
|
.addFields(
|
||||||
guildDB.credits.workRate =
|
{
|
||||||
workRate !== null ? workRate : guildDB?.credits?.workRate;
|
name: "🤖 Status",
|
||||||
guildDB.credits.workTimeout =
|
value: `${createGuild.creditsEnabled}`,
|
||||||
workTimeout !== null ? workTimeout : guildDB?.credits?.workTimeout;
|
inline: true,
|
||||||
guildDB.credits.minimumLength =
|
},
|
||||||
minimumLength !== null ? minimumLength : guildDB?.credits?.minimumLength;
|
{
|
||||||
|
name: "📈 Rate",
|
||||||
await guildDB?.save()?.then(async () => {
|
value: `${createGuild.creditsRate}`,
|
||||||
logger?.silly(`Guild saved`);
|
inline: true,
|
||||||
|
},
|
||||||
const interactionEmbed = new EmbedBuilder()
|
{
|
||||||
.setTitle("[:tools:] Credits")
|
name: "📈 Work Rate",
|
||||||
.setDescription("Credits settings updated")
|
value: `${createGuild.creditsWorkRate}`,
|
||||||
.setColor(successColor)
|
inline: true,
|
||||||
.addFields(
|
},
|
||||||
{
|
{
|
||||||
name: "🤖 Status",
|
name: "🔨 Minimum Length",
|
||||||
value: `${guildDB?.credits?.status}`,
|
value: `${createGuild.creditsMinimumLength}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "📈 Rate",
|
name: "⏰ Timeout",
|
||||||
value: `${guildDB?.credits?.rate}`,
|
value: `${createGuild.creditsTimeout}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "📈 Work Rate",
|
name: "⏰ Work Timeout",
|
||||||
value: `${guildDB?.credits?.workRate}`,
|
value: `${createGuild.creditsWorkTimeout}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
}
|
||||||
{
|
)
|
||||||
name: "🔨 Minimum Length",
|
.setTimestamp()
|
||||||
value: `${guildDB?.credits?.minimumLength}`,
|
.setFooter({
|
||||||
inline: true,
|
iconURL: footerIcon,
|
||||||
},
|
text: footerText,
|
||||||
{
|
|
||||||
name: "⏰ Timeout",
|
|
||||||
value: `${guildDB?.credits?.timeout}`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "⏰ Work Timeout",
|
|
||||||
value: `${guildDB?.credits?.workTimeout}`,
|
|
||||||
inline: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.setTimestamp()
|
|
||||||
.setFooter({
|
|
||||||
iconURL: footerIcon,
|
|
||||||
text: footerText,
|
|
||||||
});
|
|
||||||
|
|
||||||
await interaction?.editReply({
|
|
||||||
embeds: [interactionEmbed],
|
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
|
await interaction?.editReply({
|
||||||
|
embeds: [interactionEmbed],
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue