Skip to content

Commit 169d504

Browse files
author
xyzjesper
committed
Fix welcome and leave module
1 parent d6431c0 commit 169d504

20 files changed

+316
-323
lines changed

prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ model GuildLeaveSetup {
543543
// UPDATE SOON
544544
model GuildWelcomeSetup {
545545
id String @id @default(auto()) @map("_id") @db.ObjectId
546-
MessageTemplateId String
546+
MessageTemplateId String?
547547
ChannelId String
548548
Image Boolean
549549
ImageData WelcomeLeaveImageData?

src/modules/leave/buttons/leave-image-create-button-setup.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ export default {
1010
* @param {ExtendedClient} client
1111
*/
1212
async execute(interaction: ButtonInteraction, client: ExtendedClient) {
13-
const message = await interaction.message.fetch();
1413
const modal = new ModalBuilder();
1514

1615
const background = new TextInputBuilder();
1716
const theme = new TextInputBuilder();
1817
const color = new TextInputBuilder();
19-
const channel = new TextInputBuilder();
2018

2119
modal.setTitle("Create a Image").setCustomId("leave-image-create-setup");
2220

@@ -40,22 +38,13 @@ export default {
4038
.setStyle(TextInputStyle.Short)
4139
.setPlaceholder("Usage: #ffffff,#000000 - (Without the Space)")
4240
.setRequired(true);
43-
channel
44-
.setLabel("Channel ID")
45-
.setCustomId("leave-message-create-channel")
46-
.setStyle(TextInputStyle.Short)
47-
.setPlaceholder("NOT CHANGE this value if you not know what you are doing")
48-
.setValue(`${message.content}`)
49-
.setRequired(true);
5041

5142
modal.addComponents(
5243
new ActionRowBuilder<TextInputBuilder>().addComponents(background),
5344
new ActionRowBuilder<TextInputBuilder>().addComponents(theme),
5445
new ActionRowBuilder<TextInputBuilder>().addComponents(color),
55-
new ActionRowBuilder<TextInputBuilder>().addComponents(channel)
5646
);
5747

58-
interaction.showModal(modal);
59-
await message.delete();
48+
await interaction.showModal(modal);
6049
}
6150
};

src/modules/leave/commands/leave.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ export default {
2323
.setDescriptionLocalizations({
2424
de: "Nutze eine Nachricht für das Leave System"
2525
})
26+
)
27+
.addSubcommand((subCommand) =>
28+
subCommand
29+
.setName("channel")
30+
.setDescription("Set your Leave Channel")
31+
.setDescriptionLocalizations({
32+
de: "Setze den \"Verlassen\" Kanal"
33+
})
2634

2735
.addChannelOption((options) =>
2836
options
2937
.setName("channel")
3038
.setDescription("Set the Leave Channel")
31-
.setDescriptionLocalizations({de: "Setze den Leave Channel"})
39+
.setDescriptionLocalizations({
40+
de: "Setze den \"Verlassen\" Channel"
41+
})
3242
.addChannelTypes(
3343
ChannelType.GuildText,
3444
ChannelType.GuildAnnouncement
@@ -43,18 +53,6 @@ export default {
4353
.setDescriptionLocalizations({
4454
de: "Erstelle ein Image zu deiner Willkommens nachricht"
4555
})
46-
47-
.addChannelOption((options) =>
48-
options
49-
.setName("channel")
50-
.setDescription("Set the Willkommen Channel")
51-
.setDescriptionLocalizations({de: "Setze den Willkommen Channel"})
52-
.addChannelTypes(
53-
ChannelType.GuildText,
54-
ChannelType.GuildAnnouncement
55-
)
56-
.setRequired(true)
57-
)
5856
)
5957

6058
.addSubcommand((subCommand) =>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {
2+
ActionRowBuilder,
3+
ButtonStyle,
4+
ChatInputCommandInteraction,
5+
MessageFlags,
6+
ModalBuilder,
7+
PermissionFlagsBits,
8+
TextInputBuilder,
9+
TextInputStyle
10+
} from "discord.js";
11+
import {ExtendedClient} from "../../../../types/client.js";
12+
import {PermissionType} from "../../../../enums/permissionType.js";
13+
import {database} from "../../../../main/database.js";
14+
import {convertToEmojiPng} from "../../../../helper/emojis.js";
15+
16+
export default {
17+
subCommand: "leave.channel",
18+
options: {
19+
once: false,
20+
cooldown: 3000,
21+
botPermissions: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.ViewChannel],
22+
userPermissions: [PermissionFlagsBits.ManageMessages],
23+
userHasOnePermission: true,
24+
isGuildOwner: false,
25+
},
26+
/**
27+
*
28+
* @param {ChatInputCommandInteraction} interaction
29+
* @param {ExtendedClient} client
30+
*/
31+
async execute(interaction: ChatInputCommandInteraction, client: ExtendedClient) {
32+
33+
const channel = interaction.options.getChannel("channel");
34+
35+
const data = await database.guildLeaveSetup.findFirst({
36+
where: {
37+
GuildId: interaction.guild.id
38+
}
39+
})
40+
41+
if (!data) {
42+
await database.guildLeaveSetup.create({
43+
data: {
44+
Image: false,
45+
ChannelId: channel.id,
46+
Guilds: {
47+
connect: {
48+
GuildId: interaction.guild.id
49+
},
50+
}
51+
}
52+
})
53+
}
54+
55+
await database.guildLeaveSetup.update({
56+
where: {
57+
GuildId: interaction.guild.id
58+
},
59+
data: {
60+
ChannelId: channel.id
61+
}
62+
})
63+
64+
await interaction.reply({
65+
flags: MessageFlags.Ephemeral,
66+
content: `## ${await convertToEmojiPng("check", client.user.id)} Set Channel ${channel} for your welcome module.`
67+
})
68+
},
69+
};

src/modules/leave/commands/subCommand/leave.image.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,13 @@ export default {
7373
.setPlaceholder("#ffffff")
7474
.setRequired(true);
7575

76-
channel
77-
.setLabel("Channel ID")
78-
.setCustomId("leave-message-create-channel")
79-
.setStyle(TextInputStyle.Short)
80-
.setPlaceholder("NOT CHANGE")
81-
.setValue(`${interaction.options.getChannel("channel")?.id}`)
82-
.setRequired(false);
83-
8476
modal.addComponents(
8577
new ActionRowBuilder<TextInputBuilder>().addComponents(title),
8678
new ActionRowBuilder<TextInputBuilder>().addComponents(subtitle),
8779
new ActionRowBuilder<TextInputBuilder>().addComponents(text),
8880
new ActionRowBuilder<TextInputBuilder>().addComponents(color),
89-
new ActionRowBuilder<TextInputBuilder>().addComponents(channel)
9081
);
9182

92-
interaction.showModal(modal);
83+
await interaction.showModal(modal);
9384
}
9485
};
Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,58 @@
11
import {
2-
ActionRowBuilder,
3-
ButtonStyle,
4-
ChatInputCommandInteraction,
5-
MessageFlags,
6-
ModalBuilder,
7-
PermissionFlagsBits,
8-
TextInputBuilder,
9-
TextInputStyle
2+
ActionRowBuilder,
3+
ButtonStyle,
4+
ChatInputCommandInteraction,
5+
MessageFlags,
6+
ModalBuilder,
7+
PermissionFlagsBits,
8+
TextInputBuilder,
9+
TextInputStyle
1010
} from "discord.js";
11-
import { ExtendedClient } from "../../../../types/client.js";
12-
import { PermissionType } from "../../../../enums/permissionType.js";
11+
import {ExtendedClient} from "../../../../types/client.js";
12+
import {PermissionType} from "../../../../enums/permissionType.js";
1313

1414
export default {
15-
subCommand: "leave.message",
16-
options: {
17-
once: false,
18-
permission: PermissionType.LeaveWelcome,
19-
cooldown: 3000,
20-
botPermissions: [PermissionFlagsBits.SendMessages],
21-
userPermissions: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.ManageGuild],
22-
userHasOnePermission: true,
23-
isGuildOwner: false,
24-
},
25-
/**
26-
*
27-
* @param {ChatInputCommandInteraction} interaction
28-
* @param {ExtendedClient} client
29-
*/
30-
async execute(
31-
interaction: ChatInputCommandInteraction,
32-
client: ExtendedClient
33-
) {
34-
35-
if (!client.user) throw new Error("Client user not found");
36-
if (!interaction.guild) throw new Error("Guild not found");
37-
if (!interaction.member) throw new Error("Member not found");
38-
39-
const modal = new ModalBuilder();
40-
41-
const message = new TextInputBuilder();
42-
const channel = new TextInputBuilder();
43-
44-
modal.setTitle("Create a Message").setCustomId("leave-message-create");
45-
46-
message
47-
.setLabel("Message Template")
48-
.setCustomId("leave-message-create-name")
49-
.setStyle(TextInputStyle.Paragraph)
50-
.setRequired(true);
51-
channel
52-
.setLabel("Channel ID")
53-
.setCustomId("leave-message-create-channel")
54-
.setStyle(TextInputStyle.Short)
55-
.setPlaceholder("NOT CHANGE")
56-
.setValue(`${interaction.options.getChannel("channel")?.id}`)
57-
.setRequired(false);
58-
59-
modal.addComponents(
60-
new ActionRowBuilder<TextInputBuilder>().addComponents(message),
61-
new ActionRowBuilder<TextInputBuilder>().addComponents(channel)
62-
);
63-
64-
interaction.showModal(modal);
65-
}
15+
subCommand: "leave.message",
16+
options: {
17+
once: false,
18+
permission: PermissionType.LeaveWelcome,
19+
cooldown: 3000,
20+
botPermissions: [PermissionFlagsBits.SendMessages],
21+
userPermissions: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.ManageGuild],
22+
userHasOnePermission: true,
23+
isGuildOwner: false,
24+
},
25+
/**
26+
*
27+
* @param {ChatInputCommandInteraction} interaction
28+
* @param {ExtendedClient} client
29+
*/
30+
async execute(
31+
interaction: ChatInputCommandInteraction,
32+
client: ExtendedClient
33+
) {
34+
35+
if (!client.user) throw new Error("Client user not found");
36+
if (!interaction.guild) throw new Error("Guild not found");
37+
if (!interaction.member) throw new Error("Member not found");
38+
39+
const modal = new ModalBuilder();
40+
41+
const message = new TextInputBuilder();
42+
43+
modal.setTitle("Create a Message").setCustomId("leave-message-create");
44+
45+
message
46+
.setLabel("Message Template")
47+
.setCustomId("leave-message-create-name")
48+
.setStyle(TextInputStyle.Short)
49+
.setRequired(true);
50+
51+
52+
modal.addComponents(
53+
new ActionRowBuilder<TextInputBuilder>().addComponents(message),
54+
);
55+
56+
await interaction.showModal(modal);
57+
}
6658
};

src/modules/leave/modals/leave-image-create.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,10 @@ export default {
2626
}
2727
});
2828

29-
if (!data) {
30-
await database.guildLeaveSetup.create({
31-
data: {
32-
GuildId: interaction.guild?.id,
33-
ChannelId: interaction.fields.getTextInputValue(
34-
"leave-message-create-channel"
35-
),
36-
Image: true,
37-
ImageData: {
38-
Title: interaction.fields.getTextInputValue(
39-
"leave-image-create-title"
40-
),
41-
Subtitle: interaction.fields.getTextInputValue(
42-
"leave-image-create-subtitle"
43-
),
44-
Text: interaction.fields.getTextInputValue("leave-image-create-text"),
45-
Color: interaction.fields.getTextInputValue(
46-
"leave-image-create-color"
47-
),
48-
Gradient: "",
49-
Theme: "",
50-
Background: ""
51-
}
52-
}
53-
});
54-
}
29+
if (!data.ChannelId) return interaction.reply({
30+
content: `## ${await convertToEmojiPng("error", client.user.id)} There are no Channel set.`,
31+
flags: MessageFlags.Ephemeral,
32+
})
5533

5634
await database.guildLeaveSetup.update(
5735
{
@@ -82,8 +60,8 @@ export default {
8260
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
8361
new ButtonBuilder()
8462
.setCustomId("leave-image-create-button-setup")
85-
.setLabel("Setup the Image")
86-
.setStyle(ButtonStyle.Success)
63+
.setLabel("Image Card Setup")
64+
.setStyle(ButtonStyle.Secondary)
8765
);
8866

8967
await interaction.reply({

src/modules/leave/modals/leave-message-create.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,10 @@ export default {
1919
}
2020
});
2121

22-
if (!data) {
23-
await database.guildLeaveSetup.create({
24-
data: {
25-
GuildId: interaction.guild?.id,
26-
MessageTemplateId: interaction.fields.getTextInputValue(
27-
"leave-message-create-name"
28-
),
29-
ChannelId: interaction.fields.getTextInputValue(
30-
"leave-message-create-channel"
31-
),
32-
Image: true,
33-
}
34-
});
35-
}
22+
if (!data.ChannelId) return interaction.reply({
23+
content: `## ${await convertToEmojiPng("error", client.user.id)} There are no Channel set.`,
24+
flags: MessageFlags.Ephemeral,
25+
})
3626

3727
await database.guildLeaveSetup.update(
3828
{
@@ -43,10 +33,7 @@ export default {
4333
MessageTemplateId: interaction.fields.getTextInputValue(
4434
"leave-message-create-name"
4535
),
46-
ChannelId: interaction.fields.getTextInputValue(
47-
"leave-message-create-channel"
48-
),
49-
Image: true,
36+
Image: data.Image,
5037
}
5138
}
5239
);

0 commit comments

Comments
 (0)