(client, guildId, channelId)
| 331 | } |
| 332 | |
| 333 | export async function removeTriggerChannel(client, guildId, channelId) { |
| 334 | try { |
| 335 | if (!client || !client.db) { |
| 336 | throw new TitanBotError( |
| 337 | 'Database service not available', |
| 338 | ErrorTypes.DATABASE, |
| 339 | 'Database service is currently unavailable. Please try again later.' |
| 340 | ); |
| 341 | } |
| 342 | |
| 343 | const config = await getJoinToCreateConfig(client, guildId); |
| 344 | |
| 345 | const index = config.triggerChannels.indexOf(channelId); |
| 346 | if (index === -1) { |
| 347 | throw new TitanBotError( |
| 348 | 'Channel not found in Join to Create triggers', |
| 349 | ErrorTypes.VALIDATION, |
| 350 | 'This channel is not configured as a Join to Create trigger.' |
| 351 | ); |
| 352 | } |
| 353 | |
| 354 | config.triggerChannels.splice(index, 1); |
| 355 | config.enabled = config.triggerChannels.length > 0; |
| 356 | |
| 357 | if (config.channelOptions && config.channelOptions[channelId]) { |
| 358 | delete config.channelOptions[channelId]; |
| 359 | } |
| 360 | |
| 361 | if (config.temporaryChannels) { |
| 362 | for (const [tempChannelId, tempInfo] of Object.entries(config.temporaryChannels)) { |
| 363 | if (tempInfo.triggerChannelId === channelId) { |
| 364 | delete config.temporaryChannels[tempChannelId]; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | await saveJoinToCreateConfig(client, guildId, config); |
| 370 | |
| 371 | logger.info(`Removed Join to Create trigger channel ${channelId} from guild ${guildId}`); |
| 372 | |
| 373 | return true; |
| 374 | |
| 375 | } catch (error) { |
| 376 | if (error instanceof TitanBotError) { |
| 377 | throw error; |
| 378 | } |
| 379 | throw new TitanBotError( |
| 380 | `Failed to remove trigger channel: ${error.message}`, |
| 381 | ErrorTypes.DATABASE, |
| 382 | 'Failed to remove trigger channel.' |
| 383 | ); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | export async function getConfiguration(client, guildId) { |
| 388 | try { |
no test coverage detected