-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.js
152 lines (141 loc) · 6.98 KB
/
index.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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');
const client = new Client({
restartOnAuthFail: true,
puppeteer: {
headless: true,
args: [ '--no-sandbox', '--disable-setuid-sandbox' ]
},
webVersionCache: {
type: 'remote',
remotePath: "https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html",
},
ffmpeg: './ffmpeg.exe',
authStrategy: new LocalAuth({ clientId: "client" })
});
const config = require('./config/config.json');
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', () => {
console.clear();
const consoleText = './config/console.txt';
fs.readFile(consoleText, 'utf-8', (err, data) => {
if (err) {
console.log(`[${moment().tz(config.timezone).format('HH:mm:ss')}] Console Text not found!`.yellow);
console.log(`[${moment().tz(config.timezone).format('HH:mm:ss')}] ${config.name} is Already!`.green);
} else {
console.log(data.green);
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) {
// Image to Sticker (Auto && Caption)
if ((message.type == "image" || message.type == "video" || message.type == "gif") || (message._data.caption == `${config.prefix}sticker`)) {
if (config.log) console.log(`[${'!'.red}] ${message.from.replace("@c.us", "").yellow} created sticker`);
client.sendMessage(message.from, "*[⏳]* Loading..");
try {
const media = await message.downloadMedia();
client.sendMessage(message.from, media, {
sendMediaAsSticker: true,
stickerName: config.name, // Sticker Name = Edit in 'config/config.json'
stickerAuthor: config.author // Sticker Author = Edit in 'config/config.json'
}).then(() => {
client.sendMessage(message.from, "*[✅]* Successfully!");
});
} catch {
client.sendMessage(message.from, "*[❎]* Failed!");
}
// Image to Sticker (With Reply Image)
} else if (message.body == `${config.prefix}sticker`) {
if (config.log) console.log(`[${'!'.red}] ${message.from.replace("@c.us", "").yellow} created sticker`);
const quotedMsg = await message.getQuotedMessage();
if (message.hasQuotedMsg && quotedMsg.hasMedia) {
client.sendMessage(message.from, "*[⏳]* Loading..");
try {
const media = await quotedMsg.downloadMedia();
client.sendMessage(message.from, media, {
sendMediaAsSticker: true,
stickerName: config.name, // Sticker Name = Edit in 'config/config.json'
stickerAuthor: config.author // Sticker Author = Edit in 'config/config.json'
}).then(() => {
client.sendMessage(message.from, "*[✅]* Successfully!");
});
} catch {
client.sendMessage(message.from, "*[❎]* Failed!");
}
} else {
client.sendMessage(message.from, "*[❎]* Reply Image First!");
}
// Sticker to Image (Auto)
} else if (message.type == "sticker") {
if (config.log) console.log(`[${'!'.red}] ${message.from.replace("@c.us", "").yellow} convert sticker into image`);
client.sendMessage(message.from, "*[⏳]* Loading..");
try {
const media = await message.downloadMedia();
client.sendMessage(message.from, media).then(() => {
client.sendMessage(message.from, "*[✅]* Successfully!");
});
} catch {
client.sendMessage(message.from, "*[❎]* Failed!");
}
// Sticker to Image (With Reply Sticker)
} else if (message.body == `${config.prefix}image`) {
if (config.log) console.log(`[${'!'.red}] ${message.from.replace("@c.us", "").yellow} convert sticker into image`);
const quotedMsg = await message.getQuotedMessage();
if (message.hasQuotedMsg && quotedMsg.hasMedia) {
client.sendMessage(message.from, "*[⏳]* Loading..");
try {
const media = await quotedMsg.downloadMedia();
client.sendMessage(message.from, media).then(() => {
client.sendMessage(message.from, "*[✅]* Successfully!");
});
} catch {
client.sendMessage(message.from, "*[❎]* Failed!");
}
} else {
client.sendMessage(message.from, "*[❎]* Reply Sticker First!");
}
// Claim or change sticker name and sticker author
} else if (message.body.startsWith(`${config.prefix}change`)) {
if (config.log) console.log(`[${'!'.red}] ${message.from.replace("@c.us", "").yellow} change the author name on the sticker`);
if (message.body.includes('|')) {
let name = message.body.split('|')[0].replace(message.body.split(' ')[0], '').trim();
let author = message.body.split('|')[1].trim();
const quotedMsg = await message.getQuotedMessage();
if (message.hasQuotedMsg && quotedMsg.hasMedia) {
client.sendMessage(message.from, "*[⏳]* Loading..");
try {
const media = await quotedMsg.downloadMedia();
client.sendMessage(message.from, media, {
sendMediaAsSticker: true,
stickerName: name,
stickerAuthor: author
}).then(() => {
client.sendMessage(message.from, "*[✅]* Successfully!");
});
} catch {
client.sendMessage(message.from, "*[❎]* Failed!");
}
} else {
client.sendMessage(message.from, "*[❎]* Reply Sticker First!");
}
} else {
client.sendMessage(message.from, `*[❎]* Run the command :\n*${config.prefix}change <name> | <author>*`);
}
// Read chat
} else {
client.getChatById(message.id.remote).then(async (chat) => {
await chat.sendSeen();
});
}
}
});
client.initialize();