@@ -34,9 +34,13 @@ import {
3434 getApplications ,
3535 deleteApplication ,
3636} from '../../../utils/database.js' ;
37+ import { getGuildConfig } from '../../../services/guildConfig.js' ;
38+ import { setLogChannel , resolveApplicationLogChannel , resolveLogChannel } from '../../../services/loggingService.js' ;
3739
38- function buildDashboardEmbed ( settings , roles , guild ) {
39- const logChannel = settings . logChannelId ? `<#${ settings . logChannelId } >` : '`Not set`' ;
40+ async function buildDashboardEmbed ( settings , roles , guild , client ) {
41+ const guildConfig = await getGuildConfig ( client , guild . id ) ;
42+ const applicationsChannel = resolveLogChannel ( guildConfig , 'applications' ) || settings . logChannelId ;
43+ const logChannel = applicationsChannel ? `<#${ applicationsChannel } >` : '`Not set`' ;
4044 const managerRoleList =
4145 settings . managerRoles ?. length > 0
4246 ? settings . managerRoles . map ( id => `<@&${ id } >` ) . join ( ',' )
@@ -121,10 +125,10 @@ function buildButtonRow(settings, guildId, disabled = false) {
121125 ) ;
122126}
123127
124- async function refreshDashboard ( rootInteraction , settings , roles , guildId ) {
128+ async function refreshDashboard ( rootInteraction , settings , roles , guildId , client ) {
125129 const selectMenu = buildSelectMenu ( guildId ) ;
126130 await InteractionHelper . safeEditReply ( rootInteraction , {
127- embeds : [ buildDashboardEmbed ( settings , roles , rootInteraction . guild ) ] ,
131+ embeds : [ await buildDashboardEmbed ( settings , roles , rootInteraction . guild , client ) ] ,
128132 components : [
129133 buildButtonRow ( settings , guildId ) ,
130134 new ActionRowBuilder ( ) . addComponents ( selectMenu ) ,
@@ -145,8 +149,11 @@ export default {
145149 getApplicationRoles ( client , guildId ) ,
146150 ] ) ;
147151
152+ const guildConfig = await getGuildConfig ( client , guildId ) ;
153+ const applicationsChannel = resolveLogChannel ( guildConfig , 'applications' ) || settings . logChannelId ;
154+
148155 const isCompletelyUnconfigured =
149- ! settings . logChannelId &&
156+ ! applicationsChannel &&
150157 ! settings . enabled &&
151158 ( settings . managerRoles ?. length ?? 0 ) === 0 &&
152159 roles . length === 0 ;
@@ -246,7 +253,7 @@ async function showGlobalDashboard(interaction, settings, roles, guildId, client
246253 const selectMenu = buildSelectMenu ( guildId ) ;
247254
248255 await InteractionHelper . safeEditReply ( interaction , {
249- embeds : [ buildDashboardEmbed ( settings , roles , interaction . guild ) ] ,
256+ embeds : [ await buildDashboardEmbed ( settings , roles , interaction . guild , client ) ] ,
250257 components : [
251258 buildButtonRow ( settings , guildId ) ,
252259 new ActionRowBuilder ( ) . addComponents ( selectMenu ) ,
@@ -259,9 +266,10 @@ async function showGlobalDashboard(interaction, settings, roles, guildId, client
259266async function showApplicationDashboard ( rootInteraction , selectedRole , settings , roles , guildId , client ) {
260267 const roleObj = rootInteraction . guild . roles . cache . get ( selectedRole . roleId ) ;
261268
269+ const guildConfig = await getGuildConfig ( client , guildId ) ;
262270 const appSettings = await getApplicationRoleSettings ( client , guildId , selectedRole . roleId ) ;
263271 const questions = appSettings . questions || settings . questions || [ ] ;
264- const appLogChannelId = appSettings . logChannelId || settings . logChannelId ;
272+ const appLogChannelId = resolveApplicationLogChannel ( guildConfig , appSettings , settings ) ;
265273 const isEnabled = selectedRole . enabled !== false ;
266274
267275 const logChannelDisplay = appLogChannelId
@@ -712,16 +720,17 @@ async function handleLogChannel(selectInteraction, rootInteraction, settings, ro
712720 roleSettings . logChannelId = channelId ;
713721 await saveApplicationRoleSettings ( client , guildId , selectedRoleId , roleSettings ) ;
714722 } else {
723+ await setLogChannel ( client , guildId , 'applications' , channelId ) ;
715724 settings . logChannelId = channelId ;
716725 await saveApplicationSettings ( client , guildId , settings ) ;
717726 }
718727
719728 await modalSubmission . reply ( {
720- embeds : [ successEmbed ( 'Log Channel Updated' , `Application logs will now be sent to ${ channel ?? `<#${ channelId } >` } .` ) ] ,
729+ embeds : [ successEmbed ( 'Log Channel Updated' , `Application logs will now be sent to ${ channel ?? `<#${ channelId } >` } .\nYou can also manage this from \`/logging dashboard\` .` ) ] ,
721730 flags : MessageFlags . Ephemeral ,
722731 } ) ;
723732
724- await refreshDashboard ( rootInteraction , settings , roles , guildId ) ;
733+ await refreshDashboard ( rootInteraction , settings , roles , guildId , client ) ;
725734 } catch ( error ) {
726735 if ( error . code === 'INTERACTION_TIMEOUT' ) return ;
727736 logger . error ( 'Error in log channel modal:' , error ) ;
@@ -782,7 +791,7 @@ async function handleManagerRole(selectInteraction, rootInteraction, settings, r
782791 flags : MessageFlags . Ephemeral ,
783792 } ) ;
784793
785- await refreshDashboard ( rootInteraction , settings , roles , guildId ) ;
794+ await refreshDashboard ( rootInteraction , settings , roles , guildId , client ) ;
786795 } catch ( error ) {
787796 if ( error . code === 'INTERACTION_TIMEOUT' ) return ;
788797 logger . error ( 'Error in manager role modal:' , error ) ;
@@ -898,7 +907,7 @@ async function handleQuestions(selectInteraction, rootInteraction, settings, rol
898907 flags : MessageFlags . Ephemeral ,
899908 } ) ;
900909
901- await refreshDashboard ( rootInteraction , settings , roles , guildId ) ;
910+ await refreshDashboard ( rootInteraction , settings , roles , guildId , client ) ;
902911}
903912
904913async function handleRoleAdd ( selectInteraction , rootInteraction , settings , roles , guildId , client ) {
@@ -956,7 +965,7 @@ async function handleRoleAdd(selectInteraction, rootInteraction, settings, roles
956965 flags : MessageFlags . Ephemeral ,
957966 } ) ;
958967
959- await refreshDashboard ( rootInteraction , settings , roles , guildId ) ;
968+ await refreshDashboard ( rootInteraction , settings , roles , guildId , client ) ;
960969 } catch ( error ) {
961970 if ( error . code === 'INTERACTION_TIMEOUT' ) return ;
962971 logger . error ( 'Error in role add modal:' , error ) ;
@@ -1021,7 +1030,7 @@ async function handleRoleRemove(selectInteraction, rootInteraction, settings, ro
10211030 flags : MessageFlags . Ephemeral ,
10221031 } ) ;
10231032
1024- await refreshDashboard ( rootInteraction , settings , roles , guildId ) ;
1033+ await refreshDashboard ( rootInteraction , settings , roles , guildId , client ) ;
10251034 } catch ( error ) {
10261035 if ( error . code === 'INTERACTION_TIMEOUT' ) return ;
10271036 logger . error ( 'Error in role remove modal:' , error ) ;
@@ -1117,7 +1126,7 @@ async function handleRetention(selectInteraction, rootInteraction, settings, rol
11171126 flags : MessageFlags . Ephemeral ,
11181127 } ) ;
11191128
1120- await refreshDashboard ( rootInteraction , settings , roles , guildId ) ;
1129+ await refreshDashboard ( rootInteraction , settings , roles , guildId , client ) ;
11211130}
11221131
11231132async function handleDeleteApplication ( confirmSubmit , selectedRoleId , guildId , roles , client ) {
0 commit comments