import { SlashCommandBuilder, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, PermissionsBitField, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, ButtonBuilder, ButtonStyle, ComponentType, } from "discord.js"; import { addChannelForLinkshell } from "../../Utility/lsModel.js"; import { event } from "../../Utility/eventHandler.js"; import { client } from "../../Utility/discordClient.js"; import config from "../../config.json" assert { type: "json" }; import uuid4 from "uuid4"; import { runPrepQuery, numRows } from "../../Utility/db.js"; import servers from "../../resources/servers.json" assert { type: 'json' }; export default { data: new SlashCommandBuilder() .setName("lccreateecho") .setDescription("Connect a linkshell to a text-chat channel."), async execute(interaction) { if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { return await interaction.reply({ content: 'You must have the "Administrator" flag to use this command.', ephemeral: true, }); } const options = []; runPrepQuery('SELECT * FROM linkshells WHERE discord_owner_id = ?', [interaction.user.id], async (r,f,e) => { if (numRows(r)) { for(const row of r) { let lsName = row.name if (row.ffxiver == 1) { lsName = `${lsName} on ${servers.se[row.server]}` } else { lsName = `${lsName} on ${servers.platforms[ffxiver]}` } options.push(new StringSelectMenuOptionBuilder() .setLabel(row.name) .setDescription(lsName) .setValue(String(row.id))) } const select = new StringSelectMenuBuilder() .setCustomId('selectedLinkshell') .setPlaceholder('Select a Linkshell') .addOptions(...options); const row = new ActionRowBuilder() .addComponents(select); const response = await interaction.reply({ content: 'Please select the Linkshell you want to echo. Note: This will override any echo currently set up in this channel.', components: [row], ephemeral: true }) const collector = response.createMessageComponentCollector({ componentType: ComponentType.StringSelect, time: 60_000 }); collector.on('collect', async i => { const linkshellId = i.values[0]; let myHook = false const channel = await client.channels.fetch(i.channelId) channel.fetchWebhooks().then(async hooks => { hooks.each(hook => { if (hook.owner.id == config.clientId) { myHook = hook } }) if(!myHook) { myHook = await channel.createWebhook({ name: 'LinkCloud', avatar: 'https://i.imgur.com/AfFp7pu.png', }).catch(console.error); } if(myHook) { if(await addChannelForLinkshell(linkshellId, i.channelId, i.guildId, myHook.url)) { await i.reply({ content: '# Echo Created!\nYou should see messages as soon as stream data for this linkshell has been received.', ephemeral: true }); } else { await i.reply({ content: 'Failed to create echo.', ephemeral: true }); } } else { await i.reply({ content: 'Failed to create webhook.', ephemeral: true }); } }).catch(console.error); }); } else { await interaction.reply({ content: 'You have not added any linkshells. Please use the `/lcaddlinkshell` command to add one.', ephemeral: true }); } }) }, };