(client, guildId, updates)
| 266 | } |
| 267 | |
| 268 | static async updateSettings(client, guildId, updates) { |
| 269 | try { |
| 270 | |
| 271 | if (updates.logChannelId && typeof updates.logChannelId !== 'string') { |
| 272 | throw createError( |
| 273 | 'Invalid log channel ID', |
| 274 | ErrorTypes.VALIDATION, |
| 275 | 'Invalid channel ID provided.', |
| 276 | { logChannelId: updates.logChannelId } |
| 277 | ); |
| 278 | } |
| 279 | |
| 280 | if (updates.managerRoles && !Array.isArray(updates.managerRoles)) { |
| 281 | throw createError( |
| 282 | 'Invalid manager roles format', |
| 283 | ErrorTypes.VALIDATION, |
| 284 | 'Manager roles must be an array.', |
| 285 | { managerRoles: updates.managerRoles } |
| 286 | ); |
| 287 | } |
| 288 | |
| 289 | if (updates.questions) { |
| 290 | if (!Array.isArray(updates.questions) || updates.questions.length === 0) { |
| 291 | throw createError( |
| 292 | 'Invalid questions format', |
| 293 | ErrorTypes.VALIDATION, |
| 294 | 'Questions must be a non-empty array.', |
| 295 | { questions: updates.questions } |
| 296 | ); |
| 297 | } |
| 298 | |
| 299 | updates.questions = updates.questions.map(q => |
| 300 | typeof q === 'string' ? q.trim().substring(0, 100) : q |
| 301 | ); |
| 302 | } |
| 303 | |
| 304 | await saveApplicationSettings(client, guildId, updates); |
| 305 | const updatedSettings = await getApplicationSettings(client, guildId); |
| 306 | |
| 307 | logger.info('Application settings updated', { |
| 308 | guildId, |
| 309 | updates: Object.keys(updates) |
| 310 | }); |
| 311 | |
| 312 | return updatedSettings; |
| 313 | } catch (error) { |
| 314 | logger.error('Error updating application settings', { |
| 315 | error: error.message, |
| 316 | guildId, |
| 317 | updates, |
| 318 | stack: error.stack |
| 319 | }); |
| 320 | throw error; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | static async manageApplicationRoles(client, guildId, data) { |
| 325 | try { |
no test coverage detected