Don't select owner activity if there is none

This commit is contained in:
loicbersier 2020-01-10 00:38:42 +01:00
parent 6851daa978
commit fb4355d68e

View file

@ -40,6 +40,7 @@ class ReadyListener extends Listener {
}, 1800000); }, 1800000);
async function setStatus(client) { async function setStatus(client) {
let owner = client.users.get(client.ownerID);
let random = Math.floor((Math.random() * 3)); let random = Math.floor((Math.random() * 3));
if (random == 0) { // Random "Watching" status taken from json if (random == 0) { // Random "Watching" status taken from json
console.log('Status type: \x1b[32mWatching\x1b[0m'); console.log('Status type: \x1b[32mWatching\x1b[0m');
@ -55,11 +56,15 @@ class ReadyListener extends Listener {
status = status.replace('${prefix}', prefix[0]); status = status.replace('${prefix}', prefix[0]);
client.user.setActivity(`${status} | My prefix is: ${prefix[0]}`, { type: 'PLAYING' }); client.user.setActivity(`${status} | My prefix is: ${prefix[0]}`, { type: 'PLAYING' });
} else if (random == 2) { // Bot owner status } else if (random == 2 && owner.presence.activity != null) { // Bot owner status
console.log('Status type: \x1b[32mCopying owner status\x1b[0m'); console.log('Status type: \x1b[32mCopying owner status\x1b[0m');
let owner = client.users.get(client.ownerID); // Get elapsed time from when the activity started
// { type: owner.presence.activity.type, name: owner.presence.activity.name, url: owner.presence.activity.url } let diffMins = 0;
client.user.setActivity(`${owner.presence.activity.name} | My prefix is: ${prefix[0]}`, owner.presence.activity); if (owner.presence.activity.timestamps) {
let diffMs = (new Date() - owner.presence.activity.timestamps.start);
diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000);
}
client.user.setActivity(`${owner.presence.activity.name}\nfor ${diffMins} minutes | My prefix is: ${prefix[0]}`, owner.presence.activity);
} else { // Random user statuss } else { // Random user statuss
console.log('Status type: \x1b[32mCopying random user status\x1b[0m'); console.log('Status type: \x1b[32mCopying random user status\x1b[0m');
let randomuser = client.users.random(); let randomuser = client.users.random();
@ -67,12 +72,15 @@ class ReadyListener extends Listener {
while (randomuser.presence.activity == null || randomuser.presence.activity.type == 'CUSTOM_STATUS' || randomuser.bot) { while (randomuser.presence.activity == null || randomuser.presence.activity.type == 'CUSTOM_STATUS' || randomuser.bot) {
randomuser = client.users.random(); randomuser = client.users.random();
} }
// Get elapsed time from when the activity started // Get elapsed time from when the activity started
let diffMs = (new Date() - randomuser.presence.activity.timestamps.start); let diffMins = 0;
let diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); if (randomuser.presence.activity.timestamps) {
let diffMs = (new Date() - randomuser.presence.activity.timestamps.start);
client.user.setActivity(`${randomuser.username} is ${randomuser.presence.activity.type.toLowerCase()} ${randomuser.presence.activity.name} for ${diffMins} minutes | My prefix is: ${prefix[0]}`, { type: randomuser.presence.activity.type, url: randomuser.presence.activity.url, name: randomuser.presence.activity.name }); diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000);
}
client.user.setActivity(`${randomuser.username} is ${randomuser.presence.activity.type.toLowerCase()} ${randomuser.presence.activity.name}\nfor ${diffMins} minutes | My prefix is: ${prefix[0]}`, { type: randomuser.presence.activity.type, url: randomuser.presence.activity.url, name: randomuser.presence.activity.name });
} }
} }