52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { EmbedBuilder, Interaction, SlashCommandBuilder } from 'discord.js';
|
|
import got from 'got';
|
|
import { knownServers } from '../lib/knownServers';
|
|
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';
|
|
|
|
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)
|
|
),
|
|
|
|
serverWhitelist: [...knownServers.firepit_extended, ...knownServers.fbi],
|
|
|
|
execute: async (interaction: Interaction) => {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
await interaction.deferReply({ephemeral: false});
|
|
|
|
let what = interaction.options.getString('what', true).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 EmbedBuilder()
|
|
.setTitle(whatOrig)
|
|
.setImage(thumbURL)
|
|
.setFooter({text: 'Image may not always be accurate.'})
|
|
.setTimestamp();
|
|
|
|
await interaction.followUp({
|
|
embeds: [embed]
|
|
});
|
|
}
|
|
}; |