11import {
22 ButtonBuilder ,
3+ type ButtonInteraction ,
34 ButtonStyle ,
45 ChannelType ,
6+ type ChatInputCommandInteraction ,
7+ Colors ,
58 ContainerBuilder ,
9+ EmbedBuilder ,
610 MessageFlags ,
711 TextDisplayBuilder ,
812} from 'discord.js' ;
913import { createSlashCommand } from '@/common/commands/create-commands.js' ;
10- import { registerButtonSubmitInteraction } from '@/common/interactions/button-interaction.js' ;
14+ import {
15+ type ButtonSubmitInteraction ,
16+ registerButtonSubmitInteraction ,
17+ } from '@/common/interactions/button-interaction.js' ;
1118import {
1219 type ModalSubmitInteraction ,
1320 registerModalSubmitInteraction ,
1421} from '@/common/interactions/modal-interaction.js' ;
1522import { config } from '@/env.js' ;
23+ import { logToChannel } from '@/util/channel-logging.js' ;
1624import { customId } from '@/util/custom-id.js' ;
1725import { deleteShowcase } from './delete-showcase.js' ;
1826import { editShowcaseInteraction } from './edit-showcase.js' ;
19- import { buildShowcaseModal } from './util.js' ;
27+ import { buildShowcaseModal , getShowcaseLogChannel } from './util.js' ;
2028
21- export const createShowcaseCommand = createSlashCommand ( {
22- data : {
23- name : 'showcase' ,
24- description : 'Showcase a project in the showcase channel' ,
25- } ,
26- execute : async ( interaction ) => {
29+ export const showModal = async ( interaction : ButtonInteraction | ChatInputCommandInteraction ) => {
30+ try {
2731 const channel = interaction . guild ?. channels . cache . get ( config . channelIds . showcase ) ;
2832 if ( channel === undefined || channel . type !== ChannelType . GuildForum ) {
2933 await interaction . reply ( {
@@ -40,9 +44,30 @@ export const createShowcaseCommand = createSlashCommand({
4044 } ) ;
4145
4246 await interaction . showModal ( modal ) ;
47+ } catch ( error ) {
48+ console . error ( 'Error showing showcase modal:' , error ) ;
49+ await interaction . reply ( {
50+ content : 'There was an error showing the showcase modal. Please try again later.' ,
51+ flags : MessageFlags . Ephemeral ,
52+ } ) ;
53+ }
54+ } ;
55+
56+ export const createShowcaseCommand = createSlashCommand ( {
57+ data : {
58+ name : 'showcase' ,
59+ description : 'Showcase a project in the showcase channel' ,
4360 } ,
61+ execute : showModal ,
4462} ) ;
4563
64+ const createShowcaseButtonHandler : ButtonSubmitInteraction = {
65+ commandName : 'create_showcase' ,
66+ handler : showModal ,
67+ } ;
68+
69+ registerButtonSubmitInteraction ( createShowcaseButtonHandler ) ;
70+
4671const modalHandler : ModalSubmitInteraction = {
4772 commandName : 'showcase' ,
4873 handler : async ( interaction ) => {
@@ -104,6 +129,34 @@ const modalHandler: ModalSubmitInteraction = {
104129 ) ,
105130 ] ,
106131 } ) ;
132+
133+ try {
134+ const logChannel = getShowcaseLogChannel ( interaction . guild ) ;
135+ const author = {
136+ name : interaction . user . tag ,
137+ iconURL : interaction . user . displayAvatarURL ( ) ,
138+ } ;
139+
140+ const embed = new EmbedBuilder ( )
141+ . setAuthor ( author )
142+ . setTitle ( 'Showcase Created' )
143+ . addFields (
144+ { name : 'Project Name' , value : projectName || '—' , inline : false } ,
145+ { name : 'Author' , value : `<@${ interaction . user . id } >` , inline : true } ,
146+ { name : 'Thread' , value : thread . url ?? '—' , inline : true }
147+ )
148+ . setColor ( Colors . Green )
149+ . setTimestamp ( ) ;
150+
151+ await logToChannel ( {
152+ channel : logChannel ,
153+ content : { type : 'embed' , embed } ,
154+ silent : true ,
155+ } ) ;
156+ } catch ( error ) {
157+ console . error ( 'Failed to log showcase creation:' , error ) ;
158+ }
159+
107160 await interaction . editReply ( {
108161 content : `Your project has been showcased successfully! You can view it here: ${ thread . url } ` ,
109162 } ) ;
0 commit comments