♻️ slash command builder
This commit is contained in:
parent
6a146fe1a3
commit
27b6e74d16
9 changed files with 403 additions and 397 deletions
|
@ -1,99 +0,0 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction } from "discord.js";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
|
||||||
|
|
||||||
//Handlers
|
|
||||||
import logger from "@logger";
|
|
||||||
|
|
||||||
// Models
|
|
||||||
import guildSchema from "@schemas/guild";
|
|
||||||
|
|
||||||
// Function
|
|
||||||
export default async (interaction: CommandInteraction) => {
|
|
||||||
// Destructure member
|
|
||||||
const { guild, user, options } = interaction;
|
|
||||||
|
|
||||||
// Get options
|
|
||||||
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");
|
|
||||||
|
|
||||||
// Get guild object
|
|
||||||
const guildDB = await guildSchema?.findOne({
|
|
||||||
guildId: guild?.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (guildDB === null) return;
|
|
||||||
|
|
||||||
// Modify values
|
|
||||||
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;
|
|
||||||
|
|
||||||
// Save guild
|
|
||||||
await guildDB?.save()?.then(async () => {
|
|
||||||
// Embed object
|
|
||||||
const embed = {
|
|
||||||
title: ":tools: Settings - Guild [Credits]",
|
|
||||||
description: "Following settings is set!",
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send debug message
|
|
||||||
logger?.debug(
|
|
||||||
`Guild: ${guild?.id} User: ${user.id} has changed credit details.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -1,83 +0,0 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction } from "discord.js";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
import logger from "../../../../logger";
|
|
||||||
|
|
||||||
// Models
|
|
||||||
import guildSchema from "../../../../database/schemas/guild";
|
|
||||||
|
|
||||||
// Function
|
|
||||||
export default async (interaction: CommandInteraction) => {
|
|
||||||
// Destructure member
|
|
||||||
const { options, guild, user } = interaction;
|
|
||||||
|
|
||||||
// Get options
|
|
||||||
const status = options?.getBoolean("status");
|
|
||||||
const rate = options?.getNumber("rate");
|
|
||||||
const timeout = options?.getNumber("timeout");
|
|
||||||
const minimumLength = options?.getNumber("minimum-length");
|
|
||||||
|
|
||||||
// Get guild object
|
|
||||||
const guildDB = await guildSchema?.findOne({
|
|
||||||
guildId: guild?.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (guildDB === null) return;
|
|
||||||
|
|
||||||
// Modify values
|
|
||||||
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;
|
|
||||||
|
|
||||||
// Save guild
|
|
||||||
await guildDB?.save()?.then(async () => {
|
|
||||||
// Create embed object
|
|
||||||
const embed = {
|
|
||||||
title: ":hammer: Settings - Guild [Points]",
|
|
||||||
description: "Following settings is set!",
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send debug message
|
|
||||||
logger?.debug(
|
|
||||||
`Guild: ${guild?.id} User: ${user?.id} has changed credit details.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -1,51 +0,0 @@
|
||||||
// Dependencies
|
|
||||||
import { CommandInteraction } from "discord.js";
|
|
||||||
|
|
||||||
// Configurations
|
|
||||||
import { successColor, footerText, footerIcon } from "@config/embed";
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
import logger from "../../../../logger";
|
|
||||||
|
|
||||||
// Models
|
|
||||||
import apiSchema from "../../../../database/schemas/api";
|
|
||||||
import encryption from "../../../../handlers/encryption";
|
|
||||||
|
|
||||||
// Function
|
|
||||||
export default async (interaction: CommandInteraction) => {
|
|
||||||
// Destructure member
|
|
||||||
const { options, guild, user } = interaction;
|
|
||||||
|
|
||||||
// Get options
|
|
||||||
const url = options?.getString("url");
|
|
||||||
const token = encryption.encrypt(options?.getString("token"));
|
|
||||||
|
|
||||||
// Update API credentials
|
|
||||||
await apiSchema
|
|
||||||
?.findOneAndUpdate(
|
|
||||||
{ guildId: guild?.id },
|
|
||||||
{ url, token },
|
|
||||||
{ new: true, upsert: true }
|
|
||||||
)
|
|
||||||
.then(async () => {
|
|
||||||
// Embed object
|
|
||||||
const embed = {
|
|
||||||
title: ":hammer: Settings - Guild [Pterodactyl]",
|
|
||||||
color: successColor,
|
|
||||||
description: "Pterodactyl settings is saved!",
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: {
|
|
||||||
iconURL: footerIcon as string,
|
|
||||||
text: footerText as string,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send debug message
|
|
||||||
logger?.debug(
|
|
||||||
`Guild: ${guild?.id} User: ${user?.id} has changed api credentials.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return interaction reply
|
|
||||||
return interaction?.editReply({ embeds: [embed] });
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -8,14 +8,25 @@ import { errorColor, footerText, footerIcon } from "@config/embed";
|
||||||
import logger from "../../../logger";
|
import logger from "../../../logger";
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
import pterodactyl from "./addons/pterodactyl";
|
import pterodactyl from "./modules/pterodactyl";
|
||||||
import credits from "./addons/credits";
|
import credits from "./modules/credits";
|
||||||
import points from "./addons/points";
|
import points from "./modules/points";
|
||||||
|
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default async (interaction: CommandInteraction) => {
|
export default {
|
||||||
|
data: (group: SlashCommandSubcommandGroupBuilder) => {
|
||||||
|
return group
|
||||||
|
.setName("guild")
|
||||||
|
.setDescription("Manage guild settings.")
|
||||||
|
.addSubcommand(pterodactyl.data)
|
||||||
|
.addSubcommand(credits.data)
|
||||||
|
.addSubcommand(points.data);
|
||||||
|
},
|
||||||
|
execute: async (interaction: CommandInteraction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
const { memberPermissions, options, commandName, user, guild } = interaction;
|
const { memberPermissions, options, commandName, user, guild } =
|
||||||
|
interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) {
|
if (!memberPermissions?.has(Permissions?.FLAGS?.MANAGE_GUILD)) {
|
||||||
|
@ -38,19 +49,19 @@ export default async (interaction: CommandInteraction) => {
|
||||||
// Module - Pterodactyl
|
// Module - Pterodactyl
|
||||||
if (options?.getSubcommand() === "pterodactyl") {
|
if (options?.getSubcommand() === "pterodactyl") {
|
||||||
// Execute Module - Pterodactyl
|
// Execute Module - Pterodactyl
|
||||||
return pterodactyl(interaction);
|
return pterodactyl.execute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module - Credits
|
// Module - Credits
|
||||||
else if (options?.getSubcommand() === "credits") {
|
else if (options?.getSubcommand() === "credits") {
|
||||||
// Execute Module - Credits
|
// Execute Module - Credits
|
||||||
return credits(interaction);
|
return credits.execute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module - Points
|
// Module - Points
|
||||||
else if (options?.getSubcommand() === "points") {
|
else if (options?.getSubcommand() === "points") {
|
||||||
// Execute Module - Points
|
// Execute Module - Points
|
||||||
return points(interaction);
|
return points.execute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send debug message
|
// Send debug message
|
||||||
|
@ -59,4 +70,5 @@ export default async (interaction: CommandInteraction) => {
|
||||||
user?.id
|
user?.id
|
||||||
} executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}`
|
} executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}`
|
||||||
);
|
);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
134
src/plugins/settings/guild/modules/credits.ts
Normal file
134
src/plugins/settings/guild/modules/credits.ts
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
// Dependencies
|
||||||
|
import { CommandInteraction } from "discord.js";
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||||
|
|
||||||
|
//Handlers
|
||||||
|
import logger from "@logger";
|
||||||
|
|
||||||
|
// Models
|
||||||
|
import guildSchema from "@schemas/guild";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
|
// Function
|
||||||
|
export default {
|
||||||
|
data: (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 (milliseconds).")
|
||||||
|
)
|
||||||
|
.addNumberOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("timeout")
|
||||||
|
.setDescription("Timeout between earning credits (milliseconds).")
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: async (interaction: CommandInteraction) => {
|
||||||
|
// Destructure member
|
||||||
|
const { guild, user, options } = interaction;
|
||||||
|
|
||||||
|
// Get options
|
||||||
|
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");
|
||||||
|
|
||||||
|
// Get guild object
|
||||||
|
const guildDB = await guildSchema?.findOne({
|
||||||
|
guildId: guild?.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (guildDB === null) return;
|
||||||
|
|
||||||
|
// Modify values
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Save guild
|
||||||
|
await guildDB?.save()?.then(async () => {
|
||||||
|
// Embed object
|
||||||
|
const embed = {
|
||||||
|
title: ":tools: Settings - Guild [Credits]",
|
||||||
|
description: "Following settings is set!",
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send debug message
|
||||||
|
logger?.debug(
|
||||||
|
`Guild: ${guild?.id} User: ${user.id} has changed credit details.`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return interaction reply
|
||||||
|
return interaction?.editReply({ embeds: [embed] });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
107
src/plugins/settings/guild/modules/points.ts
Normal file
107
src/plugins/settings/guild/modules/points.ts
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
// Dependencies
|
||||||
|
import { CommandInteraction } from "discord.js";
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
import logger from "../../../../logger";
|
||||||
|
|
||||||
|
// Models
|
||||||
|
import guildSchema from "../../../../database/schemas/guild";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
|
// Function
|
||||||
|
export default {
|
||||||
|
data: (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) => {
|
||||||
|
// Destructure member
|
||||||
|
const { options, guild, user } = interaction;
|
||||||
|
|
||||||
|
// Get options
|
||||||
|
const status = options?.getBoolean("status");
|
||||||
|
const rate = options?.getNumber("rate");
|
||||||
|
const timeout = options?.getNumber("timeout");
|
||||||
|
const minimumLength = options?.getNumber("minimum-length");
|
||||||
|
|
||||||
|
// Get guild object
|
||||||
|
const guildDB = await guildSchema?.findOne({
|
||||||
|
guildId: guild?.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (guildDB === null) return;
|
||||||
|
|
||||||
|
// Modify values
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Save guild
|
||||||
|
await guildDB?.save()?.then(async () => {
|
||||||
|
// Create embed object
|
||||||
|
const embed = {
|
||||||
|
title: ":hammer: Settings - Guild [Points]",
|
||||||
|
description: "Following settings is set!",
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send debug message
|
||||||
|
logger?.debug(
|
||||||
|
`Guild: ${guild?.id} User: ${user?.id} has changed credit details.`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return interaction reply
|
||||||
|
return interaction?.editReply({ embeds: [embed] });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
68
src/plugins/settings/guild/modules/pterodactyl.ts
Normal file
68
src/plugins/settings/guild/modules/pterodactyl.ts
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// Dependencies
|
||||||
|
import { CommandInteraction } from "discord.js";
|
||||||
|
|
||||||
|
// Configurations
|
||||||
|
import { successColor, footerText, footerIcon } from "@config/embed";
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
import logger from "../../../../logger";
|
||||||
|
|
||||||
|
// Models
|
||||||
|
import apiSchema from "../../../../database/schemas/api";
|
||||||
|
import encryption from "../../../../handlers/encryption";
|
||||||
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
||||||
|
|
||||||
|
// Function
|
||||||
|
export default {
|
||||||
|
data: (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
return command
|
||||||
|
.setName("pterodactyl")
|
||||||
|
.setDescription("Controlpanel.gg")
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option.setName("url").setDescription("The api url").setRequired(true)
|
||||||
|
)
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("token")
|
||||||
|
.setDescription("The api token")
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: async (interaction: CommandInteraction) => {
|
||||||
|
// Destructure member
|
||||||
|
const { options, guild, user } = interaction;
|
||||||
|
|
||||||
|
// Get options
|
||||||
|
const url = options?.getString("url");
|
||||||
|
const token = encryption.encrypt(options?.getString("token"));
|
||||||
|
|
||||||
|
// Update API credentials
|
||||||
|
await apiSchema
|
||||||
|
?.findOneAndUpdate(
|
||||||
|
{ guildId: guild?.id },
|
||||||
|
{ url, token },
|
||||||
|
{ new: true, upsert: true }
|
||||||
|
)
|
||||||
|
.then(async () => {
|
||||||
|
// Embed object
|
||||||
|
const embed = {
|
||||||
|
title: ":hammer: Settings - Guild [Pterodactyl]",
|
||||||
|
color: successColor,
|
||||||
|
description: "Pterodactyl settings is saved!",
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: {
|
||||||
|
iconURL: footerIcon as string,
|
||||||
|
text: footerText as string,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send debug message
|
||||||
|
logger?.debug(
|
||||||
|
`Guild: ${guild?.id} User: ${user?.id} has changed api credentials.`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return interaction reply
|
||||||
|
return interaction?.editReply({ embeds: [embed] });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
|
@ -15,111 +15,9 @@ export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("settings")
|
.setName("settings")
|
||||||
.setDescription("Manage settings.")
|
.setDescription("Manage settings.")
|
||||||
.addSubcommandGroup((group) =>
|
.addSubcommandGroup(guildGroup.data)
|
||||||
group
|
.addSubcommandGroup(userGroup.data),
|
||||||
.setName("guild")
|
|
||||||
.setDescription("Manage guild settings.")
|
|
||||||
.addSubcommand((command) =>
|
|
||||||
command
|
|
||||||
.setName("pterodactyl")
|
|
||||||
.setDescription("Controlpanel.gg")
|
|
||||||
.addStringOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("url")
|
|
||||||
.setDescription("The api url")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
.addStringOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("token")
|
|
||||||
.setDescription("The api token")
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.addSubcommand((command) =>
|
|
||||||
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 (milliseconds)."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.addNumberOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("timeout")
|
|
||||||
.setDescription(
|
|
||||||
"Timeout between earning credits (milliseconds)."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.addSubcommand((command) =>
|
|
||||||
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)."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.addSubcommandGroup((group) =>
|
|
||||||
group
|
|
||||||
.setName("user")
|
|
||||||
.setDescription("Manage user settings.")
|
|
||||||
.addSubcommand((command) =>
|
|
||||||
command
|
|
||||||
.setName("appearance")
|
|
||||||
.setDescription("Manage your appearance")
|
|
||||||
.addStringOption((option) =>
|
|
||||||
option
|
|
||||||
.setName("language")
|
|
||||||
.setDescription("Configure your language")
|
|
||||||
.addChoice("English", "en")
|
|
||||||
.addChoice("Swedish", "sv")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
// Destructure
|
// Destructure
|
||||||
const { options, commandName, user, guild } = interaction;
|
const { options, commandName, user, guild } = interaction;
|
||||||
|
@ -127,12 +25,12 @@ export default {
|
||||||
// Group - Guild
|
// Group - Guild
|
||||||
if (options.getSubcommandGroup() === "guild") {
|
if (options.getSubcommandGroup() === "guild") {
|
||||||
// Execute Group - Guild
|
// Execute Group - Guild
|
||||||
await guildGroup(interaction);
|
await guildGroup.execute(interaction);
|
||||||
}
|
}
|
||||||
// Group - User
|
// Group - User
|
||||||
else if (options.getSubcommandGroup() === "user") {
|
else if (options.getSubcommandGroup() === "user") {
|
||||||
// Execute Group - User
|
// Execute Group - User
|
||||||
await userGroup(interaction);
|
await userGroup.execute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send debug message
|
// Send debug message
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// Dependencies
|
// Dependencies
|
||||||
|
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
||||||
import { CommandInteraction } from "discord.js";
|
import { CommandInteraction } from "discord.js";
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
|
@ -8,7 +9,25 @@ import logger from "../../../logger";
|
||||||
import appearance from "./modules/appearance";
|
import appearance from "./modules/appearance";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default async (interaction: CommandInteraction) => {
|
export default {
|
||||||
|
data: (group: SlashCommandSubcommandGroupBuilder) => {
|
||||||
|
return group
|
||||||
|
.setName("user")
|
||||||
|
.setDescription("Manage user settings.")
|
||||||
|
.addSubcommand((command) =>
|
||||||
|
command
|
||||||
|
.setName("appearance")
|
||||||
|
.setDescription("Manage your appearance")
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("language")
|
||||||
|
.setDescription("Configure your language")
|
||||||
|
.addChoice("English", "en")
|
||||||
|
.addChoice("Swedish", "sv")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
execute: async (interaction: CommandInteraction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
const { guild, user, options, commandName } = interaction;
|
const { guild, user, options, commandName } = interaction;
|
||||||
|
|
||||||
|
@ -24,4 +43,5 @@ export default async (interaction: CommandInteraction) => {
|
||||||
user?.id
|
user?.id
|
||||||
} executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}`
|
} executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}`
|
||||||
);
|
);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue