-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
70 lines (63 loc) · 1.78 KB
/
functions.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
const { downloadContentFromMessage } = require("@whiskeysockets/baileys");
const axios = require("axios");
const fetch = require("node-fetch");
const getBuffer = async (url, opcoes) => {
try {
opcoes ? opcoes : {};
const post = await axios({
method: "get",
url,
headers: {
"user-agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36",
DNT: 1,
"Upgrade-Insecure-Request": 1
},
...opcoes,
responseType: "arraybuffer"
});
return post.data;
} catch (e) {
console.log(e);
}
};
const getFileBuffer = async (mediakey, MediaType) => {
const stream = await downloadContentFromMessage(mediakey, MediaType);
let buffer = Buffer.from([]);
for await (const chunk of stream) {
buffer = Buffer.concat([buffer, chunk]);
}
return buffer;
};
const fetchJson = (url, options) =>
new Promise(async (resolve, reject) => {
fetch(url, options)
.then(response => response.json())
.then(json => {
resolve(json);
})
.catch(err => {
reject(err);
});
});
function getGroupAdmins(participants) {
admins = [];
for (let i of participants) {
if (i.admin == "admin") admins.push(i.id);
if (i.admin == "superadmin") admins.push(i.id);
}
return admins;
}
const getFormattedTime = () => {
const now = new Date();
const hours = String(now.getHours()).padStart(2, "0");
const minutes = String(now.getMinutes()).padStart(2, "0");
const seconds = String(now.getSeconds()).padStart(2, "0");
return `${hours}:${minutes}:${seconds}`;
};
module.exports = {
getBuffer,
getFileBuffer,
fetchJson,
getGroupAdmins,
getFormattedTime
};