-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
127 lines (110 loc) · 3.19 KB
/
index.js
File metadata and controls
127 lines (110 loc) · 3.19 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const { Client, LocalAuth } = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");
const moment = require("moment-timezone");
const colors = require("colors");
const fs = require("fs");
// Find available Chromium executable
const findChromiumExecutable = () => {
const possiblePaths = [
"/usr/bin/chromium-browser",
"/usr/bin/chromium",
"/usr/bin/google-chrome-stable",
"/usr/bin/google-chrome",
"/snap/bin/chromium",
];
for (const path of possiblePaths) {
if (fs.existsSync(path)) {
return path;
}
}
// If none found, return undefined to let Puppeteer use its default
return undefined;
};
// Find available FFmpeg executable
const findFfmpegExecutable = () => {
const possiblePaths = [
"/usr/bin/ffmpeg",
"/usr/local/bin/ffmpeg",
];
for (const path of possiblePaths) {
if (fs.existsSync(path)) {
return path;
}
}
// Default to system PATH
return "ffmpeg";
};
const chromiumPath = findChromiumExecutable();
const ffmpegPath = findFfmpegExecutable();
// Puppeteer args for headless operation on Ubuntu
const puppeteerArgs = ["--no-sandbox", "--disable-setuid-sandbox"];
const puppeteerConfig = chromiumPath
? {
executablePath: chromiumPath,
args: puppeteerArgs,
}
: { args: puppeteerArgs };
const client = new Client({
restartOnAuthFail: true,
ffmpeg: ffmpegPath,
authStrategy: new LocalAuth({ clientId: "client" }),
puppeteer: puppeteerConfig,
});
const config = {
name: "jomokStickerBot",
author: "alfin",
prefix: ".",
timezone: "Asia/Jakarta",
groups: true,
};
client.on("qr", (qr) => {
console.log(
`[${moment().tz(config.timezone).format("HH:mm:ss")}] Scan the QR below : `
);
qrcode.generate(qr, { small: true });
});
client.on("ready", async () => {
console.clear();
console.log(
`[${moment().tz(config.timezone).format("HH:mm:ss")}] ${
config.name
} is Already!`.green
);
});
client.on("message", async (message) => {
const isGroups = message.from.endsWith("@g.us") ? true : false;
if ((isGroups && config.groups) || !isGroups) {
const isStickerCommand = message.body.startsWith(`${config.prefix}sticker`);
const hasMedia = message.hasMedia;
const hasCaptionStickerCommand =
message._data.caption === `${config.prefix}sticker`;
if ((hasMedia || hasCaptionStickerCommand) && !isStickerCommand) {
return;
}
if (isStickerCommand || hasCaptionStickerCommand) {
if (
message.type == "image" ||
message.type == "video" ||
message.type == "gif" ||
message._data.caption == `${config.prefix}sticker`
) {
try {
const media = await message.downloadMedia();
client.sendMessage(message.from, "*[⏳]* bentar..");
client
.sendMessage(message.from, media, {
sendMediaAsSticker: true,
stickerName: config.name,
stickerAuthor: config.author,
})
.then(() => {
client.sendMessage(message.from, "*[✅]* nih stickernya tod!");
});
} catch {
client.sendMessage(message.from, "*[🔴]* error!");
}
}
}
}
});
client.initialize();