{"size": 2031, "ext": "js", "max_stars_repo_path": "commands/rpg/hunt.js", "max_stars_repo_name": "anandre/dragon-rpg", "max_stars_repo_stars_event_min_datetime": "2019-04-22T14:15:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-19T01:22:33.000Z", "max_issues_repo_path": "commands/rpg/hunt.js", "max_issues_repo_name": "anandre/dragon-rpg", "max_issues_repo_issues_event_min_datetime": "2019-10-21T09:29:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T04:25:01.000Z", "max_forks_repo_path": "commands/rpg/hunt.js", "max_forks_repo_name": "anandre/dragon-rpg", "max_forks_repo_forks_event_min_datetime": "2019-04-16T07:17:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-19T01:23:09.000Z"}
{"max_stars_count": 5, "max_issues_count": 4, "max_forks_count": 3, "avg_line_length": 35.6315789474, "max_line_length": 139, "alphanum_fraction": 0.6262924668}
const { Command } = require('discord-akairo');
const { MessageEmbed } = require('discord.js');
const { join, dirname } = require('path');
const appDir = dirname(require.main.filename);
const dataManager = require(join(appDir, '/data/manager/dataManager.js'));
const db = require(join(appDir, '/data/database/pool.js'));

class HuntCommand extends Command {
  constructor() {
    super('hunt', {
      aliases: ['hunt', 'h'],
      channel: 'guild',
      category: 'rpg',
      description: {
        content: 'Hunt for items needed to upgrade equipment',
        usage: 'hunt',
        example: 'hunt'
      }
    });
  }

  async exec(message) {
    const timer = 1800000;
    const lastHunt = await db.query(`
      SELECT
        hunttimer
      FROM
        players
      WHERE
        playerid = $1`,
    [message.author.id]);
    if (parseInt(lastHunt.rows[0].hunttimer) + timer < message.createdTimestamp) {
      const gold = await dataManager.functions.gold(message.author.id);
      const hunt = await dataManager.functions.hunt(message.author.id, message.createdTimestamp, gold);
      let huntResult = '';
      for (let i = 0; i < hunt.length; i += 3) {
        huntResult += `${hunt[i + 1]} ${hunt[i]}\n`;
      }
      huntResult += `You also receive ${gold} gold after selling some meat.`;
      const embed = new MessageEmbed()
        .setColor('#e00808')
        .setTitle(`${message.author.username} had a successful hunt!`)
        .setFooter('The hunt ended at')
        .setTimestamp()
        .setThumbnail(message.author.displayAvatarURL())
        .addField('On your hunt, you have found', huntResult);
      await message.channel.send({ embed: embed });
      // await this.client.checkXP(message)
    }
    else {
      const cdtime = Math.abs(message.createdTimestamp - (parseInt(lastHunt.rows[0].hunttimer) + timer));
      return message.answer(message.author, `you have hunted too recently.  You may hunt again in ${dataManager.functions.time(cdtime)}.`);
    }
  }
}

module.exports = HuntCommand;