sourcequery: fix timeout
This commit is contained in:
parent
bad6d45963
commit
4bceaa5ede
1 changed files with 9 additions and 10 deletions
|
@ -32,16 +32,17 @@ sourcequery.callback = async function (msg, line) {
|
||||||
await msg.addReaction("\uD83C\uDFD3");
|
await msg.addReaction("\uD83C\uDFD3");
|
||||||
|
|
||||||
let data;
|
let data;
|
||||||
|
let timeout = false;
|
||||||
try {
|
try {
|
||||||
const timeout = setTimeout(() => {
|
const doTimeout = setTimeout(() => {
|
||||||
throw "timeout";
|
timeout = true;
|
||||||
}, 5000);
|
}, 60000);
|
||||||
const query = new SourceQuery(ip, port);
|
const query = new SourceQuery(ip, port);
|
||||||
const info = await query.getInfo();
|
const info = await query.getInfo();
|
||||||
const players = await query.getPlayers();
|
const players = await query.getPlayers();
|
||||||
const rules = await query.getRules();
|
const rules = await query.getRules();
|
||||||
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(doTimeout);
|
||||||
data = {
|
data = {
|
||||||
info,
|
info,
|
||||||
players,
|
players,
|
||||||
|
@ -49,15 +50,13 @@ sourcequery.callback = async function (msg, line) {
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await msg.removeReaction("\uD83C\uDFD3");
|
await msg.removeReaction("\uD83C\uDFD3");
|
||||||
if (err == "timeout") {
|
|
||||||
return "Failed to query server after 5 seconds.";
|
|
||||||
} else {
|
|
||||||
return `:warning: An error occured while querying:\n\`\`\`\n${err.message}\n\`\`\``;
|
return `:warning: An error occured while querying:\n\`\`\`\n${err.message}\n\`\`\``;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await msg.removeReaction("\uD83C\uDFD3");
|
await msg.removeReaction("\uD83C\uDFD3");
|
||||||
if (data?.info == null) {
|
if (timeout) {
|
||||||
|
return "Failed to query server after 1 minute.";
|
||||||
|
} else if (data?.info == null) {
|
||||||
return "Failed to query any data.";
|
return "Failed to query any data.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue