community-relations/src/commands/game.ts

69 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-04-15 15:13:22 -04:00
/* eslint-disable prefer-destructuring */
import { Activity, Member, Message } from 'eris';
2020-04-15 15:13:22 -04:00
import { Client, Command, RichEmbed } from '../class';
enum ActivityType {
PLAYING = 0,
STREAMING = 1,
LISTENING = 2,
WATCHING = 3,
CUSTOM_STATUS = 4
}
2020-04-15 15:13:22 -04:00
export default class Game extends Command {
constructor(client: Client) {
super(client);
this.name = 'game';
this.description = 'Displays information about the member\'s game.';
2020-04-15 15:33:46 -04:00
this.usage = 'game [member]';
2020-04-15 15:13:22 -04:00
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 {
member = this.client.util.resolveMember(args.join(' '), message.member.guild);
2020-04-15 15:13:22 -04:00
if (!member) {
return this.error(message.channel, 'Member not found.');
2020-04-15 15:13:22 -04:00
}
}
if (member.activities.length <= 0) return this.error(message.channel, 'Cannot find a game for this member.');
2020-04-15 15:13:22 -04:00
const embed = new RichEmbed();
let mainStatus: Activity;
if (member.activities[0].type === ActivityType.CUSTOM_STATUS) {
2020-04-15 15:13:22 -04:00
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.type === ActivityType.LISTENING) {
2020-04-15 15:13:22 -04:00
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 this.error(message.channel, 'Only Spotify games are supported at this time.');
2020-04-15 15:13:22 -04:00
}
return message.channel.createMessage({ embed });
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}