@@ -9,7 +9,7 @@ import { getEmoji } from '#src/utils/EmojiUtils.js';
99import { t } from '#src/utils/Locale.js' ;
1010import { replyWithUnknownMessage } from '#src/utils/moderation/modPanel/utils.js' ;
1111import { findOriginalMessage } from '#src/utils/network/messageUtils.js' ;
12- import { fetchUserLocale } from '#src/utils/Utils.js' ;
12+ import { fetchUserLocale , resolveEval } from '#src/utils/Utils.js' ;
1313import type { Connection } from '@prisma/client' ;
1414import { stripIndents } from 'common-tags' ;
1515import {
@@ -18,7 +18,6 @@ import {
1818 ButtonBuilder ,
1919 type ButtonInteraction ,
2020 ButtonStyle ,
21- type Message ,
2221 type ModalSubmitInteraction ,
2322} from 'discord.js' ;
2423
@@ -49,7 +48,6 @@ export default class JoinRequestCommand extends BaseCommand {
4948 }
5049
5150 async execute ( ctx : Context ) : Promise < void > {
52- const targetMessage = await ctx . getTargetMessage ( 'messageorserverid' ) ;
5351 const commandChannelConnection = await fetchConnection ( ctx . channelId ) ;
5452
5553 if ( ! commandChannelConnection ) {
@@ -58,22 +56,23 @@ export default class JoinRequestCommand extends BaseCommand {
5856 }
5957
6058 // Resolve the target server ID from the message or provided option.
61- const targetServerId = await this . resolveTargetServerId (
62- targetMessage ,
63- ctx . options . getString ( 'messageorserverid' ) ,
64- ) ;
59+ const targetServerId = await this . resolveTargetServerId ( ctx ) ;
6560
66- if ( ! targetMessage && ! targetServerId ) {
67- await ctx . reply ( 'You must provide a message ID or server ID' ) ;
61+ if ( ! targetServerId ) {
62+ await ctx . reply ( {
63+ content : 'You must provide a message ID or server ID' ,
64+ flags : [ 'Ephemeral' ] ,
65+ } ) ;
6866 return ;
6967 }
7068
7169 // Retrieve the connection for the target server.
7270 const connection = await this . findTargetConnection ( commandChannelConnection , targetServerId ) ;
7371 // Fallback: if no invite is available from the connection, try fetching server data.
74- const serverData = targetServerId && ! connection ?. invite
75- ? await db . serverData . findFirst ( { where : { id : targetServerId } } )
76- : null ;
72+ const serverData =
73+ targetServerId && ! connection ?. invite
74+ ? await db . serverData . findFirst ( { where : { id : targetServerId } } )
75+ : null ;
7776
7877 // TODO: implement disabling join request in `/connection edit`
7978 if ( connection ?. joinRequestsDisabled ) {
@@ -83,20 +82,22 @@ export default class JoinRequestCommand extends BaseCommand {
8382 return ;
8483 }
8584
86- const invite = connection ?. invite ||
85+ const invite =
86+ connection ?. invite ||
8787 ( serverData ?. inviteCode ? `https://discord.gg/${ serverData . inviteCode } ` : null ) ;
8888
8989 if ( invite && targetServerId ) {
9090 const server = await ctx . client . fetchGuild ( targetServerId ) ;
9191 await ctx . reply ( {
92- content : ' I have DM\ 'd you the invite link to the server!' ,
92+ content : ` ${ ctx . getEmoji ( 'tick_icon' ) } I have DM'd you the invite link to the server!` ,
9393 flags : [ 'Ephemeral' ] ,
9494 } ) ;
9595 await ctx . user . send ( stripIndents `
9696 ### Join Request
9797 You requested to join the server \`${ server ?. name } \` through InterChat. Here is the invite link:
9898 ${ invite }
9999 ` ) ;
100+ return ;
100101 }
101102
102103 const webhookURL = connection ?. webhookURL ;
@@ -111,7 +112,9 @@ export default class JoinRequestCommand extends BaseCommand {
111112 components : [
112113 new ActionRowBuilder < ButtonBuilder > ( ) . addComponents (
113114 new ButtonBuilder ( )
114- . setCustomId ( new CustomID ( 'joinReq:accept' ) . setArgs ( ctx . user . id , ctx . channelId ) . toString ( ) )
115+ . setCustomId (
116+ new CustomID ( 'joinReq:accept' ) . setArgs ( ctx . user . id , ctx . channelId ) . toString ( ) ,
117+ )
115118 . setLabel ( 'Accept' )
116119 . setStyle ( ButtonStyle . Success ) ,
117120 new ButtonBuilder ( )
@@ -130,24 +133,34 @@ export default class JoinRequestCommand extends BaseCommand {
130133 /**
131134 * Resolves the target server ID from a given message or option.
132135 */
133- private async resolveTargetServerId (
134- targetMessage : Message | null ,
135- serverIdOpt : string | null ,
136- ) : Promise < string | null > {
136+ private async resolveTargetServerId ( ctx : Context ) : Promise < string | null > {
137+ const targetMessage = await ctx . getTargetMessage ( 'messageorserverid' ) ;
138+ const serverIdOpt = ctx . options . getString ( 'messageorserverid' ) ;
139+
137140 if ( targetMessage ) {
138141 const originalMessage = await findOriginalMessage ( targetMessage . id ) ;
139142 return originalMessage ?. guildId || serverIdOpt ;
140143 }
144+ const serverName = ctx . options . getString ( 'servername' ) ;
145+ if ( serverName ) {
146+ // FIXME: Use database to get server names probably
147+ const serverId = resolveEval < string > (
148+ await ctx . client . cluster . broadcastEval ( `
149+ const server = this.guilds.cache.find(g => g.name === ${ JSON . stringify ( serverName ) } );
150+ server?.id;
151+ ` ) ,
152+ ) ;
153+
154+ return serverId || serverIdOpt ;
155+ }
156+
141157 return serverIdOpt ;
142158 }
143159
144160 /**
145161 * Finds the connection for a given target server within the current hub.
146162 */
147- private async findTargetConnection (
148- channelConnection : Connection ,
149- targetServerId : string | null ,
150- ) {
163+ private async findTargetConnection ( channelConnection : Connection , targetServerId : string | null ) {
151164 if ( ! targetServerId ) return null ;
152165
153166 return await db . connection . findFirst ( {
@@ -196,11 +209,15 @@ export default class JoinRequestCommand extends BaseCommand {
196209 const user = await interaction . client . users . fetch ( userId ) . catch ( ( ) => null ) ;
197210 if ( ! user ) return ;
198211
199- const dmStatus = await user . send ( stripIndents `
212+ const dmStatus = await user
213+ . send (
214+ stripIndents `
200215 ### Join Request
201216 You requested to join the server \`${ interaction . guild ?. name } \` through InterChat. Here is the invite link:
202217 ${ inviteLink }
203- ` ) . catch ( ( ) => null ) ;
218+ ` ,
219+ )
220+ . catch ( ( ) => null ) ;
204221
205222 await interaction . editReply (
206223 dmStatus
0 commit comments