From 4a48b3f2b002de0d35841fe5940b5808de4a8d7f Mon Sep 17 00:00:00 2001 From: Lio Young Date: Fri, 22 Oct 2021 17:29:39 +0200 Subject: [PATCH] create animal commands and use imageproxy --- src/discord/commands/animals/cat.ts | 30 ++++++++++++++++++ src/discord/commands/animals/fox.ts | 29 ++++++++++++++++++ src/discord/commands/animals/hyena.ts | 31 +++++++++++++++++++ src/discord/commands/animals/shibe.ts | 30 ++++++++++++++++++ src/discord/commands/animals/wolf.ts | 30 ++++++++++++++++++ src/utils/animals.ts | 44 +++++++++++++++++++-------- 6 files changed, 182 insertions(+), 12 deletions(-) create mode 100644 src/discord/commands/animals/cat.ts create mode 100644 src/discord/commands/animals/fox.ts create mode 100644 src/discord/commands/animals/hyena.ts create mode 100644 src/discord/commands/animals/shibe.ts create mode 100644 src/discord/commands/animals/wolf.ts diff --git a/src/discord/commands/animals/cat.ts b/src/discord/commands/animals/cat.ts new file mode 100644 index 0000000..f5de595 --- /dev/null +++ b/src/discord/commands/animals/cat.ts @@ -0,0 +1,30 @@ +import { Context } from "@utils/types" +import { Command } from "@modules/eu/src/index" +import request from "@utils/animals" +import { MessageEmbed } from "discord.js" + +export = class Cat extends Command { + constructor() { + super({ + name: "cat", + description: "Sends a random cat image", + }) + + } + + async run(context: Context): Promise { + let { image, provider } = await request("cat") + // console.log({ image, provider }) + if (context.settings.embeds) { + let Embed = new MessageEmbed() + .setImage(image[0]) + .setFooter(`Thaldrin - Image provided by ${provider}`, "https://thaldrin.media/avatar.png") + .setColor("ORANGE") + + context.channel.send({ embeds: [Embed] }) + } + else { + context.channel.send(image[0]) + } + } +} diff --git a/src/discord/commands/animals/fox.ts b/src/discord/commands/animals/fox.ts new file mode 100644 index 0000000..6560eeb --- /dev/null +++ b/src/discord/commands/animals/fox.ts @@ -0,0 +1,29 @@ +import { Context } from "@utils/types" +import { Command } from "@modules/eu/src/index" +import request from "@utils/animals" +import { MessageEmbed } from "discord.js" + +export = class Fox extends Command { + constructor() { + super({ + name: "fox", + description: "Sends a random fox image", + }) + + } + + async run(context: Context): Promise { + let data = await request("fox") + if (context.settings.embeds) { + let Embed = new MessageEmbed() + .setImage(data.image.url) + .setFooter(`Thaldrin - Image provided by ${data.provider}`, "https://thaldrin.media/avatar.png") + .setColor("ORANGE") + + context.channel.send({ embeds: [Embed] }) + } + else { + context.channel.send(data.image.url) + } + } +} diff --git a/src/discord/commands/animals/hyena.ts b/src/discord/commands/animals/hyena.ts new file mode 100644 index 0000000..becb1a4 --- /dev/null +++ b/src/discord/commands/animals/hyena.ts @@ -0,0 +1,31 @@ +import { Context } from "@utils/types" +import { Command } from "@modules/eu/src/index" +import request from "@utils/animals" +import { MessageEmbed } from "discord.js" + +export = class Hyena extends Command { + constructor() { + super({ + name: "hyena", + aliases: ["yeen"], + description: "Sends a random yeen", + }) + + } + + async run(context: Context): Promise { + let data = await request("hyena") + + if (context.settings.embeds) { + let Embed = new MessageEmbed() + .setImage(data.image.url) + .setFooter(`Thaldrin - Image provided by ${data.provider}`, "https://thaldrin.media/avatar.png") + .setColor("ORANGE") + + context.channel.send({ embeds: [Embed] }) + } + else { + context.channel.send(data.image.url) + } + } +} diff --git a/src/discord/commands/animals/shibe.ts b/src/discord/commands/animals/shibe.ts new file mode 100644 index 0000000..62c8db1 --- /dev/null +++ b/src/discord/commands/animals/shibe.ts @@ -0,0 +1,30 @@ +import { Context } from "@utils/types" +import { Command } from "@modules/eu/src/index" +import request from "@utils/animals" +import { MessageEmbed } from "discord.js" + +export = class Shibe extends Command { + constructor() { + super({ + name: "shibe", + description: "Sends a random shibe", + }) + + } + + async run(context: Context): Promise { + let { image, provider } = await request("shibe") + // console.log({ image, provider }) + if (context.settings.embeds) { + let Embed = new MessageEmbed() + .setImage(image[0]) + .setFooter(`Thaldrin - Image provided by ${provider}`, "https://thaldrin.media/avatar.png") + .setColor("ORANGE") + + context.channel.send({ embeds: [Embed] }) + } + else { + context.channel.send(image[0]) + } + } +} diff --git a/src/discord/commands/animals/wolf.ts b/src/discord/commands/animals/wolf.ts new file mode 100644 index 0000000..b3af259 --- /dev/null +++ b/src/discord/commands/animals/wolf.ts @@ -0,0 +1,30 @@ +import { Context } from "@utils/types" +import { Command } from "@modules/eu/src/index" +import request from "@utils/animals" +import { MessageEmbed } from "discord.js" + +export = class Wolf extends Command { + constructor() { + super({ + name: "wolf", + description: "Sends a random Wolf image", + }) + + } + + async run(context: Context): Promise { + let data = await request("wolf") + + if (context.settings.embeds) { + let Embed = new MessageEmbed() + .setImage(data.image.url) + .setFooter(`Thaldrin - Image provided by ${data.provider}`, "https://thaldrin.media/avatar.png") + .setColor("ORANGE") + + context.channel.send({ embeds: [Embed] }) + } + else { + context.channel.send(data.image.url) + } + } +} diff --git a/src/utils/animals.ts b/src/utils/animals.ts index c747903..479588b 100644 --- a/src/utils/animals.ts +++ b/src/utils/animals.ts @@ -1,20 +1,40 @@ +import { ApplicationCommandPermissionTypes } from "discord.js/typings/enums"; import yiff from "./yiff"; type animal = "bird" | "cat" | "fox" | "hyena" | "shibe" | "wolf"; export default async function request(animal: animal) { switch (animal) { - case "shibe": - return { image: await yiff.shibe("shibes", 1), provider: "shibe.online" }; - case "bird": - return { image: await yiff.shibe("birds", 1), provider: "shibe.online" }; - case "cat": - return { image: await yiff.shibe("cats", 1), provider: "shibe.online" }; - case "fox": - return { image: await yiff.thaldrin("foxes"), provider: "thaldr.in" }; - case "hyena": - return { image: await yiff.thaldrin("yeens"), provider: "thaldr.in" }; - case "wolf": - return { image: await yiff.thaldrin("wolves"), provider: "thaldr.in" }; + case "shibe": { + let request = await yiff.shibe("shibes", 1) + + let proxied = request.map(x => ("https://proxy.thaldrin.media/" + x)) + return { image: proxied, provider: "shibe.online" }; + } + case "bird": { + let request = await yiff.shibe("birds", 1) + let proxied = request.map(x => ("https://proxy.thaldrin.media/" + x)) + return { image: proxied, provider: "shibe.online" }; + } + case "cat": { + let request = await yiff.shibe("cats", 1) + let proxied = request.map(x => ("https://proxy.thaldrin.media/" + x)) + return { image: proxied, provider: "shibe.online" }; + } + case "fox": { + let image = await yiff.thaldrin("foxes") + image.url = "https://proxy.thaldrin.media/" + image.url + return { image, provider: "thaldr.in" }; + } + case "hyena": { + let image = await yiff.thaldrin("yeens") + image.url = "https://proxy.thaldrin.media/" + image.url + return { image, provider: "thaldr.in" }; + } + case "wolf": { + let image = await yiff.thaldrin("wolves") + image.url = "https://proxy.thaldrin.media/" + image.url + return { image, provider: "thaldr.in" }; + } } } \ No newline at end of file