info-speedtest.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import os from 'os';
  2. import cp from "child_process";
  3. import { promisify } from "util";
  4. import fetch from 'node-fetch';
  5. const exec = promisify(cp.exec).bind(cp);
  6. var handler = async (m, { conn }) => {
  7. let response = await fetch('https://ip-json.vercel.app/');
  8. let json = await response.json();
  9. delete json.status;
  10. json.result.timeZones = [json.result.timeZones[0]];
  11. let currency = json.result.currency || {};
  12. let currencyCode = currency.code || 'N/A';
  13. let currencyName = currency.name || 'N/A';
  14. let o;
  15. //await conn.reply(m.chat, global.wait, m);
  16. m.react("🚀")
  17. try {
  18. o = await exec('python3 speed.py --secure --share');
  19. const {stdout, stderr} = o;
  20. if (stdout.trim()) {
  21. const match = stdout.match(/http[^"]+\.png/);
  22. const urlImagen = match ? match[0] : null;
  23. await conn.relayMessage(m.chat, {
  24. extendedTextMessage:{ text: stdout.trim(),
  25. contextInfo: { externalAdReply: {
  26. title: "< INFO - SPEEDTEST />", body: `${toTime(os.uptime() * 1000)}`, mediaType: 1,
  27. previewType: 0, renderLargerThumbnail: true,
  28. thumbnailUrl: urlImagen, sourceUrl: redes.getRandom()
  29. }}, mentions: null }}, {quoted: m})}
  30. //conn.sendMessage(m.chat, {image: {url: urlImagen}, caption: stdout.trim()}, {quoted: m})}
  31. if (stderr.trim()) {
  32. const match2 = stderr.match(/http[^"]+\.png/);
  33. const urlImagen2 = match2 ? match2[0] : null;
  34. await conn.relayMessage(m.chat, {
  35. extendedTextMessage:{text: stderr.trim(), contextInfo: {externalAdReply: {
  36. title: "< INFO - SPEEDTEST />", body: `${toTime(os.uptime() * 1000)}`, mediaType: 1,
  37. previewType: 0, renderLargerThumbnail: true,
  38. thumbnailUrl: urlImagen2,
  39. sourceUrl: redes.getRandom()
  40. }}, mentions: null }}, {quoted: m})
  41. //conn.sendMessage(m.chat, {image: {url: urlImagen2}, caption: stderr.trim()}, {quoted: m});
  42. }} catch (e) {
  43. o = e.message;
  44. return m.reply(o)
  45. console.log(e)}}
  46. handler.help = ["speedtest"];
  47. handler.tags = ["main"];
  48. handler.command = /^(speedtest?|test?speed)$/i;
  49. handler.register = true
  50. export default handler
  51. function deleteMessage() {
  52. }
  53. function formatSize(bytes) {
  54. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  55. if (bytes === 0) return '0 Bytes';
  56. const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
  57. return (Math.round(bytes / Math.pow(1024, i) * 100) / 100) + ' ' + sizes[i];
  58. }
  59. function ucword(str) {
  60. return str.replace(/\b\w/g, function(l) {
  61. return l.toUpperCase();
  62. });
  63. }
  64. function toTime(milliseconds) {
  65. const seconds = Math.floor(milliseconds / 1000);
  66. const minutes = Math.floor(seconds / 60);
  67. const hours = Math.floor(minutes / 60);
  68. const days = Math.floor(hours / 24);
  69. return `${days} days, ${hours % 24} hours, ${minutes % 60} minutes, ${seconds % 60} seconds`;
  70. }