forked from tuhinpal/WhatsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspam.ts
68 lines (62 loc) · 1.86 KB
/
spam.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//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, args: string[]) => {
const count = Number(args.shift());
if (isNaN(count)) {
await client.sendMessage(msg.to, `🙇♂️ *Error*\n\n` + "```Invalid count```");
return 0;
}
if (count <= 0) {
await client.sendMessage(
msg.to,
`🙇♂️ *Error*\n\n` + "```Count can't be zero.```",
);
return 0;
}
if (msg.hasQuotedMsg) {
const quotedMsg = await msg.getQuotedMessage();
if (quotedMsg.hasMedia) {
const media = await quotedMsg
.downloadMedia()
.then((media) => media)
.catch(() => null);
let sticker = false;
if (quotedMsg.type == "sticker" && media) sticker = true;
for (let i = 0; i < count; i++) {
try {
await client.sendMessage(
msg.to,
new MessageMedia(media.mimetype, media.data, media.filename),
{ sendMediaAsSticker: sticker },
);
} catch {}
}
} else {
for (let i = 0; i < count; i++)
await client.sendMessage(msg.to, quotedMsg.body);
}
} else {
if (args.length) {
const text = args.join(" ");
for (let i = 0; i < count; i++) await client.sendMessage(msg.to, text);
} else {
await client.sendMessage(
msg.to,
"```No text found for spamming!!! Please read !help spam.```",
);
}
}
};
const command: Command = {
name: "Spam",
description: "spams a certain message for given number of times",
command: "!spam",
commandType: "plugin",
isDependent: false,
help: `*Spam*\n\nSpam Messages. \n\n*!spam [count text]*\nOR\nreply *!spam [count]* to any message`,
execute,
public: false,
};
export default command;