import { ApplicationCommandOptionTypes, ApplicationCommandTypes, ButtonStyles, ComponentTypes, MessageFlags, Permissions, SeparatorSpacingSize } from "oceanic.js"; export default { data: { name: "reakcnerole", }, handle: async (interaction, database) => { await interaction.defer(MessageFlags.EPHEMERAL) const db = await database.table(`rr`) const splitID = interaction.data.customID.split('.') const kolekcia = splitID[1] const rolaID = splitID[2] const exists = await db.has(`${interaction.guildID}.${kolekcia}`) if (!exists) return await interaction.createFollowup({ flags: MessageFlags.IS_COMPONENTS_V2, components: [ { type: ComponentTypes.CONTAINER, components: [ { type: ComponentTypes.TEXT_DISPLAY, content: `❌ kolekcia ${kolekcia} neexistuje` } ] } ] }) const rolaExistuje = await db.has(`${interaction.guildID}.${kolekcia}.roles`, (r) => r.id === rolaID) if (!rolaExistuje) return await interaction.createFollowup({ flags: MessageFlags.IS_COMPONENTS_V2, components: [ { type: ComponentTypes.CONTAINER, components: [ { type: ComponentTypes.TEXT_DISPLAY, content: `❌ rola v kolekcii ${kolekcia} neexistuje` } ] } ] }) const rolaDB = await db.get(`${interaction.guildID}.${kolekcia}.roles`, (r) => r.id === rolaID) const rola = interaction.guild.roles.find(r => r.id === rolaID) if (!rola) return await interaction.createFollowup({ flags: MessageFlags.IS_COMPONENTS_V2, components: [ { type: ComponentTypes.CONTAINER, components: [ { type: ComponentTypes.TEXT_DISPLAY, content: `❌ rola neexistuje` } ] } ] }) const botPermissions = interaction.guild.clientMember.permissions if (!botPermissions.has(Permissions.MANAGE_ROLES)) return await interaction.createFollowup({ flags: MessageFlags.IS_COMPONENTS_V2, components: [ { type: ComponentTypes.CONTAINER, components: [ { type: ComponentTypes.TEXT_DISPLAY, content: `❌ nemam prava na zmenu roli` } ] } ] }) const memberMaRolu = interaction.member.roles.includes(rolaID) if (memberMaRolu) { await interaction.member.removeRole(rolaID, `reakcne role`) return await interaction.createFollowup({ flags: MessageFlags.IS_COMPONENTS_V2, components: [ { type: ComponentTypes.CONTAINER, components: [ { type: ComponentTypes.TEXT_DISPLAY, content: `✅ rola ${rola.name} ti bola odobrana` } ] } ] }) } const jednaRola = await db.get(`${interaction.guildID}.${kolekcia}.options.jednaRola`) const roly = interaction.member.roles const rolyDB = new Set((await db.get(`${interaction.guildID}.${kolekcia}.roles`)).map(i => i.id)) const memberMaRoluZKolekcie = roly.some(i => rolyDB.has(i)) if (jednaRola && memberMaRoluZKolekcie) return await interaction.createFollowup({ flags: MessageFlags.IS_COMPONENTS_V2, components: [ { type: ComponentTypes.CONTAINER, components: [ { type: ComponentTypes.TEXT_DISPLAY, content: `❌ uz mas nejaku rolu z kolekcie` } ] } ] }) await interaction.member.addRole(rolaID, `reakcne role`) await interaction.createFollowup({ flags: MessageFlags.IS_COMPONENTS_V2, components: [ { type: ComponentTypes.CONTAINER, components: [ { type: ComponentTypes.TEXT_DISPLAY, content: `✅ rola ${rola.name} ti bola pridana` } ] } ] }) } }