Merge pull request #374 from VermiumSifell/dev

🚑 accidently pushed using wrong config type, fix
This commit is contained in:
Axel Olausson Holtenäs 2022-06-21 18:05:49 +02:00 committed by GitHub
commit 821028ed7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 810 additions and 2 deletions

3
.gitignore vendored
View file

@ -4,8 +4,7 @@ node_modules
config.json
package-lock.json
config/
src/config/
# Build
build/

View file

@ -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);
}
};

View file

@ -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,
},
},
],
});
});
},
};

View file

@ -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,
},
},
],
});
});
},
};

View file

@ -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,
},
},
],
});
});
},
};

View file

@ -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 };
};

View file

@ -0,0 +1,98 @@
import {
ColorResolvable,
CommandInteraction,
MessageEmbed,
Permissions,
} from "discord.js";
import logger from "../../../../../logger";
import guildSchema from "../../../../../models/guild";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import getEmbedConfig from "../../../../../helpers/getEmbedConfig";
import getValues from "./components/getValues";
export default {
metadata: {
guildOnly: true,
ephemeral: true,
permissions: [Permissions.FLAGS.MANAGE_GUILD],
},
builder: (command: SlashCommandSubcommandBuilder) => {
return command
.setName("embeds")
.setDescription(`Embeds`)
.addStringOption((option) =>
option
.setName("success-color")
.setDescription("No provided description")
)
.addStringOption((option) =>
option.setName("wait-color").setDescription("No provided description")
)
.addStringOption((option) =>
option.setName("error-color").setDescription("No provided description")
)
.addStringOption((option) =>
option.setName("footer-icon").setDescription("No provided description")
)
.addStringOption((option) =>
option.setName("footer-text").setDescription("No provided description")
);
},
execute: async (interaction: CommandInteraction) => {
const { guild } = interaction;
if (!guild) throw new Error("Guild not found");
const { successColor, waitColor, errorColor, footerText, footerIcon } =
await getValues(interaction);
const embed = new MessageEmbed()
.setTitle("[:tools:] Embeds")
.setFooter({ text: footerText, iconURL: footerIcon })
.setTimestamp(new Date());
const guildData = await guildSchema.findOne({
guildId: guild.id,
});
if (!guildData) throw new Error("Guild data not found");
await guildData.save().then(async () => {
embed
.setDescription("Following embed configuration will be used.")
.setColor(successColor)
.addFields([
{
name: "🟢 Success Color",
value: `${successColor}`,
inline: true,
},
{
name: "🟡 Wait Color",
value: `${waitColor}`,
inline: true,
},
{
name: "🔴 Error Color",
value: `${errorColor}`,
inline: true,
},
{
name: "🖼️ Footer Icon",
value: `${footerIcon}`,
inline: true,
},
{
name: "📄 Footer Text",
value: `${footerText}`,
inline: true,
},
]);
return interaction.editReply({
embeds: [embed],
});
});
},
};

View file

@ -0,0 +1,9 @@
import audits from "./audits";
import credits from "./credits";
import points from "./points";
import cpgg from "./cpgg";
import shop from "./shop";
import welcome from "./welcome";
import embeds from "./embeds";
export default { audits, credits, points, cpgg, shop, welcome, embeds };

View file

@ -0,0 +1,106 @@
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("points")
.setDescription("Points")
.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("timeout")
.setDescription("Timeout between earning credits (milliseconds).")
);
},
execute: async (interaction: CommandInteraction) => {
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);
const { options, guild } = interaction;
const status = options?.getBoolean("status");
const rate = options?.getNumber("rate");
const timeout = options?.getNumber("timeout");
const minimumLength = options?.getNumber("minimum-length");
const guildDB = await guildSchema?.findOne({
guildId: guild?.id,
});
if (guildDB === null) {
return logger?.silly(`Guild not found in database.`);
}
guildDB.points.status = status !== null ? status : guildDB?.points?.status;
guildDB.points.rate = rate !== null ? rate : guildDB?.points?.rate;
guildDB.points.timeout =
timeout !== null ? timeout : guildDB?.points?.timeout;
guildDB.points.minimumLength =
minimumLength !== null ? minimumLength : guildDB?.points?.minimumLength;
await guildDB?.save()?.then(async () => {
logger?.silly(`Guild points updated.`);
return interaction?.editReply({
embeds: [
{
title: ":hammer: Settings - Guild [Points]",
description: `Points settings updated.`,
color: successColor,
fields: [
{
name: "🤖 Status",
value: `${guildDB?.points?.status}`,
inline: true,
},
{
name: "📈 Rate",
value: `${guildDB?.points?.rate}`,
inline: true,
},
{
name: "🔨 Minimum Length",
value: `${guildDB?.points?.minimumLength}`,
inline: true,
},
{
name: "⏰ Timeout",
value: `${guildDB?.points?.timeout}`,
inline: true,
},
],
timestamp: new Date(),
footer: {
iconURL: footerIcon,
text: footerText,
},
},
],
});
});
},
};

