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..f60b41b --- /dev/null +++ b/src/commands/fun/pat.ts @@ -0,0 +1,43 @@ +import {MessageAttachment, User} from "discord.js"; +import {NamedCommand, Command, RestCommand, getUserByNickname} 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); + } + }), + 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); + } + } + }) +}); 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; +}