import { SlashCommandBuilder } from '@discordjs/builders'; import { CommandInteraction, MessageEmbed } from 'discord.js'; import got from 'got'; const rand = require('random-seed').create(); const imagesEndpoint = 'https://commons.wikimedia.org/w/api.php?action=query&cmlimit=500&cmtitle=Category%3ALiminal_spaces&cmtype=file&list=categorymembers&format=json'; const imageEndpoint = 'https://commons.wikimedia.org/w/api.php?action=query&piprop=thumbnail&pithumbsize=200&prop=pageimages&titles={}&format=json'; const images = [ 'img1', 'img2', 'img3', 'img4', 'img5', 'img7', 'img8', 'img9', 'img10', 'img11', 'img12', 'img14', 'img15', 'img16', 'img17', 'img19', 'img20' ]; module.exports = { data: new SlashCommandBuilder() .setName('monitor') .setDescription('Monitor') .addStringOption((option) => option .setName('what') .setDescription('Monitor what? Examples include: "lobby", "bedroom", "park", "playground", etc...') .setRequired(true) ), execute: async (interaction: CommandInteraction) => { await interaction.deferReply({ephemeral: false}); let what = interaction.options.getString('what')!.toLowerCase(); const whatOrig = what; if (what.startsWith('the ')) what = what.slice(4); rand.seed(what.trim()); const images = JSON.parse((await got(imagesEndpoint)).body); const imagesArray = images.query.categorymembers; const img = imagesArray[rand.range(imagesArray.length)]; const thumb = JSON.parse((await got(imageEndpoint.replace('{}', encodeURI(img.title)))).body); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const thumbURL = Object.values(thumb.query.pages)[0].thumbnail.source; const embed = new MessageEmbed() .setTitle(whatOrig) .setImage(thumbURL) .setFooter('Image may not always be accurate.') .setTimestamp(); await interaction.followUp({ embeds: [embed] }); } };