import { Message } from 'eris';
import { totalmem } from 'os';
import { Client, Command, RichEmbed } from '../class';
import { version as tsVersion } from '../../node_modules/typescript/package.json';

export default class Info extends Command {
  constructor(client: Client) {
    super(client);
    this.name = 'info';
    this.description = 'Information about this application.';
    this.usage = 'info';
    this.permissions = 0;
    this.enabled = true;
  }

  public async run(message: Message) {
    try {
      const embed = new RichEmbed();
      embed.setTitle('Information');
      embed.setThumbnail(this.client.user.avatarURL);
      embed.setDescription(`*See \`${this.client.config.prefix}sysinfo\` for more information on libraries used by this application.*`);
      embed.addField('Version', 'Rolling Release', true);
      embed.addField('Language(s)', '<:TypeScript:703451285789343774> TypeScript', true);
      embed.addField('Runtime', `Node (${process.version})`, true);
      embed.addField('Compilers/Transpilers', `TypeScript [tsc] (${tsVersion})`, true);
      embed.addField('Memory Usage', `${Math.round(process.memoryUsage().rss / 1024 / 1024)} MB / ${Math.round(totalmem() / 1024 / 1024 / 1024)} GB`, true);
      embed.addField('Repository', 'https://loc.sh/crgit | Licensed under GNU Affero General Public License V3', true);
      embed.addField('Branch', await this.client.util.exec('git rev-parse --abbrev-ref HEAD'), true);
      embed.addField('Commit', `[${await this.client.util.exec('git rev-parse --short HEAD')}](${await this.client.util.exec('git rev-parse HEAD')})`, true);
      embed.setFooter(this.client.user.username, this.client.user.avatarURL);
      embed.setTimestamp();
      message.channel.createMessage({ embed });
    } catch (err) {
      this.client.util.handleError(err, message, this);
    }
  }
}
