-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from VermiumSifell/dev
🚑 accidently pushed using wrong config type, fix
- Loading branch information
Showing
11 changed files
with
810 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ node_modules | |
config.json | ||
package-lock.json | ||
|
||
|
||
config/ | ||
src/config/ | ||
|
||
# Build | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { SlashCommandBuilder } from "@discordjs/builders"; | ||
import { CommandInteraction } from "discord.js"; | ||
|
||
import modules from "./modules"; | ||
|
||
export const builder = new SlashCommandBuilder() | ||
.setName("config") | ||
.setDescription("Manage guild configurations.") | ||
|
||
.addSubcommand(modules.cpgg.builder) | ||
.addSubcommand(modules.credits.builder) | ||
.addSubcommand(modules.points.builder) | ||
.addSubcommand(modules.welcome.builder) | ||
.addSubcommand(modules.audits.builder) | ||
.addSubcommand(modules.shop.builder) | ||
.addSubcommand(modules.embeds.builder); | ||
|
||
export const moduleData = modules; | ||
|
||
export const execute = async (interaction: CommandInteraction) => { | ||
switch (interaction.options?.getSubcommand()) { | ||
case "cpgg": | ||
return modules.cpgg.execute(interaction); | ||
case "credits": | ||
return modules.credits.execute(interaction); | ||
case "points": | ||
return modules.points.execute(interaction); | ||
case "welcome": | ||
return modules.welcome.execute(interaction); | ||
case "audits": | ||
return modules.audits.execute(interaction); | ||
case "shop": | ||
return modules.shop.execute(interaction); | ||
case "embeds": | ||
return modules.embeds.execute(interaction); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { CommandInteraction, Permissions } from "discord.js"; | ||
|
||
import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; | ||
|
||
import logger from "../../../../../logger"; | ||
|
||
import guildSchema from "../../../../../models/guild"; | ||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; | ||
import { ChannelType } from "discord-api-types/v10"; | ||
|
||
export default { | ||
metadata: { | ||
guildOnly: true, | ||
ephemeral: true, | ||
permissions: [Permissions.FLAGS.MANAGE_GUILD], | ||
}, | ||
|
||
builder: (command: SlashCommandSubcommandBuilder) => { | ||
return command | ||
.setName("audits") | ||
.setDescription("Audits") | ||
.addBooleanOption((option) => | ||
option.setName("status").setDescription("Should audits be enabled?") | ||
) | ||
.addChannelOption((option) => | ||
option | ||
.setName("channel") | ||
.setDescription("Channel for audit messages.") | ||
.addChannelTypes(ChannelType.GuildText) | ||
); | ||
}, | ||
execute: async (interaction: CommandInteraction) => { | ||
const { successColor, footerText, footerIcon } = await getEmbedConfig( | ||
interaction.guild | ||
); | ||
|
||
const { guild, options } = interaction; | ||
|
||
const status = options?.getBoolean("status"); | ||
const channel = options?.getChannel("channel"); | ||
|
||
const guildDB = await guildSchema?.findOne({ | ||
guildId: guild?.id, | ||
}); | ||
|
||
if (guildDB === null) { | ||
return logger?.silly(`Guild not found in database.`); | ||
} | ||
|
||
guildDB.audits.status = status !== null ? status : guildDB?.audits?.status; | ||
guildDB.audits.channelId = | ||
channel !== null ? channel.id : guildDB?.audits?.channelId; | ||
|
||
await guildDB?.save()?.then(async () => { | ||
logger?.silly(`Guild audits updated.`); | ||
|
||
return interaction?.editReply({ | ||
embeds: [ | ||
{ | ||
title: ":hammer: Settings - Guild [Audits]", | ||
description: `Audits settings updated.`, | ||
color: successColor, | ||
fields: [ | ||
{ | ||
name: "🤖 Status", | ||
value: `${guildDB?.audits?.status}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "🌊 Channel", | ||
value: `${guildDB?.audits?.channelId}`, | ||
inline: true, | ||
}, | ||
], | ||
timestamp: new Date(), | ||
footer: { | ||
iconURL: footerIcon, | ||
text: footerText, | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { CommandInteraction, Permissions } from "discord.js"; | ||
|
||
import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; | ||
|
||
import logger from "../../../../../logger"; | ||
|
||
import apiSchema from "../../../../../models/api"; | ||
import encryption from "../../../../../handlers/encryption"; | ||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; | ||
|
||
export default { | ||
metadata: { | ||
guildOnly: true, | ||
ephemeral: true, | ||
permissions: [Permissions.FLAGS.MANAGE_GUILD], | ||
}, | ||
|
||
builder: (command: SlashCommandSubcommandBuilder) => { | ||
return command | ||
.setName("cpgg") | ||
.setDescription("Controlpanel.gg") | ||
.addStringOption((option) => | ||
option | ||
.setName("scheme") | ||
.setDescription(`Controlpanel.gg Scheme`) | ||
.setRequired(true) | ||
.setChoices( | ||
{ name: "HTTPS (secure)", value: "https" }, | ||
{ name: "HTTP (insecure)", value: "http" } | ||
) | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName("domain") | ||
.setDescription(`Controlpanel.gg Domain`) | ||
.setRequired(true) | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName("token") | ||
.setDescription(`Controlpanel.gg Application API`) | ||
.setRequired(true) | ||
); | ||
}, | ||
execute: async (interaction: CommandInteraction) => { | ||
const { successColor, footerText, footerIcon } = await getEmbedConfig( | ||
interaction.guild | ||
); | ||
const { options, guild } = interaction; | ||
|
||
const tokenData = options.getString("token"); | ||
const scheme = options.getString("scheme"); | ||
const domain = options.getString("domain"); | ||
const token = tokenData && encryption.encrypt(tokenData); | ||
const url = scheme && domain && encryption.encrypt(`${scheme}://${domain}`); | ||
|
||
await apiSchema | ||
?.findOneAndUpdate( | ||
{ guildId: guild?.id }, | ||
{ url, token }, | ||
{ new: true, upsert: true } | ||
) | ||
.then(async () => { | ||
logger?.silly(`Updated API credentials.`); | ||
|
||
return interaction?.editReply({ | ||
embeds: [ | ||
{ | ||
title: "[:tools:] CPGG", | ||
description: `The following configuration will be used. | ||
**Scheme**: ${scheme} | ||
**Domain**: ${domain} | ||
**Token**: ends with ${tokenData?.slice(-4)}`, | ||
color: successColor, | ||
timestamp: new Date(), | ||
footer: { | ||
iconURL: footerIcon, | ||
text: footerText, | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { CommandInteraction, Permissions } from "discord.js"; | ||
|
||
import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; | ||
|
||
import logger from "../../../../../logger"; | ||
|
||
import guildSchema from "../../../../../models/guild"; | ||
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; | ||
|
||
export default { | ||
metadata: { | ||
guildOnly: true, | ||
ephemeral: true, | ||
permissions: [Permissions.FLAGS.MANAGE_GUILD], | ||
}, | ||
|
||
builder: (command: SlashCommandSubcommandBuilder) => { | ||
return command | ||
.setName("credits") | ||
.setDescription(`Credits`) | ||
.addBooleanOption((option) => | ||
option.setName("status").setDescription("Should credits be enabled?") | ||
) | ||
.addNumberOption((option) => | ||
option.setName("rate").setDescription("Amount of credits per message.") | ||
) | ||
.addNumberOption((option) => | ||
option | ||
.setName("minimum-length") | ||
.setDescription("Minimum length of message to earn credits.") | ||
) | ||
.addNumberOption((option) => | ||
option | ||
.setName("work-rate") | ||
.setDescription("Maximum amount of credits on work.") | ||
) | ||
.addNumberOption((option) => | ||
option | ||
.setName("work-timeout") | ||
.setDescription("Timeout between work schedules (seconds).") | ||
) | ||
.addNumberOption((option) => | ||
option | ||
.setName("timeout") | ||
.setDescription("Timeout between earning credits (seconds).") | ||
); | ||
}, | ||
execute: async (interaction: CommandInteraction) => { | ||
const { successColor, footerText, footerIcon } = await getEmbedConfig( | ||
interaction.guild | ||
); | ||
const { guild, options } = interaction; | ||
|
||
if (guild == null) return; | ||
|
||
const status = options?.getBoolean("status"); | ||
const rate = options?.getNumber("rate"); | ||
const timeout = options?.getNumber("timeout"); | ||
const minimumLength = options?.getNumber("minimum-length"); | ||
const workRate = options?.getNumber("work-rate"); | ||
const workTimeout = options?.getNumber("work-timeout"); | ||
|
||
const guildDB = await guildSchema?.findOne({ | ||
guildId: guild?.id, | ||
}); | ||
|
||
if (guildDB === null) { | ||
return logger?.silly(`Guild is null`); | ||
} | ||
|
||
guildDB.credits.status = | ||
status !== null ? status : guildDB?.credits?.status; | ||
guildDB.credits.rate = rate !== null ? rate : guildDB?.credits?.rate; | ||
guildDB.credits.timeout = | ||
timeout !== null ? timeout : guildDB?.credits?.timeout; | ||
guildDB.credits.workRate = | ||
workRate !== null ? workRate : guildDB?.credits?.workRate; | ||
guildDB.credits.workTimeout = | ||
workTimeout !== null ? workTimeout : guildDB?.credits?.workTimeout; | ||
guildDB.credits.minimumLength = | ||
minimumLength !== null ? minimumLength : guildDB?.credits?.minimumLength; | ||
|
||
await guildDB?.save()?.then(async () => { | ||
logger?.silly(`Guild saved`); | ||
|
||
return interaction?.editReply({ | ||
embeds: [ | ||
{ | ||
title: ":tools: Settings - Guild [Credits]", | ||
description: `Credits settings updated.`, | ||
color: successColor, | ||
fields: [ | ||
{ | ||
name: "🤖 Status", | ||
value: `${guildDB?.credits?.status}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "📈 Rate", | ||
value: `${guildDB?.credits?.rate}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "📈 Work Rate", | ||
value: `${guildDB?.credits?.workRate}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "🔨 Minimum Length", | ||
value: `${guildDB?.credits?.minimumLength}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "⏰ Timeout", | ||
value: `${guildDB?.credits?.timeout}`, | ||
inline: true, | ||
}, | ||
{ | ||
name: "⏰ Work Timeout", | ||
value: `${guildDB?.credits?.workTimeout}`, | ||
inline: true, | ||
}, | ||
], | ||
timestamp: new Date(), | ||
footer: { | ||
iconURL: footerIcon, | ||
text: footerText, | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}, | ||
}; |
35 changes: 35 additions & 0 deletions
35
src/plugins/commands/config/modules/embeds/components/getValues/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ColorResolvable, CommandInteraction } from "discord.js"; | ||
import guildSchema from "../../../../../../../models/guild"; | ||
import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; | ||
|
||
export default async (interaction: CommandInteraction) => { | ||
const { options, guild } = interaction; | ||
|
||
if (!guild) throw new Error("Guild not found"); | ||
|
||
const embedConfig = await getEmbedConfig(guild); | ||
if (!embedConfig) throw new Error("Embed config not found"); | ||
|
||
const newSuccessColor = options.getString("success-color") as ColorResolvable; | ||
const newWaitColor = options.getString("wait-color") as ColorResolvable; | ||
const newErrorColor = options.getString("error-color") as ColorResolvable; | ||
const newFooterIcon = options.getString("footer-icon"); | ||
const newFooterText = options.getString("footer-text"); | ||
|
||
const guildData = await guildSchema.findOne({ | ||
guildId: guild.id, | ||
}); | ||
if (!guildData) throw new Error("Guild data not found"); | ||
if (!guildData?.embeds) | ||
throw new Error("Guild embed configuration not found"); | ||
let { successColor, waitColor, errorColor, footerText, footerIcon } = | ||
guildData.embeds; | ||
|
||
successColor = newSuccessColor || successColor; | ||
waitColor = newWaitColor || waitColor; | ||
errorColor = newErrorColor || errorColor; | ||
footerIcon = newFooterIcon || footerIcon; | ||
footerText = newFooterText || footerText; | ||
|
||
return { successColor, waitColor, errorColor, footerText, footerIcon }; | ||
}; |
Oops, something went wrong.