2020-04-15 15:13:22 -04:00
/* eslint-disable prefer-destructuring */
2020-04-16 23:27:46 -04:00
import { Activity , Member , Message } from 'eris' ;
2020-04-15 15:13:22 -04:00
import { Client , Command , RichEmbed } from '../class' ;
2020-04-16 23:27:46 -04:00
enum ActivityType {
2020-04-17 20:31:15 -04:00
PLAYING ,
STREAMING ,
LISTENING ,
WATCHING ,
CUSTOM_STATUS
2020-04-16 23:27:46 -04:00
}
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 {
2020-04-17 12:33:03 -04:00
member = this . client . util . resolveMember ( args . join ( ' ' ) , this . client . guilds . get ( this . client . config . guildID ) ) ;
2020-04-15 15:13:22 -04:00
if ( ! member ) {
2020-04-16 22:56:52 -04:00
return this . error ( message . channel , 'Member not found.' ) ;
2020-04-15 15:13:22 -04:00
}
}
2020-04-16 23:35:56 -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 ;
2020-04-16 23:27:46 -04:00
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 ) ;
2020-04-16 23:27:46 -04:00
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 ) ;
embed . addField ( 'Album' , mainStatus . assets . large_text ) ;
embed . addField ( 'Start' , ` ${ new Date ( mainStatus . timestamps . start ) . toLocaleTimeString ( 'en-us' ) } ET ` , true ) ;
embed . addField ( 'End' , ` ${ new Date ( mainStatus . timestamps . end ) . toLocaleTimeString ( 'en-us' ) } ET ` , true ) ;
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 {
2020-04-16 22:56:52 -04:00
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 ) ;
}
}
}