View file

@ -0,0 +1,87 @@
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("shop")
.setDescription("Shop")
.addBooleanOption((option) =>
option
.setName("roles-status")
.setDescription("Should roles be enabled?")
)
.addNumberOption((option) =>
option
.setName("roles-price-per-hour")
.setDescription("Price per hour for roles.")
);
},
execute: async (interaction: CommandInteraction) => {
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);
const { options, guild } = interaction;
const rolesStatus = options?.getBoolean("roles-status");
const rolesPricePerHour = options?.getNumber("roles-price-per-hour");
const guildDB = await guildSchema?.findOne({
guildId: guild?.id,
});
if (guildDB === null) {
return logger?.silly(`Guild not found in database.`);
}
guildDB.shop.roles.status =
rolesStatus !== null ? rolesStatus : guildDB?.shop?.roles?.status;
guildDB.shop.roles.pricePerHour =
rolesPricePerHour !== null
? rolesPricePerHour
: guildDB?.shop?.roles?.pricePerHour;
await guildDB?.save()?.then(async () => {
logger?.silly(`Guild shop updated.`);
return interaction?.editReply({
embeds: [
{
title: ":hammer: Settings - Guild [Shop]",
description: `Shop settings updated.`,
color: successColor,
fields: [
{
name: "🤖 Roles Status",
value: `${guildDB?.shop?.roles.status}`,
inline: true,
},
{
name: "🌊 Roles Price Per Hour",
value: `${guildDB?.shop?.roles.pricePerHour}`,
inline: true,
},
],
timestamp: new Date(),
footer: {
iconURL: footerIcon,
text: footerText,
},
},
],
});
});
},
};

View file

@ -0,0 +1,132 @@
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("welcome")
.setDescription("Welcome")
.addBooleanOption((option) =>
option.setName("status").setDescription("Should welcome be enabled?")
)
.addChannelOption((option) =>
option
.setName("join-channel")
.setDescription("Channel for join messages.")
.addChannelTypes(ChannelType.GuildText)
)
.addChannelOption((option) =>
option
.setName("leave-channel")
.setDescription("Channel for leave messages.")
.addChannelTypes(ChannelType.GuildText)
)
.addStringOption((option) =>
option
.setName("leave-message")
.setDescription("Message for leave messages.")
)
.addStringOption((option) =>
option
.setName("join-message")
.setDescription("Message for join messages.")
);
},
execute: async (interaction: CommandInteraction) => {
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);
const { options, guild } = interaction;
const status = options?.getBoolean("status");
const joinChannel = options?.getChannel("join-channel");
const leaveChannel = options?.getChannel("leave-channel");
const joinChannelMessage = options?.getString("join-message");
const leaveChannelMessage = options?.getString("leave-message");
const guildDB = await guildSchema?.findOne({
guildId: guild?.id,
});
if (guildDB === null) {
return logger?.silly(`Guild not found in database.`);
}
guildDB.welcome.status =
status !== null ? status : guildDB?.welcome?.status;
guildDB.welcome.joinChannel =
joinChannel !== null ? joinChannel.id : guildDB?.welcome?.joinChannel;
guildDB.welcome.leaveChannel =
leaveChannel !== null ? leaveChannel.id : guildDB?.welcome?.leaveChannel;
guildDB.welcome.joinChannelMessage =
joinChannelMessage !== null
? joinChannelMessage
: guildDB?.welcome?.joinChannelMessage;
guildDB.welcome.leaveChannelMessage =
leaveChannelMessage !== null
? leaveChannelMessage
: guildDB?.welcome?.leaveChannelMessage;
await guildDB?.save()?.then(async () => {
logger?.silly(`Guild welcome updated.`);
if (!guildDB?.welcome?.status) {
return interaction?.editReply({
embeds: [
{
title: "[:tools:] Welcome",
description: `This module is currently disabled, please enable it to continue.`,
color: successColor,
timestamp: new Date(),
footer: {
iconURL: footerIcon,
text: footerText,
},
},
],
});
}
return interaction?.editReply({
embeds: [
{
title: "[:tools:] Welcome",
description: `The following configuration will be used.
[👋] **Welcome**
**Channel**: <#${guildDB?.welcome?.joinChannel}>
**Message**: ${guildDB?.welcome?.joinChannelMessage}
[🚪] **Leave**
**Channel**: <#${guildDB?.welcome?.leaveChannel}>
**Message**: ${guildDB?.welcome?.leaveChannelMessage}`,
color: successColor,
timestamp: new Date(),
footer: {
iconURL: footerIcon,
text: footerText,
},
},
],
});
});
},
};