/* eslint-disable prefer-destructuring */ import { Activity, Member, Message } from 'eris'; import { Client, Command, RichEmbed } from '../class'; export default class Game extends Command { constructor(client: Client) { super(client); this.name = 'game'; this.description = 'Displays information about the member\'s game.'; this.usage = 'game [member]'; this.permissions = 0; this.aliases = ['activity']; this.guildOnly = true; this.enabled = true; } public async run(message: Message, args: string[]) { try { let member: Member; if (!args[0]) member = message.member; else { // @ts-ignore member = this.client.util.resolveMember(message, args[0], message.channel.guild); if (!member) { return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Member not found.***`); } } if (member.activities.length <= 0) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Cannot find a game for this member.***`); const embed = new RichEmbed(); let mainStatus: Activity; if (member.activities[0].type === 4) { mainStatus = member.activities[1]; embed.setDescription(`*${member.activities[0].state}*`); } else { mainStatus = member.activities[0]; } embed.setAuthor(member.user.username, member.user.avatarURL); if (mainStatus?.name === 'Spotify') { embed.setTitle('Spotify'); embed.setColor('#1ed760'); embed.addField('Song', mainStatus.details, true); embed.addField('Artist', mainStatus.state, true); // @ts-ignore embed.addField('Album', mainStatus.assets.large_text); // @ts-ignore embed.addField('Start', `${new Date(mainStatus.timestamps.start).toLocaleTimeString('en-us')} ET`, true); // @ts-ignore embed.addField('End', `${new Date(mainStatus.timestamps.end).toLocaleTimeString('en-us')} ET`, true); // @ts-ignore embed.setThumbnail(`https://i.scdn.co/image/${mainStatus.assets.large_image.split(':')[1]}`); embed.setFooter(`Listening to Spotify | ${this.client.user.username}`, 'https://media.discordapp.net/attachments/358674161566220288/496894273304920064/2000px-Spotify_logo_without_text.png'); embed.setTimestamp(); } else { return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Only Spotify games are supported at this time.***`); } return message.channel.createMessage({ embed }); } catch (err) { return this.client.util.handleError(err, message, this); } } }