misc.mcserver: increase timeout, add reaction

This commit is contained in:
Cynthia Foxwell 2023-07-09 18:03:28 -06:00
parent edb2bdb552
commit 3d600c8c9a

View file

@ -758,18 +758,20 @@ mcserver.callback = async function (msg, line) {
const ip = split[0]; const ip = split[0];
const port = split[1] ?? 25565; const port = split[1] ?? 25565;
await msg.addReaction("\uD83C\uDFD3");
const data = await new Promise((resolve, reject) => { const data = await new Promise((resolve, reject) => {
logger.verbose("mcserver", "querying", ip, port); logger.verbose("mcserver", "querying", ip, port);
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
logger.verbose("mcserver", "timeout"); logger.verbose("mcserver", "timeout");
resolve("timeout"); resolve("timeout");
}, 10000); }, 60000);
const client = net.createConnection( const client = net.createConnection(
{ {
host: ip, host: ip,
port: port, port: port,
timeout: 10000, timeout: 60000,
}, },
function () { function () {
logger.verbose("mcserver", "connect"); logger.verbose("mcserver", "connect");
@ -803,8 +805,11 @@ mcserver.callback = async function (msg, line) {
}); });
if (data == "timeout") { if (data == "timeout") {
await msg.removeReaction("\uD83C\uDFD3");
return "Timed out trying to query."; return "Timed out trying to query.";
} else { } else {
await msg.removeReaction("\uD83C\uDFD3");
const motd = data.description.text.replace( const motd = data.description.text.replace(
/\u00a7([a-f0-9k-or])/gi, /\u00a7([a-f0-9k-or])/gi,
(formatting) => { (formatting) => {