MCPcopy
hub / github.com/codebymitch/TitanBot / updateChannelConfig

Function updateChannelConfig

src/services/joinToCreateService.js:273–331  ·  view source on GitHub ↗
(client, guildId, channelId, updates)

Source from the content-addressed store, hash-verified

271}
272
273export async function updateChannelConfig(client, guildId, channelId, updates) {
274 try {
275 if (!client || !client.db) {
276 throw new TitanBotError(
277 'Database service not available',
278 ErrorTypes.DATABASE,
279 'Database service is currently unavailable. Please try again later.'
280 );
281 }
282
283 const config = await getJoinToCreateConfig(client, guildId);
284
285 if (!config.triggerChannels.includes(channelId)) {
286 throw new TitanBotError(
287 'Channel is not configured as a Join to Create trigger',
288 ErrorTypes.VALIDATION,
289 'This channel is not set up as a Join to Create trigger.'
290 );
291 }
292
293 if (updates.nameTemplate) {
294 validateChannelNameTemplate(updates.nameTemplate);
295 }
296 if (updates.bitrate !== undefined) {
297 validateBitrate(updates.bitrate / 1000);
298 }
299 if (updates.userLimit !== undefined) {
300 validateUserLimit(updates.userLimit);
301 }
302
303 if (!config.channelOptions) {
304 config.channelOptions = {};
305 }
306
307 config.channelOptions[channelId] = {
308 ...config.channelOptions[channelId],
309 ...updates,
310 updatedAt: Date.now()
311 };
312
313 await saveJoinToCreateConfig(client, guildId, config);
314
315 logger.info(`Updated Join to Create config for channel ${channelId} in guild ${guildId}`, {
316 updates: Object.keys(updates)
317 });
318
319 return config.channelOptions[channelId];
320
321 } catch (error) {
322 if (error instanceof TitanBotError) {
323 throw error;
324 }
325 throw new TitanBotError(
326 `Failed to update channel config: ${error.message}`,
327 ErrorTypes.DATABASE,
328 'Failed to update configuration.'
329 );
330 }

Callers 3

handleNameTemplateModalFunction · 0.90
handleUserLimitModalFunction · 0.90
handleBitrateModalFunction · 0.90

Calls 5

getJoinToCreateConfigFunction · 0.90
saveJoinToCreateConfigFunction · 0.90
validateBitrateFunction · 0.85
validateUserLimitFunction · 0.85

Tested by

no test coverage detected