diff --git a/commands/fun/animal.ts b/commands/fun/animal.ts new file mode 100644 index 0000000..d2b1c39 --- /dev/null +++ b/commands/fun/animal.ts @@ -0,0 +1,99 @@ +import { commandModule, CommandType } from '@sern/handler' +import axios from "axios"; +import { ActionRowBuilder, ApplicationCommandOptionType, ButtonBuilder, ButtonStyle, ComponentType, EmbedBuilder } from "discord.js"; +import { publish } from "../../src/plugins/publish.js"; +/* +import { publish } from "../../src/plugins/publish.js"; +import { ownerOnly } from "../../src/plugins/ownerOnly.js" +*/ + +export default commandModule({ + name: 'animal', + type: CommandType.Slash, + plugins: [publish({ guildIds: ['1000400148289036298', '928018226330337280'] })], + description: 'Enseña un animal', + //alias : [], + options: [ + { + name: 'gato', + description: 'Enseña un gato', + type: ApplicationCommandOptionType.Subcommand + }, + { + name: 'capybara', + description: 'Enseña un capybara', + type: ApplicationCommandOptionType.Subcommand + }, + ], + execute: async (ctx, options) => { + switch (options[1].getSubcommand()) { + case 'gato': { + const request = await axios.get(`https://api.thecatapi.com/v1/images/search?api_key=${process.env.CATAPI}`).then(res => res.data) + const embed = new EmbedBuilder() + .setAuthor({name: ctx.user.username, iconURL: ctx.user.displayAvatarURL()}) + .setColor("Random") + .setImage(request[0].url) + .setFooter({text: `ID: ${request[0].id}`}) + .setTitle('Gato') + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId("cat-upvote") + .setEmoji("⬆️") + .setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId("cat-downvote") + .setEmoji("⬇️") + .setStyle(ButtonStyle.Danger), + ) + const rowdisabled = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId("cat-upvote") + .setEmoji("⬆️") + .setStyle(ButtonStyle.Success) + .setDisabled(true), + new ButtonBuilder() + .setCustomId("cat-downvote") + .setEmoji("⬇️") + .setStyle(ButtonStyle.Danger) + .setDisabled(true), + ) + const message = await ctx.reply({embeds: [embed], components: [row]}) + const collector = message.createMessageComponentCollector({time: 30000, componentType: ComponentType.Button}) + collector.on('collect', async (i) => { + await i.deferReply({ephemeral: true}) + if (i.customId === "cat-upvote") { + await axios.post(`https://api.thecatapi.com/v1/votes?api_key=${process.env.CATAPI}`, { + "image_id": request[0].id, + "sub_id": i.user.id, + "value": 1 + }) + i.editReply({content: "Has votado positivamente al gato con ID " + "`" + request[0].id + "`"}) + } + if (i.customId === "cat-downvote") { + await axios.post(`https://api.thecatapi.com/v1/votes?api_key=${process.env.CATAPI}`, { + "image_id": request[0].id, + "sub_id": i.user.id, + "value": -1 + }) + i.editReply({content: "Has votado negativamente al gato con ID " + "`" + request[0].id + "`"}) + } + }) + collector.on('end', async (i) => { + await message.edit({components: [rowdisabled]}) + }) + } + case 'capybara': { + const request = await axios('https://api.capybara-api.xyz/v1/image/random').then(res => res.data) + const embed = new EmbedBuilder() + .setAuthor({name: ctx.user.username, iconURL: ctx.user.displayAvatarURL()}) + .setTitle('Capybara') + .setColor('Random') + .setImage(request.image_urls.medium) + .setFooter({text: `ID: ${request.id}`}) + await ctx.interaction.reply({embeds: [embed], ephemeral: true}) + } + } + }, +}); \ No newline at end of file diff --git a/commands/fun/cat.ts b/commands/fun/cat.ts deleted file mode 100644 index 9529a7e..0000000 --- a/commands/fun/cat.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { commandModule, CommandType } from '@sern/handler' -import { Context } from "@sern/handler"; -import axios from "axios"; -import { ActionRowBuilder, APIMessageActionRowComponent, ButtonBuilder, ButtonStyle, ComponentType, EmbedBuilder } from "discord.js"; -import { publish } from "../../src/plugins/publish.js"; -/* -import { publish } from "../../src/plugins/publish.js"; -import { ownerOnly } from "../../src/plugins/ownerOnly.js" -*/ - -export default commandModule({ - name: 'gato', - type: CommandType.Slash, - plugins: [publish({ guildIds: ['1000400148289036298', '928018226330337280'] })], - description: 'QUIEN HA DICHO GATOS?!?!?!', - //alias : [], - options: [], - execute: async (ctx: Context, options) => { - const request = await axios.get(`https://api.thecatapi.com/v1/images/search?api_key=${process.env.CATAPI}`).then(res => res.data) - const embed = new EmbedBuilder() - .setAuthor({name: ctx.user.username, iconURL: ctx.user.displayAvatarURL()}) - .setColor("Random") - .setImage(request[0].url) - .setFooter({text: `ID: ${request[0].id}`}) - .setTitle('Gato') - const row = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setCustomId("cat-upvote") - .setEmoji("⬆️") - .setStyle(ButtonStyle.Success), - new ButtonBuilder() - .setCustomId("cat-downvote") - .setEmoji("⬇️") - .setStyle(ButtonStyle.Danger), - ) - const rowdisabled = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setCustomId("cat-upvote") - .setEmoji("⬆️") - .setStyle(ButtonStyle.Success) - .setDisabled(true), - new ButtonBuilder() - .setCustomId("cat-downvote") - .setEmoji("⬇️") - .setStyle(ButtonStyle.Danger) - .setDisabled(true), - ) - const message = await ctx.reply({embeds: [embed], components: [row]}) - const collector = message.createMessageComponentCollector({time: 30000, componentType: ComponentType.Button}) - collector.on('collect', async (i) => { - await i.deferReply({ephemeral: true}) - if (i.customId === "cat-upvote") { - await axios.post(`https://api.thecatapi.com/v1/votes?api_key=${process.env.CATAPI}`, { - "image_id": request[0].id, - "sub_id": i.user.id, - "value": 1 - }) - i.editReply({content: "Has votado positivamente al gato con ID " + "`" + request[0].id + "`"}) - } - if (i.customId === "cat-downvote") { - await axios.post(`https://api.thecatapi.com/v1/votes?api_key=${process.env.CATAPI}`, { - "image_id": request[0].id, - "sub_id": i.user.id, - "value": -1 - }) - i.editReply({content: "Has votado negativamente al gato con ID " + "`" + request[0].id + "`"}) - } - }) - collector.on('end', async (i) => { - await message.edit({components: [rowdisabled]}) - }) - }, -}); \ No newline at end of file