forked from Claxl/StickerBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsgHndlr.js
More file actions
192 lines (182 loc) · 11.1 KB
/
msgHndlr.js
File metadata and controls
192 lines (182 loc) · 11.1 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// const { decryptMedia } = require('@open-wa/wa-decrypt')
// const fs = require('fs-extra')
// //const axios = require('axios')
// const moment = require('moment-timezone')
// //const get = require('got')
// var colors = require('colors');
// const { exec } = require('child_process')
// const { stdout } = require('process')
// moment.tz.setDefault('Europe/Rome').locale('id')
// module.exports = msgHandler = async (client, message) => {
// try {
// const { type, id, from, t, sender, isGroupMsg, chat, caption, isMedia, mimetype, quotedMsg, quotedMsgObj, mentionedJidList } = message
// let { body } = message
// const { name, formattedTitle } = chat
// let { pushname, verifiedName } = sender
// pushname = pushname || verifiedName
// const commands = caption || body || ''
// var withNoDigits = ""
// const command = commands.toLowerCase().split(' ')[0] || ''
// const time = moment(t * 1000).format('DD/MM HH:mm:ss')
// const uaOverride = 'WhatsApp/2.2029.4 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
// if (isMedia && type === 'image') {
// console.log(moment().format("H:mm:ss").green + " Sticker " + message.from);
// client.reply(from, 'Your Sticker is being made, pls be patient', id)
// const mediaData = await decryptMedia(message, uaOverride)
// console.log(moment().format("H:mm:ss").green + " I have decoded the photo " + message.from);
// const imageBase64 = `data:${mimetype};base64,${mediaData.toString('base64')}`
// await client.sendImageAsSticker(from, imageBase64)
// console.log(moment().format("H:mm:ss").green + " sticker made " + message.from);
// }
// if (isMedia && (mimetype === 'video/mp4' && message.duration < 10 || mimetype === 'image/gif' && message.duration < 10)) {
// const mediaData = await decryptMedia(message, uaOverride)
// console.log(moment().format("H:mm:ss").green + " Sticker " + message.from);
// client.reply(from, 'Your Sticker is being made, pls be patient', id)
// const filename = `./media/input.${mimetype.split('/')[1]}`
// console.log(moment().format("H:mm:ss").green + " I have decoded the video " + message.from);
// await fs.writeFileSync(filename, mediaData)
// console.log(moment().format("H:mm:ss").green + " saved video " + message.from);
// await exec(`gify ${filename} ./media/output.gif --fps=30 --scale=240:240`, async function (error, stdout, stderr) {
// console.log(moment().format("H:mm:ss").green + " video converted to gif " + message.from);
// const gif = await fs.readFileSync('./media/output.gif', { encoding: "base64" })
// await client.sendImageAsSticker(from, `data:image/gif;base64,${gif.toString('base64')}`)
// console.log(moment().format("H:mm:ss").green + " sticker sent " + message.from);
// })
// }
// if (command === "!Help") {
// console.log(moment().format("H:m:ss").green + ": Guide " + message.from);
// client.sendText(message.from, 'Connect to the site https://giphy.com/ \n\nChoose your gif\n\nHold and click "Share" if you are on safari\nHold and then click "open image in other tab" if you are on chrome\n\nThen send that link');
// client.sendText(message.from, "https://youtu.be/aGc8Po8G0Bo \n\n\nHere is a little safari video guide\n");
// client.sendText(message.from, "https://youtu.be/YBe_7KzvQ_g \n\n\nHere is a little chrome video guide\n");
// client.sendText(message.from, "If you want a static sticker instead, send a photo\n\nIt could take only the central part of the photo");
// client.sendText(message.from, "From today you can send a video / gif and it will become an animated sticker");
// }
// if (command === "!Link") {
// console.log(moment().format("H:m:ss").green + ": Creator " + message.from);
// client.sendText(message.from, "Use this link to access google drive resources and recorded lectures \n\n\n https://drive.google.com/drive/folders/1TnsZJdZ_gISnefClnIUURAO-Oydshemm?usp=sharing");
// }
// if (command === "!Creator") {
// console.log(moment().format("H:m:ss").green + ": Link " + message.from);
// client.sendText(message.from, "https://www.instagram.com/shlaize/ \n\n\n https://github.com/shl3sh \n\n\nContact me for any bot problems, or if you want to contribute to its growth");
// }
// if (body.includes("media")) {
// console.log(moment().format("H:mm:ss").green + " giphy " + message.from);
// if (!isNaN(body.charAt(13))) {
// console.log(moment().format("H:mm:ss").green + " link with number, I remove the number " + message.from);
// withNoDigits = body.replace(/\d+/, "");
// console.log(moment().format("H:mm:ss").green + withNoDigits);
// console.log(moment().format("H:mm:ss").green + " number removed " + message.from);
// } else {
// console.log(moment().format("H:mm:ss").green + " no number " + message.from);
// withNoDigits = body;
// console.log(moment().format("H:mm:ss").green + withNoDigits);
// console.log(moment().format("H:mm:ss").green + " link" + message.from);
// }
// client.sendGiphyAsSticker(message.from, withNoDigits);
// client.sendText(message.from, "Alright! Wait a moment");
// console.log(moment().format("H:mm:ss").green + "Sticker sent" + message.from);
// }
// } catch (err) {
// console.log("error".red)
// //client.kill().then(a => console.log(a))
// }
// }
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
const { decryptMedia } = require('@open-wa/wa-decrypt')
const fs = require('fs-extra')
//const axios = require('axios')
const moment = require('moment-timezone')
//const get = require('got')
var colors = require('colors');
const { exec } = require('child_process')
const { stdout } = require('process')
moment.tz.setDefault('Europe/Rome').locale('id')
//FUNCTION TO VERIFY SIZE
function getFilesizeInBytes() {
var stats = fs.statSync('./media/output.gif')
var fileSizeInBytes = stats.size;
//Converting to megabytes
var fileSizeInMegabytes = fileSizeInBytes / (1024*1024);
return fileSizeInMegabytes;
}
module.exports = msgHandler = async (client, message) => {
try {
const { type, id, from, t, sender, isGroupMsg, chat, caption, isMedia, mimetype, quotedMsg, quotedMsgObj, mentionedJidList } = message
let { body } = message
const { name, formattedTitle } = chat
let { pushname, verifiedName } = sender
pushname = pushname || verifiedName
const commands = caption || body || ''
var withNoDigits = ""
const command = commands.toLowerCase().split(' ')[0] || ''
const time = moment(t * 1000).format('DD/MM HH:mm:ss')
const uaOverride = 'WhatsApp/2.2029.4 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
if (isMedia && type === 'image') {
console.log(moment().format("H:mm:ss").green + " Sticker " + message.from);
client.reply(from, 'Your Sticker is being made, pls be patient', id)
const mediaData = await decryptMedia(message, uaOverride)
console.log(moment().format("H:mm:ss").green + " decripto la foto " + message.from);
const imageBase64 = `data:${mimetype};base64,${mediaData.toString('base64')}`
await client.sendImageAsSticker(from, imageBase64)
console.log(moment().format("H:mm:ss").green + " sticker inviato " + message.from);
}
if (isMedia && (mimetype === 'video/mp4' && message.duration < 10 || mimetype === 'image/gif' && message.duration < 10)) {
const mediaData = await decryptMedia(message, uaOverride)
console.log(moment().format("H:mm:ss").green + " Sticker Animato " + message.from);
client.reply(from, 'Your Sticker is being made, pls be patient', id)
const filename = `./media/input.${mimetype.split('/')[1]}`
console.log(moment().format("H:mm:ss").green + " decripto il video " + message.from);
await fs.writeFileSync(filename, mediaData)
console.log(moment().format("H:mm:ss").green + " video salvato " + message.from);
await exec(`gify ${filename} ./media/output.gif --fps=30 --scale=240:240`, async function (error, stdout, stderr) {
console.log(moment().format("H:mm:ss").green + " video convertito in gif " + message.from);
const gif = await fs.readFileSync('./media/output.gif', { encoding: "base64" })
<<<<<<< HEAD
await client.sendImageAsSticker(from, `data:image/gif;base64,${gif.toString('base64')}`)
console.log(moment().format("H:mm:ss").green + " sticker inviato " + message.from);
=======
getFilesizeInBytes(); //Verify the file size
if (getFilesizeInBytes() > 4.3){
console.log(moment().format("H:mm:ss").green+" File too large "+message.from);
client.reply(from, "Your gif/videos it's too large, try to compress/optimaze it and send it again!", id)
} else {
await client.sendImageAsSticker(from, `data:image/gif;base64,${gif.toString('base64')}`)
}
console.log(moment().format("H:mm:ss").green+" sticker inviato "+message.from);
>>>>>>> 49c3033c1d5de86ea73c8907216097409286e1b4
})//
}
if (command == '!guida' || command == "!help") {
console.log(moment().format("H:m:ss").green + ": Guida " + message.from);
client.sendText(message.from, 'Collegati al sito https://giphy.com/ \n\nScegli la gif da te preferita\n\nTieni premuto e clicca "Condividi" Se ti trovi su safari\nTieni premuto e clicca "immagine in altra scheda" Se ti trovi su chrome\n\nPoi invia quel link');
client.sendText(message.from, "https://youtu.be/aGc8Po8G0Bo \n\n\nEcco a te una piccola videoguida per safari\n");
client.sendText(message.from, "https://youtu.be/YBe_7KzvQ_g \n\n\nEcco a te una piccola videoguida per chrome\n");
client.sendText(message.from, "Se invece vuoi uno sticker statico, manda una foto\n\nN.B. potrebbe prendere solo la parte centrale della foto");
client.sendText(message.from, "Da oggi puoi anche inviare un video/gif ed esso diventerà uno sticker animato");
}
if (command === "!Creator") {
console.log(moment().format("H:m:ss").green + ": Creator " + message.from);
client.sendText(message.from, "https://www.instagram.com/whataboutclaxl/ \n\n\n https://github.com/Claxl \n\n\nContattami per qualsiasi problema sul bot, se vuoi contribuire alla sua crescita");
}
if (body.includes("media")) {
console.log(moment().format("H:mm:ss").green + " giphy " + message.from);
if (!isNaN(body.charAt(13))) {
console.log(moment().format("H:mm:ss").green + " link con numero, tolgo il numero " + message.from);
withNoDigits = body.replace(/\d+/, "");
console.log(moment().format("H:mm:ss").green + withNoDigits);
console.log(moment().format("H:mm:ss").green + " numero tolto " + message.from);
} else {
console.log(moment().format("H:mm:ss").green + " nessun numero " + message.from);
withNoDigits = body;
console.log(moment().format("H:mm:ss").green + withNoDigits);
console.log(moment().format("H:mm:ss").green + " link" + message.from);
}
client.sendGiphyAsSticker(message.from, withNoDigits);
client.sendText(message.from, "Tutto ok! Attendi un attimo");
console.log(moment().format("H:mm:ss").green + " sticker inviato " + message.from);
}
} catch (err) {
console.log("errore".red)
//client.kill().then(a => console.log(a))
}
}