forked from yusufusta/WhatsAsena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.js
52 lines (42 loc) · 1.73 KB
/
web.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
/* Copyright (C) 2020 Yusuf Usta.
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
WhatsAsena - Yusuf Usta
*/
const Asena = require('../events');
const {MessageType} = require('@adiwajshing/baileys');
const speedTest = require('@lh2020/speedtest-net');
const Language = require('../language');
const Lang = Language.getString('web');
// https://github.com/ddsol/speedtest.net/blob/master/bin/index.js#L86
function speedText(speed) {
let bits = speed * 8;
const units = ['', 'K', 'M', 'G', 'T'];
const places = [0, 1, 2, 3, 3];
let unit = 0;
while (bits >= 2000 && unit < 4) {
unit++;
bits /= 1000;
}
return `${bits.toFixed(places[unit])} ${units[unit]}bps`;
}
Asena.addCommand({pattern: 'speedtest', fromMe: true, desc: Lang.SPEEDTEST_DESC}, (async (message, match) => {
var msg = await message.reply(Lang.SPEEDTESTING);
var st = await speedTest({acceptLicense: true, acceptGdpr: true});
await message.client.sendMessage(
message.jid,Lang.SPEEDTEST_RESULT + '\n\n' +
'*ISP:* ```' + st.isp + '```\n' +
'*Ping:* ```' + st.ping.latency + 'ms```\n' +
'*' + Lang.UPLOAD + ':* ```' + speedText(st.upload.bandwidth) + '```\n' +
'*' + Lang.DOWNLOAD + ':* ```' + speedText(st.download.bandwidth) + '```\n',MessageType.text
);
await msg.delete();
}));
Asena.addCommand({pattern: 'ping', fromMe: true, deleteCommand: false, desc: Lang.PING_DESC}, (async (message, match) => {
var start = new Date().getTime();
var msg = await message.reply('```Ping!```');
var end = new Date().getTime();
await msg.delete();
await message.client.sendMessage(
message.jid,'*Pong!*\n```' + (end - start) + 'ms```', MessageType.text);
}));