forked from DGXeon/Vimdhayak-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
116 lines (97 loc) · 2.91 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
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
const fetch = require('node-fetch')
const axios = require('axios')
const cfonts = require('cfonts')
const spin = require('spinnies')
const Crypto = require('crypto')
const h2k = (number) => {
var SI_POSTFIXES = ["", " K", " M", " G", " T", " P", " E"]
var tier = Math.log10(Math.abs(number)) / 3 | 0
if(tier == 0) return number
var postfix = SI_POSTFIXES[tier]
var scale = Math.pow(10, tier * 3)
var scaled = number / scale
var formatted = scaled.toFixed(1) + ''
if (/\.0$/.test(formatted))
formatted = formatted.substr(0, formatted.length - 2)
return formatted + postfix
}
const getBuffer = async (url, options) => {
try {
options ? options : {}
const res = await axios({
method: "get",
url,
headers: {
'DNT': 1,
'Upgrade-Insecure-Request': 1
},
...options,
responseType: 'arraybuffer'
})
return res.data
} catch (e) {
console.log(`Error : ${e}`)
}
}
const randomBytes = (length) => {
return Crypto.randomBytes(length)
}
const generateMessageID = () => {
return randomBytes(10).toString('hex').toUpperCase()
}
const getGroupAdmins = (participants) => {
admins = []
for (let i of participants) {
i.isAdmin ? admins.push(i.jid) : ''
}
return admins
}
const getRandom = (ext) => {
return `${Math.floor(Math.random() * 10000)}${ext}`
}
const spinner = {
"interval": 120,
"frames": [
"🦄",
"🦄🦄",
"🦄🦄🦄",
"🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄",
"🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄🦄",
]}
let globalSpinner;
const getGlobalSpinner = (disableSpins = false) => {
if(!globalSpinner) globalSpinner = new spin({ color: 'blue', succeedColor: 'green', spinner, disableSpins});
return globalSpinner;
}
spins = getGlobalSpinner(false)
const start = (id, text) => {
spins.add(id, {text: text})
/*setTimeout(() => {
spins.succeed('load-spin', {text: 'Success'})
}, Number(wait) * 1000)*/
}
const info = (id, text) => {
spins.update(id, {text: text})
}
const success = (id, text) => {
spins.succeed(id, {text: text})
}
const close = (id, text) => {
spins.fail(id, {text: text})
}
const banner = cfonts.render(('Xeon-BOT Inc.'), {
font: 'block',
color: 'white',
align: 'left',
gradient: ["red","yellow"],
lineHeight: 2
});
module.exports = { getBuffer, h2k, generateMessageID, getGroupAdmins, getRandom, start, info, success, banner, close }