forked from Galactic/galactic-bot
78 lines
2.0 KiB
JavaScript
78 lines
2.0 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
|
|
class MusicTasteCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'musictaste',
|
|
aliases: ['music-taste'],
|
|
module: 'miscellaneous',
|
|
arguments: [
|
|
{
|
|
name: 'song',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG', 'VERBAL'],
|
|
default: true
|
|
},
|
|
{
|
|
name: 'album',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG', 'VERBAL'],
|
|
default: true
|
|
}
|
|
],
|
|
disabled: true,
|
|
archivable: false
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
this._cache = null;
|
|
this._cached = null;
|
|
|
|
}
|
|
|
|
async execute(message, { params, args }) { //eslint-disable-line
|
|
|
|
if(!this._cache
|
|
|| this._cached+60000 > Date.now()) await this.cache();
|
|
|
|
const data = [];
|
|
for(const user of this._cache) {
|
|
const { activities } = user.presences;
|
|
for(const activity of activities) {
|
|
if(activity.name === 'SPOTIFY' && activity.type === 'LISTENING') data.push({
|
|
song: activity.details,
|
|
artist: activity.state,
|
|
album: activity.assets.largeText,
|
|
user
|
|
});
|
|
}
|
|
}
|
|
|
|
// const filters =
|
|
|
|
this.embed();
|
|
|
|
|
|
}
|
|
|
|
|
|
async cache() {
|
|
|
|
const result = await this.client.shard.broadcastEval(`this.users.cache.filter((user) => {
|
|
for(const activity of user?.presence.activities) {
|
|
if(activity.name === 'Spotify' && activity.type === 'LISTENING') return true;
|
|
}
|
|
})`).catch((error) => this.client.logger.error(`Error fetching users via musictaste: ${error}`));
|
|
|
|
this._cache = result.reduce((p, v) => p.concat(v));
|
|
this._cached = Date.now();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
module.exports = MusicTasteCommand; |