2022-05-16 18:41:15 +01:00
|
|
|
import { Command } from "../type/command";
|
|
|
|
import randomBunny from "random-bunny";
|
2022-09-18 11:57:22 +01:00
|
|
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
|
|
|
import EmbedColours from "../constants/EmbedColours";
|
2022-05-16 18:41:15 +01:00
|
|
|
|
|
|
|
export default class Bunny extends Command {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
super.CommandBuilder = new SlashCommandBuilder()
|
|
|
|
.setName("bunny")
|
|
|
|
.setDescription("Get a random picture of a rabbit.");
|
2022-05-16 18:41:15 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
public override async execute(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
|
2022-09-05 18:07:32 +01:00
|
|
|
const subreddits = [
|
|
|
|
'rabbits',
|
|
|
|
'bunnieswithhats',
|
|
|
|
'buncomfortable',
|
|
|
|
'bunnytongues',
|
|
|
|
'dutchbunnymafia',
|
|
|
|
];
|
|
|
|
|
|
|
|
const random = Math.floor(Math.random() * subreddits.length);
|
|
|
|
const selectedSubreddit = subreddits[random];
|
|
|
|
|
|
|
|
const result = await randomBunny(selectedSubreddit, 'hot');
|
2022-05-16 18:41:15 +01:00
|
|
|
|
|
|
|
if (result.IsSuccess) {
|
2022-09-18 11:57:22 +01:00
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor(EmbedColours.Ok)
|
|
|
|
.setTitle(result.Result!.Title)
|
|
|
|
.setDescription(result.Result!.Permalink)
|
2022-05-16 18:41:15 +01:00
|
|
|
.setImage(result.Result!.Url)
|
|
|
|
.setURL(`https://reddit.com${result.Result!.Permalink}`)
|
2022-09-18 11:57:22 +01:00
|
|
|
.setFooter({ text: `r/${selectedSubreddit} · ${result.Result!.Ups} upvotes`});
|
|
|
|
|
|
|
|
await interaction.reply({ embeds: [ embed ]});
|
2022-05-16 18:41:15 +01:00
|
|
|
} else {
|
2022-09-18 11:57:22 +01:00
|
|
|
await interaction.reply("There was an error running this command.");
|
2022-05-16 18:41:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|