Move code inside the success promise for online status
This commit is contained in:
parent
d59b7f03d5
commit
3a6a190404
46
index.js
46
index.js
|
@ -41,45 +41,45 @@ function getOnlineReport(channel = null) {
|
|||
});
|
||||
Servers.forEach(function (server) {
|
||||
if ( !online[server.slug] ) return;
|
||||
const q = new Query({host: server.rconAddress, port: server.queryPort, timeout: 250});
|
||||
const q = new Query({host: server.rconAddress, port: server.queryPort, timeout: 7250});
|
||||
try {
|
||||
q.fullStat()
|
||||
.then(response => {
|
||||
online[server.slug].tested = true;
|
||||
online[server.slug].online = true;
|
||||
online[server.slug].players = response.players;
|
||||
//sendOnline(online, channel);
|
||||
})
|
||||
.then(() => { q.close(); })
|
||||
.then(success => {
|
||||
q.close();
|
||||
let playerCount = 0;
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor(0x44ff44)
|
||||
.setThumbnail(Config.GUILD_THUMBNAIL);
|
||||
for ( const s in online ) {
|
||||
if ( !online[s].tested ) {
|
||||
continue;
|
||||
}
|
||||
if ( online[s].players.length > 0 ) {
|
||||
playerCount += online[s].players.length;
|
||||
embed.addFields({name: "**"+online[s].name+"**", value: online[s].players.join(', '), inline: false});
|
||||
}
|
||||
};
|
||||
embed.setTitle("**Players Currently Online:** " + playerCount);
|
||||
if ( channel !== null ) channel.send({embeds: [embed]});
|
||||
if ( Config.PRESENCE_INTERVAL != 0 ) {
|
||||
client.user.setPresence({ activities: [{ name: "Online: " + playerCount }], status: 'online' });
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
q.close();
|
||||
//console.log("slug: " + server.slug);
|
||||
//console.log(online);
|
||||
online[server.slug].tested = true;
|
||||
//sendOnline(online, channel);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
let playerCount = 0;
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor(0x44ff44)
|
||||
.setThumbnail(Config.GUILD_THUMBNAIL);
|
||||
for ( const s in online ) {
|
||||
if ( !online[s].tested ) {
|
||||
continue;
|
||||
}
|
||||
if ( online[s].players.length > 0 ) {
|
||||
playerCount += online[s].players.length;
|
||||
embed.addFields({name: "**"+online[s].name+"**", value: online[s].players.join(', '), inline: false});
|
||||
}
|
||||
};
|
||||
embed.setTitle("**Players Currently Online:** " + playerCount);
|
||||
if ( channel !== null ) channel.send({embeds: [embed]});
|
||||
if ( Config.PRESENCE_INTERVAL != 0 ) {
|
||||
client.user.setPresence({ activities: [{ name: "Online: " + playerCount }], status: 'online' });
|
||||
}
|
||||
}
|
||||
|
||||
client.on('messageCreate', (msg) => {
|
||||
|
@ -200,4 +200,4 @@ client.on('messageCreate', (msg) => {
|
|||
|
||||
client.login(Config.BOT_TOKEN);
|
||||
|
||||
// vim: set ts=4 sw=4:
|
||||
// vim: set et ts=4 sw=4:
|
||||
|
|
Loading…
Reference in New Issue
Block a user