forked from tuhinpal/WhatsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticker.ts
53 lines (50 loc) · 1.39 KB
/
sticker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//jshint esversion:8
import whatsapp, { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
const { MessageMedia } = whatsapp;
const execute = async (client: Client, msg: Message) => {
const chatId = (await msg.getChat()).id._serialized;
const message: Message =
(await msg
.getQuotedMessage()
.then((msg) => msg)
.catch(() => null)) || msg;
if (message.hasMedia) {
const attachmentData = await message
.downloadMedia()
.then((media) => media)
.catch(() => null);
if (!attachmentData) {
return;
}
try {
await client.sendMessage(
chatId,
new MessageMedia(
attachmentData.mimetype,
attachmentData.data,
attachmentData.filename,
),
{ sendMediaAsSticker: true },
);
} catch {
await client.sendMessage(chatId, "Sending sticker failed.");
}
} else {
await client.sendMessage(
chatId,
`🙇♂️ *Error*\n\n` + "```No image found to make a Sticker```",
);
}
};
const command: Command = {
name: "Sticker Maker",
description: "generates sticker from image",
command: "!sticker",
commandType: "plugin",
isDependent: false,
help: `*Sticker Maker*\n\nCreate sticker from Image.\n\nReply an image with *!sticker* to get a sticker of that image.`,
execute,
public: true,
};
export default command;