/* eslint-disable no-useless-return */
import { CommandInteraction } from 'eris';
import { Client, Event } from '../class';

export default class InteractionCommandHandler extends Event {
  public client: Client;

  constructor(client: Client) {
    super(client);
    this.event = 'interactionCreate';
  }

  public async run(interaction: CommandInteraction) {
    try {
      console.log(interaction);
      const int = this.client.interactions.get(interaction.id);
      if (!int) return;
      if (!int.checkPermissions(this.client.util.resolveMember(interaction.member?.id, this.client.guilds.get(this.client.config.guildID)))) return;
      // this.client.util.signale.log(`User '${message.author.username}#${message.author.discriminator}' ran interaction '${resolved.cmd.name}' in '${message.channel.id}'.`);
      await int.run(interaction);
      this.client.db.mongo.Stat.updateOne({ name: 'commands' }, { $inc: { value: 1 } }).exec();
    } catch (err) {
      this.client.util.handleError(err);
    }
  }
}
