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

Function handleBitrateModal

src/commands/JoinToCreate/jointocreate.js:521–587  ·  view source on GitHub ↗
(interaction, triggerChannel, currentConfig, client)

Source from the content-addressed store, hash-verified

519}
520
521async function handleBitrateModal(interaction, triggerChannel, currentConfig, client) {
522 try {
523 const currentBitrate = ((currentConfig.channelConfig.bitrate ?? currentConfig.bitrate ?? 64000) / 1000);
524
525 const modal = new ModalBuilder()
526 .setCustomId(`jtc_bitrate_modal_${triggerChannel.id}`)
527 .setTitle('Configure Bitrate')
528 .addComponents(
529 new ActionRowBuilder().addComponents(
530 new TextInputBuilder()
531 .setCustomId('bitrate')
532 .setLabel('Enter bitrate in kbps (8-384)')
533 .setPlaceholder('Enter a number between 8 and 384')
534 .setStyle(TextInputStyle.Short)
535 .setRequired(true)
536 .setMinLength(1)
537 .setMaxLength(3)
538 .setValue(currentBitrate.toString())
539 )
540 );
541
542 await interaction.showModal(modal);
543
544 const modalSubmission = await interaction.awaitModalSubmit({
545 filter: (i) => i.customId === `jtc_bitrate_modal_${triggerChannel.id}` && i.user.id === interaction.user.id,
546 time: 60000
547 });
548
549 if (!hasManageGuildPermission(modalSubmission.member)) {
550 await modalSubmission.reply({
551 content: '❌ You need **Manage Server** permission to modify these settings.',
552 flags: MessageFlags.Ephemeral
553 });
554 return;
555 }
556
557 const userInput = modalSubmission.fields.getTextInputValue('bitrate').trim();
558
559 await updateChannelConfig(client, interaction.guild.id, triggerChannel.id, {
560 bitrate: parseInt(userInput) * 1000
561 });
562
563 await logConfigurationChange(client, interaction.guild.id, interaction.user.id, 'Updated bitrate', {
564 channelId: triggerChannel.id,
565 bitrate: parseInt(userInput)
566 });
567
568 await modalSubmission.reply({
569 embeds: [successEmbed('Updated', `Bitrate changed to ${parseInt(userInput)} kbps`)],
570 flags: MessageFlags.Ephemeral
571 });
572
573 } catch (error) {
574 if (error.code === 'INTERACTION_COLLECTOR_ERROR') {
575 return;
576 }
577 if (error instanceof TitanBotError) {
578 throw error;

Callers 1

handleConfigSubcommandFunction · 0.85

Calls 4

hasManageGuildPermissionFunction · 0.90
updateChannelConfigFunction · 0.90
logConfigurationChangeFunction · 0.90
successEmbedFunction · 0.90

Tested by

no test coverage detected