<commit_before>'use strict';

const _ = require('lodash');
const Discord = require('discord.js');

const CacheMiddleware = require('../../../../bot/middleware/Cache');

const DiscordReplyMessage = require('../../../../bot/modules/DiscordReplyMessage');

const ApiBase = require('./ApiBase');


// Hardcoded cats, lye pls
const availableCats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37];


class CommandCats extends ApiBase {
    constructor(bot) {
        super(bot, 'cats', ['cats']);

        this.setMiddleware(new CacheMiddleware(bot, this, { uniqueUser: true }));
    }

    async onApiCommand(message, gw2Api) {
        const bot = this.getBot();
        const l = bot.getLocalizer();
        const apiKey = await this.getApiKey(message);

        const toNames = cats => cats.map(cat => l.t([`module.guildwars2:cats.cat-${cat.id}`, 'module.guildwars2:cats.cat-unknown'], { id: cat.id, hint: cat.hint }));
        const cats = await gw2Api.authenticate(apiKey).account().home().cats().get();
        const ownedCats = toNames(cats);
        const missingCats = toNames(_.differenceWith(availableCats, cats, (a, b) => a === b.id).map(cat => ({ id: cat, hint: 'no hint' })));

        if (ownedCats.length === 0) {
            return l.t('module.guildwars2:cats.response-no-cats');
        }

        const user = (message.member && message.member.nickname) || message.author.username;
        const embed = new Discord.RichEmbed().setTitle(l.t('module.guildwars2:cats.response-title', { user }));
        if (ownedCats.length === availableCats.length) {
            embed.setDescription(l.t('module.guildwars2:cats.response-all-cats'));
        } else {
            embed.setDescription(l.t('module.guildwars2:cats.response-number-cats', { count: ownedCats.length, total: availableCats.length }));
        }<commit_msg>Get the cat ids from the API directly, closes #6<commit_after>'use strict';

const _ = require('lodash');
const Discord = require('discord.js');

const CacheMiddleware = require('../../../../bot/middleware/Cache');

const DiscordReplyMessage = require('../../../../bot/modules/DiscordReplyMessage');

const ApiBase = require('./ApiBase');


// Missing cats on the API, see arenanet/api-cdi#564
const missingApiCats = [34, 36, 37];


class CommandCats extends ApiBase {
    constructor(bot) {
        super(bot, 'cats', ['cats']);

        this.setMiddleware(new CacheMiddleware(bot, this, { uniqueUser: true }));
    }

    async onApiCommand(message, gw2Api) {
        const bot = this.getBot();
        const l = bot.getLocalizer();
        const apiKey = await this.getApiKey(message);

        const toNames = cats => cats.map(cat => l.t([`module.guildwars2:cats.cat-${cat.id}`, 'module.guildwars2:cats.cat-unknown'], { id: cat.id, hint: cat.hint }));
        const [availableCats, accountCats] = await Promise.all([
            gw2Api.cats().ids().then(ids => [...new Set([...ids, ...missingApiCats])]),
            gw2Api.authenticate(apiKey).account().home().cats().get()
        ]);
        const ownedCats = toNames(accountCats);
        const missingCats = toNames(_.differenceWith(availableCats, accountCats, (a, b) => a === b.id).map(cat => ({ id: cat, hint: 'no hint' })));

        if (ownedCats.length === 0) {
            return l.t('module.guildwars2:cats.response-no-cats');
        }

        const user = (message.member && message.member.nickname) || message.author.username;
        const embed = new Discord.RichEmbed().setTitle(l.t('module.guildwars2:cats.response-title', { user }));
        if (ownedCats.length === availableCats.length) {
            embed.setDescription(l.t('module.guildwars2:cats.response-all-cats'));
        } else {
            embed.setDescription(l.t('module.guildwars2:cats.response-number-cats', { count: ownedCats.length, total: availableCats.length }));
        }
{'fraction_non_alphanumeric': 0.17777212614445576, 'fraction_numerical': 0.02288911495422177, 'mean_word_length': 3.105427974947808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4925273', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1265, 'n_words': 262}