From 58858c5d0965e039d8dbab8839e5e2b881307fc5 Mon Sep 17 00:00:00 2001 From: Alyxia Sother Date: Mon, 17 May 2021 17:24:54 +0000 Subject: [PATCH 1/2] Added pat command --- package-lock.json | 35 +++++++++++++++++++++++++++++++++++ package.json | 1 + src/commands/fun/pat.ts | 30 ++++++++++++++++++++++++++++++ src/defs/petpet.d.ts | 4 ++++ 4 files changed, 70 insertions(+) create mode 100644 src/commands/fun/pat.ts create mode 100644 src/defs/petpet.d.ts diff --git a/package-lock.json b/package-lock.json index 59d7bdd..d7dc9f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "moment": "^2.29.1", "ms": "^2.1.3", "onion-lasers": "^1.1.2", + "pet-pet-gif": "^1.0.8", "relevant-urban": "^2.0.0", "translate-google": "^1.4.3", "weather-js": "^2.0.0" @@ -3015,6 +3016,14 @@ "assert-plus": "^1.0.0" } }, + "node_modules/gifencoder": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/gifencoder/-/gifencoder-2.0.1.tgz", + "integrity": "sha512-x19DcyWY10SkshBpokqFOo/HBht9GB75evRYvaLMbez9p+yB/o+kt0fK9AwW59nFiAMs2UUQsjv1lX/hvu9Ong==", + "dependencies": { + "canvas": "^2.2.0" + } + }, "node_modules/glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -5334,6 +5343,15 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, + "node_modules/pet-pet-gif": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/pet-pet-gif/-/pet-pet-gif-1.0.8.tgz", + "integrity": "sha512-xmQM2DhlSPb1Wo4L5Z6Er4QdzVUjblyUg6LgtvGGtXnwnuhOZBQ0JhNyM+1CL6zxJAG5CQFLhIXxxQa28YpBdg==", + "dependencies": { + "gifencoder": "^2.0.1", + "lodash": "^4.17.21" + } + }, "node_modules/picomatch": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.3.tgz", @@ -10179,6 +10197,14 @@ "assert-plus": "^1.0.0" } }, + "gifencoder": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/gifencoder/-/gifencoder-2.0.1.tgz", + "integrity": "sha512-x19DcyWY10SkshBpokqFOo/HBht9GB75evRYvaLMbez9p+yB/o+kt0fK9AwW59nFiAMs2UUQsjv1lX/hvu9Ong==", + "requires": { + "canvas": "^2.2.0" + } + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -11988,6 +12014,15 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, + "pet-pet-gif": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/pet-pet-gif/-/pet-pet-gif-1.0.8.tgz", + "integrity": "sha512-xmQM2DhlSPb1Wo4L5Z6Er4QdzVUjblyUg6LgtvGGtXnwnuhOZBQ0JhNyM+1CL6zxJAG5CQFLhIXxxQa28YpBdg==", + "requires": { + "gifencoder": "^2.0.1", + "lodash": "^4.17.21" + } + }, "picomatch": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.3.tgz", diff --git a/package.json b/package.json index e94ee70..bbc8ec8 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "moment": "^2.29.1", "ms": "^2.1.3", "onion-lasers": "^1.1.2", + "pet-pet-gif": "^1.0.8", "relevant-urban": "^2.0.0", "translate-google": "^1.4.3", "weather-js": "^2.0.0" diff --git a/src/commands/fun/pat.ts b/src/commands/fun/pat.ts new file mode 100644 index 0000000..be8070d --- /dev/null +++ b/src/commands/fun/pat.ts @@ -0,0 +1,30 @@ +import {MessageAttachment, User} from "discord.js"; +import {NamedCommand, Command} from "onion-lasers"; +import petPetGif from "pet-pet-gif"; + +export default new NamedCommand({ + description: "Generates a pat GIF of the provided attachment image OR the avatar of the mentioned user.", + usage: "(@user)", + async run({message, send, author}) { + if (message.attachments.size !== 0) { + const attachment = message.attachments.first()!; + const gif = await petPetGif(attachment.url); + const file = new MessageAttachment(gif, "pat.gif"); + send(file); + } else { + const gif = await petPetGif(author.displayAvatarURL({format: "png"})); + const file = new MessageAttachment(gif, "pat.gif"); + send(file); + } + }, + id: "user", + user: new Command({ + description: "User to generate a GIF of.", + async run({send, args}) { + const user: User = args[0]; + const gif = await petPetGif(user.displayAvatarURL({format: "png"})); + const file = new MessageAttachment(gif, "pat.gif"); + send(file); + } + }) +}); diff --git a/src/defs/petpet.d.ts b/src/defs/petpet.d.ts new file mode 100644 index 0000000..d59b77b --- /dev/null +++ b/src/defs/petpet.d.ts @@ -0,0 +1,4 @@ +declare module "pet-pet-gif" { + function petPetGif(image: string): Promise; + export = petPetGif; +} From 6003367a6b170742a04255978afcdc6fd9f64da1 Mon Sep 17 00:00:00 2001 From: Alyxia Sother Date: Mon, 17 May 2021 19:49:10 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: WatDuhHekBro --- src/commands/fun/pat.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/commands/fun/pat.ts b/src/commands/fun/pat.ts index be8070d..f60b41b 100644 --- a/src/commands/fun/pat.ts +++ b/src/commands/fun/pat.ts @@ -1,5 +1,5 @@ import {MessageAttachment, User} from "discord.js"; -import {NamedCommand, Command} from "onion-lasers"; +import {NamedCommand, Command, RestCommand, getUserByNickname} from "onion-lasers"; import petPetGif from "pet-pet-gif"; export default new NamedCommand({ @@ -26,5 +26,18 @@ export default new NamedCommand({ const file = new MessageAttachment(gif, "pat.gif"); send(file); } + }), + any: new RestCommand({ + description: "User to generate a GIF of.", + async run({send, combined, guild}) { + const user = await getUserByNickname(combined, guild); + + if (typeof user === "string") send(user); + else { + const gif = await petPetGif(user.displayAvatarURL({format: "png"})); + const file = new MessageAttachment(gif, "pat.gif"); + send(file); + } + } }) });