Files
euba-itckar-bot/commands/rr.js
2026-09-23 20:43:26 +02:00

741 lines
32 KiB
JavaScript

import { ApplicationCommandOptionTypes, ApplicationCommandTypes, ButtonStyles, ComponentTypes, MessageFlags, Permissions, SeparatorSpacingSize, TextInputStyles } from "oceanic.js";
export default {
data: {
type: ApplicationCommandTypes.CHAT_INPUT, // CHAT_INPUT = slash commands - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandTypes.html
name: "rr",
description: "nastav reakcne role",
options: [
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "zoznam",
description: "zobrazit zoznam kolekcii"
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "zoznam_roli",
description: "zobrazit zoznam roli v kolekcii",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia, z ktorej sa zobrazi zoznam roli",
required: true
},
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "vytvorit",
description: "vytvorit novu kolekciu",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "nazov kolekcie na vytvorenie",
required: true
},
{
type: ApplicationCommandOptionTypes.BOOLEAN, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "jedna_rola",
description: "moznost vybrat iba jednej role z kolekcie"
}
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "pridat_rolu",
description: "pridat rolu do kolekcie",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia, do ktorej bude rola pridana",
required: true
},
{
type: ApplicationCommandOptionTypes.ROLE, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "rola",
description: "rola na pridanie do kolekcie",
required: true
},
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "nazov",
description: "nazov role v kolekcii"
}
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "odobrat_rolu",
description: "odobrat rolu z kolekcie",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia, z ktorej bude rola odobrana",
required: true
},
{
type: ApplicationCommandOptionTypes.ROLE, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "rola",
description: "rola na odobranie z kolekcie",
required: true
}
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "zmazat",
description: "zmazat kolekciu",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia na zmazanie",
required: true
}
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "poslat",
description: "poslat kolekciu do kanala",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia na odoslanie",
required: true
}
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "upravit",
description: "upravit kolekciu",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia na upravenie",
required: true
},
{
type: ApplicationCommandOptionTypes.BOOLEAN, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "jedna_rola",
description: "moznost vybrat iba jednej role z kolekcie"
},
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "novy_nazov",
description: "novy nazov kolekcie"
}
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "upravit_rolu",
description: "upravit rolu v kolekcii",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia, z ktorej je rola na upravenie",
required: true
},
{
type: ApplicationCommandOptionTypes.ROLE, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "rola",
description: "rola na upravenie",
required: true
},
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "nazov",
description: "nazov role v kolekcii"
}
]
},
{
type: ApplicationCommandOptionTypes.SUB_COMMAND, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "popis",
description: "upravit popis kolekcie",
options: [
{
type: ApplicationCommandOptionTypes.STRING, // A string input - full list: https://docs.oceanic.ws/latest/enums/Constants.ApplicationCommandOptionTypes.html
name: "kolekcia",
description: "kolekcia, ktorej popis bude upraveny",
required: true
}
]
}
],
dmPermission: false, // false = usable in guilds only, true = both guild & direct message
defaultMemberPermissions: "8" // The bitfield of the default permissions required to use this command (8 = Administrator)
},
handle: async (interaction, database) => {
const db = await database.table(`rr`)
const action = interaction.data.options.getSubCommand()[0]
if (action !== `popis`) await interaction.defer(MessageFlags.EPHEMERAL);
switch (action) {
case "vytvorit": {
const kolekcia = interaction.data.options.getString("kolekcia")
const jednaRola = interaction.data.options.getString("jedna_rola")
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} uz existuje`
}
]
}
]
})
await db.set(`${interaction.guildID}.${kolekcia}`, { options: { jednaRola }, popis: null, roles: [] })
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `✅ kolekcia ${kolekcia} vytvorena`
}
]
}
]
})
break
} case "pridat_rolu": {
const kolekcia = interaction.data.options.getString("kolekcia")
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 rola = interaction.data.options.getRole("rola")
const rolaExistuje = await db.has(`${interaction.guildID}.${kolekcia}.roles`, (r) => r.id === rola.id)
const nazov = interaction.data.options.getString("nazov")
if (rolaExistuje)
return await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `❌ rola ${rola.name} uz v kolekcii ${kolekcia} existuje`
}
]
}
]
})
await db.push(`${interaction.guildID}.${kolekcia}.roles`, { id: rola.id, nazov })
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `✅ rola ${rola.name} pridana do kolekcie ${kolekcia}`
}
]
}
]
})
break
} case "odobrat_rolu": {
const kolekcia = interaction.data.options.getString("kolekcia")
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 rola = interaction.data.options.getRole("rola")
const rolaExistuje = await db.has(`${interaction.guildID}.${kolekcia}.roles`, (r) => r.id === rola.id)
if (!rolaExistuje)
return await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `❌ rola ${rola.name} v kolekcii ${kolekcia} neexistuje`
}
]
}
]
})
await db.delete(`${interaction.guildID}.${kolekcia}.roles`, (r) => r.id === rola.id)
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `✅ rola ${rola.name} odobrana z kolekcie ${kolekcia}`
}
]
}
]
})
break
} case "zmazat": {
const kolekcia = interaction.data.options.getString("kolekcia")
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`
}
]
}
]
})
await db.delete(`${interaction.guildID}.${kolekcia}`)
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `✅ kolekcia ${kolekcia} zmazana`
}
]
}
]
})
break
} case "poslat": {
const kolekcia = interaction.data.options.getString("kolekcia")
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 botPermissions = interaction.channel.permissionsOf(interaction.guild.clientMember)
if (!botPermissions.has(Permissions.SEND_MESSAGES))
return await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `❌ nemam prava na poslanie spravy`
}
]
}
]
})
const popis = await db.get(`${interaction.guildID}.${kolekcia}.popis`)
const roleDB = await db.get(`${interaction.guildID}.${kolekcia}.roles`)
const komponenty = []
komponenty.push({
type: ComponentTypes.TEXT_DISPLAY,
content: `# ${kolekcia}`
})
if (popis)
komponenty.push({
type: ComponentTypes.TEXT_DISPLAY,
content: popis
})
komponenty.push({
type: ComponentTypes.SEPARATOR,
spacing: SeparatorSpacingSize.LARGE,
divider: true
})
const komponentyRoli = []
let i = 0
for (const rolaDB of roleDB) {
const rola = interaction.guild.roles.find(r => r.id === rolaDB.id)
if (!rola) continue
if (i % 5 === 0)
komponentyRoli.push({
type: ComponentTypes.ACTION_ROW,
components: []
})
komponentyRoli[Math.floor(i / 5)].components.push(
{
type: ComponentTypes.BUTTON,
style: ButtonStyles.PRIMARY,
label: rolaDB.nazov ?? rola.name,
customID: `reakcnerole.${kolekcia}.${rolaDB.id}`
}
)
i++
}
if (!komponentyRoli.length)
komponentyRoli.push({
type: ComponentTypes.TEXT_DISPLAY,
content: `zatial ziadne role`
})
await interaction.channel.createMessage({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [...komponenty, ...komponentyRoli]
}
]
})
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `✅ sprava poslana`
}
]
}
]
})
break
} case "upravit": {
const kolekcia = interaction.data.options.getString("kolekcia")
const jednaRola = interaction.data.options.getBoolean("jedna_rola")
const novyNazov = interaction.data.options.getString("novy_nazov")
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`
}
]
}
]
})
if (jednaRola !== undefined)
await db.set(`${interaction.guildID}.${kolekcia}.options`, { jednaRola })
if (novyNazov)
await db.rename(`${interaction.guildID}.${kolekcia}`, `${interaction.guildID}.${novyNazov}`)
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `✅ kolekcia ${novyNazov ?? kolekcia} upravena`
}
]
}
]
})
break
} case "upravit_rolu": {
const kolekcia = interaction.data.options.getString("kolekcia")
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 rola = interaction.data.options.getRole("rola")
const rolaExistuje = await db.has(`${interaction.guildID}.${kolekcia}.roles`, (r) => r.id === rola.id)
const nazov = interaction.data.options.getString("nazov")
if (!rolaExistuje)
return await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `❌ rola ${rola.name} v kolekcii ${kolekcia} neexistuje`
}
]
}
]
})
if (nazov) await db.update(`${interaction.guildID}.${kolekcia}.roles`, (r => r.id === rola.id), { nazov })
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `✅ rola ${rola.name} upravena v kolekcii ${kolekcia}`
}
]
}
]
})
break
} case "popis": {
const kolekcia = interaction.data.options.getString("kolekcia")
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`
}
]
}
]
})
await interaction.createModal({
customID: `reakcnerole.${kolekcia}.popis`,
title: `${kolekcia} - upravit popis`,
components: [
{
type: ComponentTypes.LABEL,
label: `popis`,
component: {
type: ComponentTypes.TEXT_INPUT,
style: TextInputStyles.PARAGRAPH,
customID: `popis`,
required: false
}
}
]
})
break
} case "zoznam": {
const kolekcie = await db.get(`${interaction.guildID}`)
let textZoznam = `# zoznam kolekcií`
if (Object.keys(kolekcie)?.length) {
for (const kolekcia of Object.keys(kolekcie)) {
textZoznam += `\n- ${kolekcia}`
}
} else {
textZoznam += `\nziadne kolekcie`
}
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: textZoznam
}
]
}
]
})
break
} case "zoznam_roli": {
const kolekcia = interaction.data.options.getString("kolekcia")
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 role = await db.get(`${interaction.guildID}.${kolekcia}.roles`)
let textZoznam = `# zoznam rolí (${kolekcia})`
if (role?.length) {
for (const rola of role) {
textZoznam += `\n- ${rola.nazov ? `${rola.nazov} `: ``}<@&${rola.id}>`
}
} else {
textZoznam += `\nziadne role`
}
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: textZoznam
}
]
}
]
})
break
} default: {
await interaction.createFollowup({
flags: MessageFlags.IS_COMPONENTS_V2,
components: [
{
type: ComponentTypes.CONTAINER,
components: [
{
type: ComponentTypes.TEXT_DISPLAY,
content: `❌ neplatna akcia`
}
]
}
]
})
}
}
}
}