import { SlashCommandBuilder, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, PermissionsBitField, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, ButtonBuilder, ButtonStyle, ComponentType, } from "discord.js"; import { getLSFromGuildId, getLSModel, updateLSModel, createNewLS } 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"; const servers = config.servers; const options = []; for (const idx in servers) { options.push({ name: servers[idx], value: idx }); } export default { data: new SlashCommandBuilder() .setName("lcaddlinkshell") .setDescription("Add your linkshell to the Link Cloud service.") /*.addStringOption((option) => option .setName("linkshellname") .setDescription("The name of your linkshell, exactly as it appears in game.") .setRequired(true) )*/ .addStringOption((option) => option .setName("provider") .setDescription("FFXI Server Type") .setRequired(true) .addChoices(...options) ), 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 version = interaction.options.getString("provider"); const confirm = new ButtonBuilder().setCustomId("confirm").setLabel("Yes").setStyle(ButtonStyle.Success); const cancel = new ButtonBuilder().setCustomId("cancel").setLabel("No").setStyle(ButtonStyle.Danger); const response = version > 0 ? await interaction.reply({ content: `Have you set up your LinkCloud addon for FFXI using the \`/lcjoin\` command?`, components: [new ActionRowBuilder().addComponents(cancel, confirm)], ephemeral: true, }) : await interaction.reply({ content: `LinkCloud is not currently supported by this server. Please visit our discord for more info, or to get this server added to the list.`, ephemeral: true, }) const collectorFilter = (i) => i.user.id === interaction.user.id; try { const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 }); if (confirmation.customId === "confirm") { let sqlCreationId = false const sqlResult = await runPrepQuery("SELECT * FROM `pendinglinks` WHERE `userId` = ? LIMIT 0,1", [interaction.user.id], async (r,f,e) => { if(numRows(r)) { sqlCreationId = r[0].linkId } const creationId = sqlCreationId ? sqlCreationId : uuid4(); if(!sqlCreationId) { await runPrepQuery("INSERT INTO `pendinglinks` (`linkId`, `userId`, `ffxiver`) VALUES(?,?, ?)", [creationId, interaction.user.id, version], async(r,f,e) => { if(e) { return confirmation.update({ content: `Something Failed. Try again later.`, components: [], }); } }) } await confirmation.update({ content: `# LinkCloud Linkshell Setup\nPlease follow the steps below.\n\n- Equip the Linkshell you wish to equip in the Linkshell #1 slot.\n- UnEquip any Linkshell equipped in the Linkshell #2 slot.\n- Run the command below in game.\n\n\`\`\`//lc addlinkshell ${creationId}\`\`\`\n\nYou will receive a direct message in discord once the process has completed.`, components: [], }); }) } else if (confirmation.customId === "cancel") { await confirmation.update({ content: "Please run the `/lcjoin` command first, then run this command again.", components: [], }); } } catch (e) { console.log(e) await interaction.editReply({ content: "Confirmation not received within 1 minute, cancelling", components: [], ephemeral: true, }); } /*const response = await interaction.reply({ content: `**Please run the command below in game.**\n\n\`\`\`//lc addlinkshell ${creationId}\`\`\``, ephemeral: true, });*/ /*const lsName = interaction.options.getString("linkshellname"); const version = interaction.options.getString("ffxiversion"); let serverName = ""; if (Number(serverId) < 1000) { serverName = servers.retail[serverId]; } else { serverName = servers.community[serverId]; } console.log(serverId, lsName); const confirm = new ButtonBuilder() .setCustomId("confirm") .setLabel("Connect") .setStyle(ButtonStyle.Success); const cancel = new ButtonBuilder().setCustomId("cancel").setLabel("Cancel").setStyle(ButtonStyle.Danger); const response = await interaction.reply({ content: `**Confirm the information below to finish**\n\n**Linkshell Name** \`${lsName}\`\n**FFXI Server** \`${serverName}\``, components: [new ActionRowBuilder().addComponents(cancel, confirm)], ephemeral: true, }); const collectorFilter = (i) => i.user.id === interaction.user.id; try { const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 }); if (confirmation.customId === "confirm") { await confirmation.update({ content: `Linkshell ${lsName} on ${serverName} has been added to LinkCloud.`, components: [], ephemeral: true, }); } else if (confirmation.customId === "cancel") { await confirmation.update({ content: "Action cancelled", components: [] }); } } catch (e) { await interaction.editReply({ content: "Confirmation not received within 1 minute, cancelling", components: [], ephemeral: true, }); } */ }, }; event.on("on_serverId", async (interaction) => {}); /* console.log(lsName) try { let lsModel = getLSModel(lsName.trim().replace(String.fromCharCode(10), '').replace(String.fromCharCode(13), '')) const channel = await client.channels.fetch(interaction.channelId) console.log(lsModel) if (lsModel) { await interaction.reply({ content: 'Your linkshell already exists.', ephemeral: true }); } else { let myHook = false 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) { createNewLS(interaction.guildId, interaction.channelId, lsName, interaction.user.id, myHook.url) await interaction.reply({ content: 'Your linkshell was successfully connected!', ephemeral: true }); } else { await interaction.reply({ content: 'Failed to create webhook.', ephemeral: true }); } }).catch(console.error); } } catch (e) { console.log(e) await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); }*/