commit 078fce52fb48c05620746285417402fe19090c2e
parent a1b062a27e0854be29074396e42633fdf7552979
Author: Bruno <b-coimbra@hotmail.com>
Date: Sun, 22 Mar 2020 10:12:39 -0300
added pat command
Diffstat:
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/lib/commands/pat.ts b/lib/commands/pat.ts
@@ -0,0 +1,64 @@
+import { Message, Attachment, RichEmbed } from 'discord.js';
+import { FORMATS } from '../extensions';
+
+import Jimp from 'jimp';
+
+const TEMPLATE = "./lib/resources/pat-template.png";
+
+interface Scope {
+ message: Message;
+ args: any;
+}
+
+export default (home_scope: Scope) => {
+ const { message, args } = home_scope;
+
+ if (args.length == 0) {
+ message.channel.send(
+ "Pat someone!\n" + ".pat [@user-name]".format(FORMATS.block)
+ );
+ }
+
+ const size = 200;
+ const [x, y] = [200, 108];
+ const filename = "patted.png";
+
+ const description =
+ `${message.mentions.users.first().username}`.format(FORMATS.bold)
+ + ', you got a pat from '
+ + `${message.author.username}`.format(FORMATS.bold)
+ + ' :blush:';
+
+ const pat = async (image: string) => {
+ const template = await Jimp.read(TEMPLATE);
+ const img = await Jimp.read(image);
+ const composed = template.composite(
+ img.resize(Jimp.AUTO, size), x, y,
+ {
+ mode: Jimp.BLEND_DESTINATION_OVER,
+ opacityDest: 1,
+ opacitySource: 1
+ });
+
+ composed.getBuffer(Jimp.MIME_PNG, (e : Error, buffer: Buffer) => {
+ if (e?.message) {
+ message.channel.send(
+ `Unable to pat ${message.mentions.users.first().username} :(`
+ );
+ return;
+ }
+
+ const attachment = new Attachment(buffer, filename);
+ const embed = new RichEmbed()
+ .setColor('#b943e8')
+ .setTitle("Incoming pat")
+ .setDescription(description)
+ .attachFile(attachment)
+ .setImage(`attachment://${filename}`);
+
+ message.channel.send(embed);
+ });
+ };
+
+ pat(message.mentions.users.first().avatarURL);
+};
diff --git a/lib/resources/pat-template.png b/lib/resources/pat-template.png
Binary files differ.