Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 8766db7

Browse files
authored
feat: join a server using /joinserver (#241)
* feat: join a server using `/joinserver` * add fallback to get invite from server config
1 parent 844670f commit 8766db7

File tree

4 files changed

+339
-102
lines changed

4 files changed

+339
-102
lines changed

src/commands/Main/connection/edit.ts

Lines changed: 9 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type Context from '#src/core/CommandContext/Context.js';
1919
import { RegisterInteractionHandler } from '#src/decorators/RegisterInteractionHandler.js';
2020
import Logger from '#src/utils/Logger.js';
2121
import { isGuildTextBasedChannel } from '#utils/ChannelUtls.js';
22-
import { updateConnection } from '#utils/ConnectedListUtils.js';
22+
import { handleConnectionInviteCreation, updateConnection } from '#utils/ConnectedListUtils.js';
2323
import Constants from '#utils/Constants.js';
2424
import { CustomID } from '#utils/CustomID.js';
2525
import db from '#utils/Db.js';
@@ -91,9 +91,7 @@ export default class ConnectionEditSubcommand extends BaseCommand {
9191
});
9292
}
9393

94-
const iconURL = ctx.guild?.iconURL() ?? ctx.user.avatarURL()?.toString();
95-
96-
const embed = await buildEditEmbed(ctx.client, channelId, iconURL, locale);
94+
const embed = await buildEditEmbed(ctx.client, channelId, locale);
9795
const editSelect = buildEditSelect(ctx.client, channelId, ctx.user.id, locale);
9896
const channelSelect = buildChannelSelect(channelId, ctx.user.id);
9997

@@ -112,49 +110,8 @@ export default class ConnectionEditSubcommand extends BaseCommand {
112110
const customId = CustomID.parseCustomId(interaction.customId);
113111
const locale = await fetchUserLocale(interaction.user.id);
114112

115-
if (customId.suffix === 'invite') {
116-
await interaction.deferReply({ flags: ['Ephemeral'] });
117-
118-
const invite = interaction.fields.getTextInputValue('connInviteField');
119-
const [channelId] = customId.args;
120-
121-
if (!invite) {
122-
await updateConnection({ channelId }, { invite: { unset: true } });
123-
await interaction.followUp({
124-
content: t('connection.inviteRemoved', locale, {
125-
emoji: getEmoji('tick_icon', interaction.client),
126-
}),
127-
flags: ['Ephemeral'],
128-
});
129-
return;
130-
}
131-
132-
const validInvite = Constants.Regex.DiscordInvite.test(invite);
133-
const fetchedInvite = validInvite
134-
? await interaction.client?.fetchInvite(invite).catch(() => null)
135-
: null;
136113

137-
if (fetchedInvite?.guild?.id !== interaction.guildId) {
138-
await interaction.followUp({
139-
// FIXME: remove ts
140-
content: t('connection.setInviteError', locale, {
141-
emoji: getEmoji('x_icon', interaction.client),
142-
}),
143-
flags: ['Ephemeral'],
144-
});
145-
return;
146-
}
147-
148-
await updateConnection({ channelId }, { invite });
149-
150-
await interaction.followUp({
151-
content: t('connection.inviteAdded', locale, {
152-
emoji: getEmoji('tick_icon', interaction.client),
153-
}),
154-
flags: ['Ephemeral'],
155-
});
156-
}
157-
else if (customId.suffix === 'embed_color') {
114+
if (customId.suffix === 'embed_color') {
158115
const embedColor = interaction.fields.getTextInputValue('embed_color');
159116

160117
if (!Constants.Regex.Hexcode.test(embedColor)) {
@@ -183,14 +140,7 @@ export default class ConnectionEditSubcommand extends BaseCommand {
183140

184141
await interaction.message
185142
?.edit({
186-
embeds: [
187-
await buildEditEmbed(
188-
interaction.client,
189-
customId.args[0],
190-
interaction.guild?.iconURL() ?? interaction.user.avatarURL()?.toString(),
191-
locale,
192-
),
193-
],
143+
embeds: [await buildEditEmbed(interaction.client, customId.args[0], locale)],
194144
})
195145
.catch(() => null);
196146
}
@@ -232,23 +182,9 @@ export default class ConnectionEditSubcommand extends BaseCommand {
232182
break;
233183

234184
case 'invite': {
235-
const modal = new ModalBuilder()
236-
.setTitle('Add Invite Link')
237-
.setCustomId(
238-
new CustomID().setIdentifier('connectionModal', 'invite').setArgs(channelId).toString(),
239-
)
240-
.addComponents(
241-
new ActionRowBuilder<TextInputBuilder>().addComponents(
242-
new TextInputBuilder()
243-
.setLabel('Invite Link')
244-
.setValue('https://discord.gg/')
245-
.setCustomId('connInviteField')
246-
.setRequired(false)
247-
.setStyle(TextInputStyle.Short),
248-
),
249-
);
250-
251-
await interaction.showModal(modal);
185+
// TODO: maybe send them error message
186+
if (!interaction.inCachedGuild()) return;
187+
await handleConnectionInviteCreation(interaction, connection, locale);
252188
break;
253189
}
254190
case 'embed_color': {
@@ -280,12 +216,7 @@ export default class ConnectionEditSubcommand extends BaseCommand {
280216
break;
281217
}
282218

283-
const newEmbeds = await buildEditEmbed(
284-
interaction.client,
285-
channelId,
286-
interaction.guild?.iconURL() ?? interaction.user.avatarURL()?.toString(),
287-
locale,
288-
);
219+
const newEmbeds = await buildEditEmbed(interaction.client, channelId, locale);
289220
const msgBody = { embeds: [newEmbeds] };
290221

291222
try {
@@ -365,14 +296,7 @@ export default class ConnectionEditSubcommand extends BaseCommand {
365296
const channelSelect = buildChannelSelect(newChannel.id, interaction.user.id);
366297

367298
await interaction.editReply({
368-
embeds: [
369-
await buildEditEmbed(
370-
interaction.client,
371-
newChannel.id,
372-
interaction.guild?.iconURL() ?? interaction.user.avatarURL()?.toString(),
373-
locale,
374-
),
375-
],
299+
embeds: [await buildEditEmbed(interaction.client, newChannel.id, locale)],
376300
components: [channelSelect, editSelect],
377301
});
378302
}

0 commit comments

Comments
 (0)