Skip to content

Commit c14cd97

Browse files
committed
global server configuration
1 parent 5422074 commit c14cd97

3 files changed

Lines changed: 102 additions & 1 deletion

File tree

prisma/schema.prisma

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ model Guild {
1919
iconUrl String?
2020
createdAt DateTime @default(now())
2121
updatedAt DateTime @updatedAt
22-
2322
boosters Booster[]
2423
}
2524

@@ -52,4 +51,13 @@ model CustomRole {
5251
updatedAt DateTime @updatedAt
5352
5453
@@index([deleteScheduledAt])
54+
}
55+
56+
model GuildSetting {
57+
uid String @id @default(cuid())
58+
gid String @unique
59+
greetChannelId String
60+
logChannelId String
61+
createdAt DateTime @default(now()) // not the time the server was created, rather the time it was setted up at.
62+
lastCheckup DateTime @default(now())
5563
}

src/commands/setup.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {
2+
SlashCommandBuilder,
3+
ModalBuilder,
4+
ChannelType,
5+
LabelBuilder,
6+
MessageFlags,
7+
} from "discord.js";
8+
import { Command } from "../base/classes/command.js";
9+
import { prisma } from "../libs/database.js";
10+
11+
export default new Command({
12+
info: new SlashCommandBuilder()
13+
.setName("setup")
14+
.setDescription("Setup this server!"),
15+
async execute(interaction) {
16+
if (!interaction.guild) return;
17+
18+
const serversetup = await prisma.guildSetting.findFirst({
19+
where: {
20+
gid: interaction.guild.id
21+
}
22+
});
23+
24+
if (serversetup) {
25+
await interaction.reply({ content: "This server has been setted up.", flags: [MessageFlags.Ephemeral]})
26+
return
27+
}
28+
29+
const modal = new ModalBuilder().setTitle('Setup').setCustomId('setupboostifymodal')
30+
const GreetingChannelRes = new LabelBuilder()
31+
.setLabel('Where should boosts be sent?')
32+
.setChannelSelectMenuComponent(
33+
(channel) =>
34+
channel.addChannelTypes(ChannelType.GuildAnnouncement, ChannelType.GuildText)
35+
.setCustomId('boostchannel')
36+
.setRequired(true)
37+
);
38+
39+
const LoggingChannel = new LabelBuilder()
40+
.setLabel('Where should logs be sent?')
41+
.setChannelSelectMenuComponent(
42+
(channel) =>
43+
channel.addChannelTypes(ChannelType.GuildText)
44+
.setCustomId('logs')
45+
.setRequired(true)
46+
);
47+
48+
modal.addLabelComponents(GreetingChannelRes, LoggingChannel);
49+
interaction.showModal(modal);
50+
},
51+
ownerOnly: true,
52+
})
53+

src/events/setupResponse.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
ChannelType,
3+
Client,
4+
Events,
5+
Interaction,
6+
MessageFlags
7+
} from "discord.js";
8+
import { prisma } from "../libs/database.js";
9+
10+
export default {
11+
name: Events.InteractionCreate,
12+
async execute(_client: Client, interaction: Interaction) {
13+
if (!interaction.isModalSubmit()) return;
14+
if (!interaction.guild) return;
15+
if (interaction.customId != 'setupboostifymodal') return;
16+
const boostchannel = interaction.fields.getSelectedChannels('boostchannel', true, [ChannelType.GuildText, ChannelType.GuildAnnouncement]);
17+
const logsChannel = interaction.fields.getSelectedChannels('logs', true, [ChannelType.GuildText]);
18+
19+
const boostChannelId = boostchannel.first()
20+
const logChannelId = logsChannel.first()
21+
22+
if (!boostChannelId || !logChannelId) {
23+
return interaction.reply({ content: 'Please select both channels.', ephemeral: true });
24+
}
25+
26+
await prisma.guildSetting.create({
27+
data: {
28+
uid: crypto.randomUUID(),
29+
gid: interaction.guild!.id,
30+
greetChannelId: boostChannelId.id,
31+
logChannelId: logChannelId.id,
32+
}
33+
});
34+
35+
await interaction.reply({
36+
content: `✅ Setup complete!\n- Boost notifications: <#${boostChannelId}>\n- Logs: <#${logChannelId}>`,
37+
flags: MessageFlags.Ephemeral,
38+
});
39+
}
40+
};

0 commit comments

Comments
 (0)