🏷️ add welcome settings
This commit is contained in:
parent
5c5859a3e4
commit
b1451c790a
3 changed files with 155 additions and 1 deletions
|
@ -17,6 +17,13 @@ interface IGuild {
|
|||
minimumLength: number;
|
||||
timeout: number;
|
||||
};
|
||||
welcome: {
|
||||
status: boolean;
|
||||
joinChannel: string;
|
||||
leaveChannel: string;
|
||||
joinChannelMessage: string;
|
||||
leaveChannelMessage: string;
|
||||
};
|
||||
}
|
||||
|
||||
const guildSchema = new Schema<IGuild>(
|
||||
|
@ -83,6 +90,16 @@ const guildSchema = new Schema<IGuild>(
|
|||
default: 5000,
|
||||
},
|
||||
},
|
||||
welcome: {
|
||||
status: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
joinChannel: { type: String },
|
||||
leaveChannel: { type: String },
|
||||
joinChannelMessage: { type: String },
|
||||
leaveChannelMessage: { type: String },
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
|
|
@ -11,6 +11,7 @@ import logger from "@logger";
|
|||
import pterodactyl from "./modules/pterodactyl";
|
||||
import credits from "./modules/credits";
|
||||
import points from "./modules/points";
|
||||
import welcome from "./modules/welcome";
|
||||
import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
|
||||
|
||||
// Function
|
||||
|
@ -21,7 +22,8 @@ export default {
|
|||
.setDescription("Guild settings.")
|
||||
.addSubcommand(pterodactyl.data)
|
||||
.addSubcommand(credits.data)
|
||||
.addSubcommand(points.data);
|
||||
.addSubcommand(points.data)
|
||||
.addSubcommand(welcome.data);
|
||||
},
|
||||
execute: async (interaction: CommandInteraction) => {
|
||||
// Destructure member
|
||||
|
@ -59,6 +61,10 @@ export default {
|
|||
logger?.verbose(`Executing points subcommand`);
|
||||
|
||||
return points.execute(interaction);
|
||||
} else if (options?.getSubcommand() === "welcome") {
|
||||
logger?.verbose(`Executing welcome subcommand`);
|
||||
|
||||
return welcome.execute(interaction);
|
||||
}
|
||||
|
||||
logger?.verbose(`No subcommand found`);
|
||||
|
|
131
src/plugins/settings/guild/modules/welcome.ts
Normal file
131
src/plugins/settings/guild/modules/welcome.ts
Normal file
|
@ -0,0 +1,131 @@
|
|||
// 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";
|
||||
import { ChannelType } from "discord-api-types/v10";
|
||||
|
||||
// Function
|
||||
export default {
|
||||
data: (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.")
|
||||
.addChannelType(ChannelType.GuildText as number)
|
||||
)
|
||||
.addChannelOption((option) =>
|
||||
option
|
||||
.setName("leave-channel")
|
||||
.setDescription("Channel for leave messages.")
|
||||
.addChannelType(ChannelType.GuildText as number)
|
||||
)
|
||||
.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) => {
|
||||
// Destructure member
|
||||
const { options, guild } = interaction;
|
||||
|
||||
// Get options
|
||||
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");
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guildSchema?.findOne({
|
||||
guildId: guild?.id,
|
||||
});
|
||||
|
||||
if (guildDB === null) {
|
||||
return logger?.verbose(`Guild not found in database.`);
|
||||
}
|
||||
|
||||
// Modify values
|
||||
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;
|
||||
|
||||
// Save guild
|
||||
await guildDB?.save()?.then(async () => {
|
||||
logger?.verbose(`Guild welcome updated.`);
|
||||
|
||||
return interaction?.editReply({
|
||||
embeds: [
|
||||
{
|
||||
title: ":hammer: Settings - Guild [Welcome]",
|
||||
description: `Welcome settings updated.`,
|
||||
color: successColor,
|
||||
fields: [
|
||||
{
|
||||
name: "🤖 Status",
|
||||
value: `${guildDB?.welcome?.status}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🌊 Join Channel",
|
||||
value: `${guildDB?.welcome?.joinChannel}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "🌊 Leave Channel",
|
||||
value: `${guildDB?.welcome?.leaveChannel}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📄 Join Channel Message",
|
||||
value: `${guildDB?.welcome?.joinChannelMessage}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "📄 Leave Channel Message",
|
||||
value: `${guildDB?.welcome?.leaveChannelMessage}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: {
|
||||
iconURL: footerIcon,
|
||||
text: footerText,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
Loading…
Add table
Reference in a new issue