Skip to content

Commit

Permalink
Update info-speedtest.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Flores authored Apr 10, 2024
1 parent 518f844 commit e4dbed0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions plugins/info-speedtest.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import cp from 'child_process';
import {promisify} from 'util';
import { promisify } from 'util';
const exec = promisify(cp.exec).bind(cp);

const handler = async (m) => {
await conn.reply(m.chat, global.wait, m);
let o;
try {
o = await exec('python3 speedtest.py --secure --share');
const { stdout, stderr } = o;
if (stdout.trim()) {
const result = stdout.trim();

const match = result.match(/https?:\/\/\S+/);
if (match) {
const imageLink = match[0];

await conn.sendFile(m.chat, imageLink, 'speedtest.png', 'Resultado del speedtest:');
await conn.reply(m.chat, result.replace(imageLink, ''), m);
} else {
await conn.reply(m.chat, result, m);
}
}
if (stderr.trim()) {
await conn.reply(m.chat, stderr, m);
}
} catch (e) {
o = e;
} finally {
const {stdout, stderr} = o;
if (stdout.trim()) m.reply(stdout);
if (stderr.trim()) m.reply(stderr);
await conn.reply(m.chat, e.message, m);
}
};

handler.help = ['speedtest'];
handler.tags = ['info'];
handler.command = /^(speedtest?|test?speed)$/i;
Expand Down

0 comments on commit e4dbed0

Please sign in to comment.