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");
|
||||
|
||||
let data;
|
||||
let timeout = false;
|
||||
try {
|
||||
const timeout = setTimeout(() => {
|
||||
throw "timeout";
|
||||
}, 5000);
|
||||
const doTimeout = setTimeout(() => {
|
||||
timeout = true;
|
||||
}, 60000);
|
||||
const query = new SourceQuery(ip, port);
|
||||
const info = await query.getInfo();
|
||||
const players = await query.getPlayers();
|
||||
const rules = await query.getRules();
|
||||
|
||||
clearTimeout(timeout);
|
||||
clearTimeout(doTimeout);
|
||||
data = {
|
||||
info,
|
||||
players,
|
||||
|
@ -49,15 +50,13 @@ sourcequery.callback = async function (msg, line) {
|
|||
};
|
||||
} catch (err) {
|
||||
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\`\`\``;
|
||||
}
|
||||
}
|
||||
|
||||
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.";
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue