From 39b8e045d51d2bdb2859bd820a44bb505613021e Mon Sep 17 00:00:00 2001 From: Lio Young Date: Sun, 16 May 2021 23:39:18 +0200 Subject: [PATCH] unify animal image commands to use a single function --- .gitignore | 3 ++- src/modules/animals/birb.ts | 4 ++-- src/modules/animals/cat.ts | 13 +++++++------ src/modules/animals/fox.ts | 5 +++-- src/modules/animals/hyena.ts | 5 +++-- src/modules/animals/shibe.ts | 6 ++++-- src/modules/animals/wolf.ts | 5 +++-- src/utils/animals.ts | 20 ++++++++++++++++++++ 8 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 src/utils/animals.ts diff --git a/.gitignore b/.gitignore index 4f4750d..f216a68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config.ts node_modules/ build/ -logs/ \ No newline at end of file +logs/ +.vscode diff --git a/src/modules/animals/birb.ts b/src/modules/animals/birb.ts index b544dba..e16aa0f 100644 --- a/src/modules/animals/birb.ts +++ b/src/modules/animals/birb.ts @@ -2,6 +2,7 @@ import yiff from '../../utils/yiff'; import Command from '../../handler/structures/Command'; import { Context } from '../../utils/types'; import { MessageEmbed } from 'discord.js'; +import request from '../../utils/animals'; export = class Birb extends Command { constructor() { @@ -14,8 +15,7 @@ export = class Birb extends Command { } async command(ctx: Context) { - let image = await yiff.shibe("birds", 1) - let provider = "shibe.online" + let { image, provider } = await request('bird') if (ctx.settings.embeds) { let Cat = new MessageEmbed() .setImage(image[0]) diff --git a/src/modules/animals/cat.ts b/src/modules/animals/cat.ts index 1f602fd..1f15d23 100644 --- a/src/modules/animals/cat.ts +++ b/src/modules/animals/cat.ts @@ -2,20 +2,21 @@ import yiff from '../../utils/yiff'; import Command from '../../handler/structures/Command'; import { Context } from '../../utils/types'; import { MessageEmbed } from 'discord.js'; +import request from '../../utils/animals'; -export = class Birb extends Command { +export = class Cat extends Command { constructor() { super({ - name: "birb", - description: "Show a Birb", - aliases: ["bird", 'birds'], + name: "cat", + description: "Show a Cat", + aliases: ["mow", 'meow'], cooldown: 2, }) } async command(ctx: Context) { - let image = await yiff.shibe("birds", 1) - let provider = "shibe.online" + let { image, provider } = await request('shibe') + if (ctx.settings.embeds) { let Birb = new MessageEmbed() .setImage(image[0]) diff --git a/src/modules/animals/fox.ts b/src/modules/animals/fox.ts index 7da4198..d984b17 100644 --- a/src/modules/animals/fox.ts +++ b/src/modules/animals/fox.ts @@ -2,6 +2,7 @@ import yiff from '../../utils/yiff'; import Command from '../../handler/structures/Command'; import { Context } from '../../utils/types'; import { MessageEmbed } from 'discord.js'; +import request from '../../utils/animals'; export = class Fox extends Command { constructor() { @@ -14,8 +15,8 @@ export = class Fox extends Command { } async command(ctx: Context) { - let image = await yiff.thaldrin("foxes") - let provider = "thaldr.in" + let { image, provider } = await request('fox') + if (ctx.settings.embeds) { let Fox = new MessageEmbed() diff --git a/src/modules/animals/hyena.ts b/src/modules/animals/hyena.ts index d1ca4fe..a2a9922 100644 --- a/src/modules/animals/hyena.ts +++ b/src/modules/animals/hyena.ts @@ -2,6 +2,7 @@ import yiff from '../../utils/yiff'; import Command from '../../handler/structures/Command'; import { Context } from '../../utils/types'; import { MessageEmbed } from 'discord.js'; +import request from '../../utils/animals'; export = class Hyena extends Command { constructor() { @@ -14,8 +15,8 @@ export = class Hyena extends Command { } async command(ctx: Context) { - let image = await yiff.thaldrin("yeens") - let provider = "thaldr.in" + let { image, provider } = await request('hyena') + if (ctx.settings.embeds) { let Hyena = new MessageEmbed() diff --git a/src/modules/animals/shibe.ts b/src/modules/animals/shibe.ts index b9eabd4..a75ed73 100644 --- a/src/modules/animals/shibe.ts +++ b/src/modules/animals/shibe.ts @@ -2,6 +2,7 @@ import yiff from '../../utils/yiff'; import Command from '../../handler/structures/Command'; import { Context } from '../../utils/types'; import { MessageEmbed } from 'discord.js'; +import request from '../../utils/animals'; export = class Shibe extends Command { constructor() { @@ -14,8 +15,9 @@ export = class Shibe extends Command { } async command(ctx: Context) { - let image = await yiff.shibe("shibes", 1) - let provider = "shibe.online" + + let { image, provider } = await request('shibe') + if (ctx.settings.embeds) { let Shibe = new MessageEmbed() .setImage(image[0]) diff --git a/src/modules/animals/wolf.ts b/src/modules/animals/wolf.ts index aad7f8c..143b48e 100644 --- a/src/modules/animals/wolf.ts +++ b/src/modules/animals/wolf.ts @@ -2,6 +2,7 @@ import yiff from '../../utils/yiff'; import Command from '../../handler/structures/Command'; import { Context } from '../../utils/types'; import { MessageEmbed } from 'discord.js'; +import request from '../../utils/animals'; export = class Wolf extends Command { constructor() { @@ -14,8 +15,8 @@ export = class Wolf extends Command { } async command(ctx: Context) { - let image = await yiff.thaldrin("wolves") - let provider = "thaldr.in" + let { image, provider } = await request('wolf') + if (ctx.settings.embeds) { let Wolf = new MessageEmbed() .setImage(image.url) diff --git a/src/utils/animals.ts b/src/utils/animals.ts new file mode 100644 index 0000000..2808c77 --- /dev/null +++ b/src/utils/animals.ts @@ -0,0 +1,20 @@ +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" }; + } +}