2023-11-16 11:33:11 +01:00
|
|
|
import { EmbedBuilder, CommandInteraction, SlashCommandBuilder } from 'discord.js';
|
2022-11-25 16:23:40 +01:00
|
|
|
import got from 'got';
|
2023-09-25 18:24:18 +02:00
|
|
|
import { knownServers } from '../lib/knownServers';
|
2023-11-16 11:33:11 +01:00
|
|
|
import { Command } from '../types/index';
|
|
|
|
|
2022-06-08 01:28:20 +02:00
|
|
|
const rand = require('random-seed').create();
|
|
|
|
|
2022-11-25 16:23:40 +01:00
|
|
|
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';
|
|
|
|
|
2023-11-16 11:33:11 +01:00
|
|
|
export default {
|
2022-06-08 01:28:20 +02:00
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('monitor')
|
|
|
|
.setDescription('Monitor')
|
2022-07-16 21:24:13 +02:00
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName('what')
|
|
|
|
.setDescription('Monitor what? Examples include: "lobby", "bedroom", "park", "playground", etc...')
|
|
|
|
.setRequired(true)
|
|
|
|
),
|
2022-06-08 01:28:20 +02:00
|
|
|
|
2023-09-25 18:24:18 +02:00
|
|
|
serverWhitelist: [...knownServers.firepit_extended, ...knownServers.fbi],
|
|
|
|
|
2023-11-16 11:33:11 +01:00
|
|
|
execute: async (interaction: CommandInteraction) => {
|
2023-06-11 17:23:57 +02:00
|
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
|
2022-11-25 16:23:40 +01:00
|
|
|
await interaction.deferReply({ephemeral: false});
|
|
|
|
|
2023-06-11 17:23:57 +02:00
|
|
|
let what = interaction.options.getString('what', true).toLowerCase();
|
2022-11-25 16:23:40 +01:00
|
|
|
const whatOrig = what;
|
2022-06-08 01:28:20 +02:00
|
|
|
|
|
|
|
if (what.startsWith('the ')) what = what.slice(4);
|
2022-11-25 16:23:40 +01:00
|
|
|
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;
|
2022-06-08 01:28:20 +02:00
|
|
|
|
2023-06-11 17:23:57 +02:00
|
|
|
const embed = new EmbedBuilder()
|
2022-11-25 16:23:40 +01:00
|
|
|
.setTitle(whatOrig)
|
|
|
|
.setImage(thumbURL)
|
2023-06-11 17:23:57 +02:00
|
|
|
.setFooter({text: 'Image may not always be accurate.'})
|
2022-06-08 01:28:20 +02:00
|
|
|
.setTimestamp();
|
|
|
|
|
2022-11-25 16:23:40 +01:00
|
|
|
await interaction.followUp({
|
|
|
|
embeds: [embed]
|
2022-06-08 01:28:20 +02:00
|
|
|
});
|
|
|
|
}
|
2023-11-16 11:33:11 +01:00
|
|
|
} satisfies Command;
|