Change reporting online count periodically to setting bot presence information

This commit is contained in:
Junior 2024-11-22 14:52:20 +00:00
parent bb6b3eb8a1
commit 625bbf1e6f
2 changed files with 26 additions and 30 deletions

View File

@ -2,12 +2,11 @@ const config = {
GUILD_THUMBNAIL: 'https://www.circlecraft.info/images/circlecraft_discord.png', GUILD_THUMBNAIL: 'https://www.circlecraft.info/images/circlecraft_discord.png',
BOT_TOKEN: 'YOUR_BOT_TOKEN_GOES_HERE', BOT_TOKEN: 'YOUR_BOT_TOKEN_GOES_HERE',
CHANNELS_ALLOW: ['123456789012345678', '123456789012345678'], CHANNELS_ALLOW: ['123456789012345678', '123456789012345678'],
REPORT_CHANNEL: '1309262211654619188',
MOD_ROLE: '123456789012345678', MOD_ROLE: '123456789012345678',
STAFF_ROLE: '123456789012345678', STAFF_ROLE: '123456789012345678',
RESTART_ROLE: '123456789012345678' RESTART_ROLE: '123456789012345678'
ALLOW_RESTART: false, ALLOW_RESTART: false,
REPORT_INTERVAL: 0 PRESENCE_INTERVAL: 5
} }
module.exports = config; module.exports = config;

View File

@ -17,10 +17,11 @@ const client = new Client({
client.on('ready', () => { client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`); console.log(`Logged in as ${client.user.tag}!`);
var interval = Config.REPORT_INTERVAL * 60 * 1000; var interval = Config.PRESENCE_INTERVAL * 60 * 1000;
if ( interval != 0 ) { if ( interval != 0 ) {
getOnlineReport();
setInterval(function() { setInterval(function() {
doOnlineReport(channel); getOnlineReport();
}, interval); }, interval);
} }
}); });
@ -30,28 +31,7 @@ process.on('SIGINT', function() {
process.exit(1); process.exit(1);
}); });
function sendOnline(online, channel) { function getOnlineReport(channel = null) {
let playerCount = 0;
let embed = new EmbedBuilder()
.setColor(0x44ff44)
.setThumbnail(Config.GUILD_THUMBNAIL);
for ( const s in online ) {
if ( !online[s].tested ) {
return;
}
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);
channel.send({embeds: [embed]});
}
async function doOnlineReport(channel = null) {
if ( channel === null ) {
const channel = await client.channels.fetch(Config.REPORT_CHANNEL);
}
let online = []; let online = [];
Servers.forEach(function (server) { Servers.forEach(function (server) {
if ( server.active ) { if ( server.active ) {
@ -68,7 +48,7 @@ async function doOnlineReport(channel = null) {
online[server.slug].tested = true; online[server.slug].tested = true;
online[server.slug].online = true; online[server.slug].online = true;
online[server.slug].players = response.players; online[server.slug].players = response.players;
sendOnline(online, channel); //sendOnline(online, channel);
}) })
.then(() => { q.close(); }) .then(() => { q.close(); })
.catch(e => { .catch(e => {
@ -76,18 +56,35 @@ async function doOnlineReport(channel = null) {
//console.log("slug: " + server.slug); //console.log("slug: " + server.slug);
//console.log(online); //console.log(online);
online[server.slug].tested = true; online[server.slug].tested = true;
sendOnline(online, channel); //sendOnline(online, channel);
}); });
} catch (e) { } catch (e) {
console.log(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: 'idle' });
}
} }
client.on('messageCreate', (msg) => { client.on('messageCreate', (msg) => {
if ( msg.author.id === client.user.id ) return; if ( msg.author.id === client.user.id ) return;
if ( msg.content.startsWith(">>paddle") ) { if ( msg.content.startsWith(">>paddle") ) {
console.log("Trying to paddle");
if ( msg.member.roles.cache.has(Config.MOD_ROLE) || msg.member.roles.cache.has(Config.STAFF_ROLE) ) { if ( msg.member.roles.cache.has(Config.MOD_ROLE) || msg.member.roles.cache.has(Config.STAFF_ROLE) ) {
let response = ""; let response = "";
msg.mentions.users.forEach(function (user) { msg.mentions.users.forEach(function (user) {
@ -111,7 +108,7 @@ client.on('messageCreate', (msg) => {
} }
if ( msg.content == ">>online" && Config.CHANNELS_ALLOW.includes(msg.channel.id) ) { if ( msg.content == ">>online" && Config.CHANNELS_ALLOW.includes(msg.channel.id) ) {
doOnlineReport(msg.channel); getOnlineReport(msg.channel);
} }
if ( msg.content == ">>server" && Config.CHANNELS_ALLOW.includes(msg.channel.id) ) { if ( msg.content == ">>server" && Config.CHANNELS_ALLOW.includes(msg.channel.id) ) {