(client, guildId, channelId, options = {})
| 178 | } |
| 179 | |
| 180 | export async function initializeJoinToCreate(client, guildId, channelId, options = {}) { |
| 181 | try { |
| 182 | if (!client || !client.db) { |
| 183 | throw new TitanBotError( |
| 184 | 'Database service not available', |
| 185 | ErrorTypes.DATABASE, |
| 186 | 'System error occurred. Please try again.' |
| 187 | ); |
| 188 | } |
| 189 | |
| 190 | if (!guildId || !channelId) { |
| 191 | throw new TitanBotError( |
| 192 | 'Missing required guild or channel ID', |
| 193 | ErrorTypes.VALIDATION, |
| 194 | 'Invalid guild or channel information provided.' |
| 195 | ); |
| 196 | } |
| 197 | |
| 198 | if (options.nameTemplate) { |
| 199 | validateChannelNameTemplate(options.nameTemplate); |
| 200 | } |
| 201 | if (options.bitrate) { |
| 202 | validateBitrate(options.bitrate / 1000); |
| 203 | } |
| 204 | if (options.userLimit !== undefined) { |
| 205 | validateUserLimit(options.userLimit); |
| 206 | } |
| 207 | |
| 208 | const config = await getJoinToCreateConfig(client, guildId); |
| 209 | |
| 210 | if (config.triggerChannels.includes(channelId)) { |
| 211 | throw new TitanBotError( |
| 212 | 'Channel already configured as Join to Create trigger', |
| 213 | ErrorTypes.VALIDATION, |
| 214 | 'This channel is already set up as a Join to Create trigger.' |
| 215 | ); |
| 216 | } |
| 217 | |
| 218 | if (Array.isArray(config.triggerChannels) && config.triggerChannels.length > 0) { |
| 219 | throw new TitanBotError( |
| 220 | 'Guild already has a Join to Create trigger configured', |
| 221 | ErrorTypes.VALIDATION, |
| 222 | 'This server already has a Join to Create channel configured. Use `/jointocreate dashboard` to modify it, or remove it before creating a new one.', |
| 223 | { |
| 224 | guildId, |
| 225 | existingTriggerChannelId: config.triggerChannels[0], |
| 226 | expected: true, |
| 227 | suppressErrorLog: true |
| 228 | } |
| 229 | ); |
| 230 | } |
| 231 | |
| 232 | config.triggerChannels.push(channelId); |
| 233 | config.enabled = true; |
| 234 | |
| 235 | if (Object.keys(options).length > 0) { |
| 236 | if (!config.channelOptions) { |
| 237 | config.channelOptions = {}; |
no test coverage detected