Skip to content

Commit e963a39

Browse files
committed
feat: added everyone command, added --clean option in build command and ignore revoke messages by admin
1 parent 07f0ea2 commit e963a39

4 files changed

Lines changed: 106 additions & 9 deletions

File tree

src/commands/build.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,36 @@ import redis from "../components/redis";
66

77
export const info = {
88
command: "build",
9-
description: "Build the bot.",
10-
usage: "build",
11-
example: "build",
9+
description: "Build the bot (optionally clean before building).",
10+
usage: "build [--clean]",
11+
example: "build --clean",
1212
role: "admin",
1313
cooldown: 5000,
1414
};
1515

1616
const execPromise = util.promisify(exec);
1717

1818
export default async function (msg: Message) {
19-
if (!/^build$/.test(msg.body)) return;
19+
const match = /^build(?:\s+--clean)?$/i.exec(msg.body.trim());
20+
if (!match) return;
2021

21-
const { stdout, stderr } = await execPromise("npm run build");
22-
if (stdout) log.info("Build", `build stdout:\n${stdout}`);
23-
if (stderr) log.warn("Build", `build stderr:\n${stderr}`);
22+
const cleanBuild = msg.body.includes("--clean");
2423

25-
await msg.reply(stdout || stderr);
24+
const command = cleanBuild
25+
? "npm run clean && npm run build"
26+
: "npm run build";
27+
const label = cleanBuild ? "Clean Build" : "Build";
28+
29+
const { stdout, stderr } = await execPromise(command);
30+
31+
if (stdout) log.info(label, `${label} stdout:\n${stdout}`);
32+
if (stderr) log.warn(label, `${label} stderr:\n${stderr}`);
33+
34+
const output = stdout || stderr || "Done (no output)";
35+
const text = `
36+
\`${label}\`
37+
38+
${output.slice(-1500)}
39+
`;
40+
await msg.reply(text);
2641
}

src/commands/everyone.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { GroupChat } from "whatsapp-web.js";
2+
import { Message } from "../../types/message";
3+
import log from "../components/utils/log";
4+
import sleep from "../components/utils/sleep";
5+
import { helloMessage } from "../components/utils/data";
6+
7+
export const info = {
8+
command: "everyone",
9+
description: "Mentions everyone in the group.",
10+
usage: "everyone",
11+
example: "everyone",
12+
role: "admin",
13+
cooldown: 5000,
14+
};
15+
16+
export default async function (msg: Message) {
17+
if (!/^everyone$/i.test(msg.body)) return;
18+
19+
const chat = await msg.getChat();
20+
21+
if (!chat.isGroup) {
22+
await msg.reply("This only works in group chats.");
23+
return;
24+
}
25+
26+
const groupChat = chat as GroupChat;
27+
const participants = groupChat.participants;
28+
const mentions = participants.map((p) => p.id._serialized);
29+
const total = mentions.length;
30+
31+
const baseText =
32+
helloMessage[Math.floor(Math.random() * helloMessage.length)];
33+
const batchSize = 30;
34+
35+
for (let i = 0; i < total; i += batchSize) {
36+
const batchMentions = mentions.slice(i, i + batchSize);
37+
const mentionText = batchMentions
38+
.map((jid) => `@${jid.split("@")[0]}`)
39+
.join(" ");
40+
41+
const messageText = i === 0 ? `${baseText}\n\n${mentionText}` : mentionText;
42+
43+
await msg.reply(messageText, undefined, { mentions: batchMentions });
44+
const min = 2000;
45+
const max = 6000;
46+
const randomMs = Math.floor(Math.random() * (max - min + 1)) + min;
47+
48+
await sleep(randomMs);
49+
}
50+
}

src/components/events/revoke.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@ import { addMessage, getMessage } from "../services/message";
33
import log from "../utils/log";
44
import { getSetting } from "../services/settings";
55
import path from "path";
6+
import client from "../client";
67

78
export default async function (msg: Message, revoked_msg?: Message) {
89
try {
9-
if (msg.fromMe || !revoked_msg || revoked_msg.fromMe) return;
10+
const myJid = (await client()).info.wid._serialized;
11+
if (
12+
msg.fromMe ||
13+
!revoked_msg ||
14+
revoked_msg.fromMe ||
15+
revoked_msg?.author === myJid ||
16+
revoked_msg?.id?.id === myJid
17+
)
18+
return;
1019

1120
const lid = (msg.author ?? msg.from).split("@")[0];
1221

src/components/utils/data.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ const wrong = [
3333
"Sorry, that's wrong. 🙈",
3434
"Try once more! 🔁",
3535
];
36+
const helloMessage = [
37+
"👋 Hello everyone!",
38+
"Listen to me!!!!",
39+
"Hope you're all having a great day ☀️",
40+
"Don't forget to stay hydrated 💧",
41+
"Let's keep the chat active 🔥",
42+
"Good vibes only 😎",
43+
"Teamwork makes the dream work 💪",
44+
"Reminder: be kind and respectful ❤️",
45+
"Big shoutout to everyone here 🎉",
46+
"Stay focused and keep grinding 🚀",
47+
"Anyone up for a quick chat? 💬",
48+
"Sending positive energy your way ✨",
49+
"You’re all awesome! 🙌",
50+
"Let’s make today productive 💼",
51+
"Keep smiling, it confuses people 😁",
52+
"Don’t forget to take breaks ⏸️",
53+
"Let’s get things done! ⚡",
54+
"Coffee time, anyone? ☕",
55+
"Make every moment count ⏰",
56+
"Stay awesome, legends! 👑",
57+
];
3658
const personPronouns = ["he", "she", "him", "her", "they", "them"];
3759

3860
export {
@@ -49,4 +71,5 @@ export {
4971
wrong,
5072
offensiveWords,
5173
personPronouns,
74+
helloMessage,
5275
};

0 commit comments

Comments
 (0)