(interaction, client)
| 117 | }; |
| 118 | |
| 119 | async function handleSetupSubcommand(interaction, client) { |
| 120 | try { |
| 121 | const category = interaction.options.getChannel('category'); |
| 122 | const nameTemplate = interaction.options.getString('channel_name') || "{username}'s Room"; |
| 123 | const userLimit = interaction.options.getInteger('user_limit') || 0; |
| 124 | const bitrate = interaction.options.getInteger('bitrate') || 64; |
| 125 | const guildId = interaction.guild.id; |
| 126 | |
| 127 | logger.debug(`Setting up Join to Create in guild ${guildId} with template: ${nameTemplate}`); |
| 128 | |
| 129 | const existingConfig = await getConfiguration(client, guildId); |
| 130 | |
| 131 | if (Array.isArray(existingConfig.triggerChannels) && existingConfig.triggerChannels.length > 0) { |
| 132 | const activeTriggerChannels = []; |
| 133 | const staleTriggerChannelIds = []; |
| 134 | |
| 135 | for (const existingChannelId of existingConfig.triggerChannels) { |
| 136 | const existingChannel = await interaction.guild.channels.fetch(existingChannelId).catch(() => null); |
| 137 | if (existingChannel) { |
| 138 | activeTriggerChannels.push(existingChannel); |
| 139 | } else { |
| 140 | staleTriggerChannelIds.push(existingChannelId); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (staleTriggerChannelIds.length > 0) { |
| 145 | for (const staleChannelId of staleTriggerChannelIds) { |
| 146 | logger.info(`Cleaning up stale JTC trigger ${staleChannelId} from guild ${guildId}`); |
| 147 | await removeTriggerChannel(client, guildId, staleChannelId); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if (activeTriggerChannels.length > 0) { |
| 152 | const primaryTrigger = activeTriggerChannels[0]; |
| 153 | const errorMessage = `This server already has a Join to Create channel set up: ${primaryTrigger}\n\nUse \`/jointocreate dashboard\` to modify it, or remove it first before creating a new one.`; |
| 154 | |
| 155 | throw new TitanBotError( |
| 156 | 'Guild already has a Join to Create channel', |
| 157 | ErrorTypes.VALIDATION, |
| 158 | errorMessage, |
| 159 | { |
| 160 | guildId, |
| 161 | activeTriggerCount: activeTriggerChannels.length, |
| 162 | expected: true, |
| 163 | suppressErrorLog: true |
| 164 | } |
| 165 | ); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | logger.debug('Creating Join to Create trigger channel...'); |
| 170 | let triggerChannel = await interaction.guild.channels.create({ |
| 171 | name: 'Join to Create', |
| 172 | type: ChannelType.GuildVoice, |
| 173 | parent: category?.id, |
| 174 | userLimit: 0, |
| 175 | bitrate: 64000, |
| 176 | permissionOverwrites: [ |
no test coverage detected